-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Encapsulate encoding and decoding of HTTP header fields #1461
Conversation
* Move HttpHeaders from structures.h into a separate module, and expand * Replace common HTTP header field names with enumerated type - eliminates errors due to mis-typing, simplifies code * Replace instances of NULL with nullptr as appropriate in any updated files * Wrap constant string data with _F() or F() as appropriate Methods no longer used: * HttpResponse::hasHeader() * HttpRequest::getHeader()
@slaff I've held-off making any changes to Samples (HttpClient, HttpClient_Instapush, HttpServer_ConfigNetwork, MeteoControl, but can add those if you want. |
I originally implemented the HttpHeaders class as a HashMap(enum, String) but because that wouldn't support custom header fields directly I elected to keep it as a HashMap(String, String) for simplicity. Clearly using the enum for lookups is a lot faster so I may revisit this at some point. |
* Missed a few string tweaks * WebsocketFrame.h shouldn't be in this PR
We should not forbid or make it very complicated to set custom headers. If there is an elegant way to use enum as lookup and also allow custom headers I will be keen to see it (Can be done also as a separate PR ). |
As long as the changes are related to the main goal of that PR then go ahead. Because the samples are the first thing that new developers copy and modify we should give them a very good start by applying the best practises in using Sming and C++. |
* HTTP header field name enumeration values changed from camel case to uppercase, underscores and HTTP_HEADER_ prefix * Update HttpClient, HttpClient_Instapush and HttpServer_ConfigNetwork samples to use enumerated headers * Moved HttpHeaders into Network/Http
…1463 * Comparison accomplished using stack, avoids allocating temporary String variable on heap
Methods no longer used: