Skip to content

+full HEADER in ESP8266WebServer #795

Closed
@xbary

Description

@xbary

Hi

I would ask to be added to the official version of such an allowance:


in file ESP8266WebServer.h (on comment // Add by XBary)
...
WiFiClient client() { return _currentClient; }
HTTPUpload& upload() { return _currentUpload; }
String HEADER() { return _currentHEADER; } // Add by XBary

String arg(const char* name); // get request argument value by name
...
and
...
HTTPMethod _currentMethod;
String _currentUri;
String _currentHEADER; // Add by XBary

size_t _currentArgCount;
RequestArgument* _currentArgs;

...

in file Parsing.cpp
...
String req = client.readStringUntil('\r');
client.readStringUntil('\n');
_currentHEADER = req + "\r\n"; // Add by XBary

// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
...
and
...
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
_currentHEADER += (req + "\r\n"); // Add by XBary

  #ifdef DEBUG
  DEBUG_OUTPUT.print("headerName: ");

...
and
...
if (headerDiv == -1){
break;
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
_currentHEADER += (req + "\r\n"); // Add XBary

  #ifdef DEBUG
  DEBUG_OUTPUT.print("headerName: ");
  DEBUG_OUTPUT.println(headerName);
  DEBUG_OUTPUT.print("headerValue: ");

...

Example use:
...
void handle_mainmenu()
{
WiFiClient client = server.client();
String hostheader = server.HEADER();
int sesID = GetSession(client, hostheader);
...

The application mainmenu now have access to the entire HTTP header. I read User-agent: or cookies, etc.

Regards XBary

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions