-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add header access using same method as arguments #886
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
Changes from 6 commits
ec89479
05921b7
9b3b922
d9e3a35
c117d78
d44fc5b
fab08c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,13 @@ class ESP8266WebServer | |
String argName(int i); // get request argument name by number | ||
int args(); // get arguments count | ||
bool hasArg(const char* name); // check if argument exists | ||
|
||
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount); // set the request headers to collect | ||
String header(const char* name); // get request header value by name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this end up copying the returned String (or will the compiler optimize)? Is there a "best practice" (examples in other well-used libraries) on how to return a String efficiently? (Am I focusing too much on optimizations 😄 😞 ?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you look just above (ESP8266WebServer.h Line 81), you'll see that the existing argument access method is the same. There may be a better way but I decided to follow the conventions of the existing code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, cool, good enough for me. |
||
String header(int i); // get request header value by number | ||
String headerName(int i); // get request header name by number | ||
int headers(); // get header count | ||
bool hasHeader(const char* name); // check if header exists | ||
|
||
String hostHeader(); // get request host header if available or empty String if not | ||
|
||
|
@@ -124,6 +131,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){ | |
void _uploadWriteByte(uint8_t b); | ||
uint8_t _uploadReadByte(WiFiClient& client); | ||
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength); | ||
bool _collectHeader(const char* headerName); | ||
|
||
struct RequestArgument { | ||
String key; | ||
|
@@ -139,6 +147,11 @@ template<typename T> size_t streamFile(T &file, const String& contentType){ | |
size_t _currentArgCount; | ||
RequestArgument* _currentArgs; | ||
HTTPUpload _currentUpload; | ||
|
||
size_t _currentHeaderCount; | ||
RequestArgument* _currentHeaders; | ||
size_t _headerKeysCount; | ||
const char** _headerKeys; | ||
|
||
size_t _contentLength; | ||
String _responseHeaders; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also maybe want to do
_headerKeysCount = 0
just to be safe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it because the object is being destroyed anyway but why not, can't be too safe. Does the rest of the PR work for you?