Skip to content

+full HEADER in ESP8266WebServer #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xbary opened this issue Sep 16, 2015 · 3 comments
Closed

+full HEADER in ESP8266WebServer #795

xbary opened this issue Sep 16, 2015 · 3 comments

Comments

@xbary
Copy link

xbary commented Sep 16, 2015

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

@bren3582
Copy link

My vote (if I get one) is to make headers accessible in the same way as arguments. Then one could do something like server.header("Cookie") to get the value. I've coded this up reusing RequestArgument and it's working great. I'll submit a pull request later today or tomorrow. Thanks for the great project!

@xbary
Copy link
Author

xbary commented Oct 13, 2015

And so be ... now wait for an official patch. Thanks for brianensor for taking the topic.

@Links2004
Copy link
Collaborator

see #933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants