Skip to content
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

Merged
merged 5 commits into from
Oct 6, 2018

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Oct 6, 2018

  • 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()

* 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()
@mikee47
Copy link
Contributor Author

mikee47 commented Oct 6, 2018

@slaff I've held-off making any changes to Samples (HttpClient, HttpClient_Instapush, HttpServer_ConfigNetwork, MeteoControl, but can add those if you want.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 6, 2018

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
Sming/SmingCore/Data/HttpHeaders.cpp Outdated Show resolved Hide resolved
Sming/SmingCore/Data/HttpHeaders.h Outdated Show resolved Hide resolved
@slaff
Copy link
Contributor

slaff commented Oct 6, 2018

Clearly using the enum for lookups is a lot faster so I may revisit this at some point.

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 ).

@slaff
Copy link
Contributor

slaff commented Oct 6, 2018

HttpClient, HttpClient_Instapush, HttpServer_ConfigNetwork, MeteoControl, but can add those if you want.

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
@slaff slaff added this to the 3.6.2 milestone Oct 6, 2018
@slaff slaff removed the 3 - Review label Oct 6, 2018
@slaff slaff merged commit 7a47fe4 into SmingHub:develop Oct 6, 2018
@mikee47 mikee47 deleted the feature/HttpHeaders branch October 6, 2018 20:00
@slaff slaff mentioned this pull request Oct 8, 2018
4 tasks
mikee47 added a commit to mikee47/Sming that referenced this pull request Oct 10, 2018
…1463

* Comparison accomplished using stack, avoids allocating temporary String variable on heap
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

Successfully merging this pull request may close these issues.

2 participants