-
-
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
HttpRequest improvements and move HttpParams into separate module #1498
Conversation
* Move trivial code into headers * Simplify getHeader() and getPostParameter() methods by calling `HashMap[] const` method, thus ensuring missing values aren't added. Also more efficient as doesn't require two lookups (one for contains(), another for operator[]). * Simplify and optimise HttpRequest::getBody() by reading content directly into pre-allocated String
WebHelpers/escape * bugfix: encoding of space as '+' added * uri_escape(const char*, int) rewritten without using heap * add uri_unescape_inplace(char*, int) * bugfix: output buffer must account for nul terminator in uri_unescape_inplace(String&) structures.h * Move HttpParams definition into separate module UrlencodedOutputStream * Remove (duplicate) definition of HttpParams * Move output code into HttpParams::printTo() method
ca5d3bd
to
b4a1117
Compare
HttpRequest* setBody(uint8_t* rawData, size_t length); | ||
|
||
/** | ||
* @brief Instead of storing the response body we can set a stream that will take care to process it | ||
* @param ReadWriteStream *stream | ||
* | ||
* @retval HttpRequest* | ||
* | ||
* @note The response to this message will be stored in the user-provided stream. |
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.
The response to this message
. Did you mean The response to this request
?
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.
Yes! Well spotted.
|
||
HttpRequest* setHeader(const String& name, const String& value); | ||
/** @deprecated this replaces existing post parameter set, which is different to |
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.
Can you add here also a very small example of the new recommended way? That target audience is beginners.
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.
setPostParameters() isn't actually used anywhere in Sming or its samples. Would it be safe to delete?
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.
If we're keeping it, I'd probably amend the comment to something like:
To set all post parameters, use request.postParams = params
To copy additional post parameters, use request.postParams.setMultiple(params)
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.
If we're keeping it,
Yes, we will keep it for now. For deprecation we usually do the following:
- once a method is marked as deprecated we remove its use inside of Sming and samples
- we announce it as deprecated and suggest replacement (in code comments and/or git comments)
- we create a new 3.x release with the deprecated method in it + information in release notes
- we remove the deprecated method in following 3.x release (might be 3.x+1, but that is not always the case. If the impact is low then we can schedule the removal in the next 3.x+1 release.
@mikee47 Is it tested on real device with real app ? |
Yes, the escaping changes are tested and verified. This PR is mainly refactoring, the substantive changes are yet to come. |
206c905
to
d998e9a
Compare
@@ -280,6 +280,8 @@ int HttpServerConnection::staticOnBody(http_parser* parser, const char* at, size | |||
} | |||
|
|||
// TODO: ... | |||
connection->request.setBody((const uint8_t *)&at, length); |
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.
That is something that we don't do. Because it is the easiest way to crash remotely the http server and the device. Just send a request with very long body. What we do is use body parsers and decide in there how to operate over the incoming response body.
That said, please, remove that new line.
@@ -280,6 +280,8 @@ int HttpServerConnection::staticOnBody(http_parser* parser, const char* at, size | |||
} | |||
|
|||
// TODO: ... | |||
connection->request.setBody((const uint8_t *)&at, length); |
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.
That is something that we don't do. Because it is the easiest way to crash remotely the http server and the device. Just send a request with very long body. What we do is use body parsers and decide in there how to operate over the incoming response body.
That said, please, remove that new line.
@@ -280,6 +280,8 @@ int HttpServerConnection::staticOnBody(http_parser* parser, const char* at, size | |||
} | |||
|
|||
// TODO: ... | |||
connection->request.setBody((const uint8_t *)&at, length); |
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.
That is something that we don't do. Because it is the easiest way to crash remotely the http server and the device. Just send a request with very long body. What we do is use body parsers and decide in there how to operate over the incoming response body.
That said, please, remove that new line.
@@ -280,6 +280,8 @@ int HttpServerConnection::staticOnBody(http_parser* parser, const char* at, size | |||
} | |||
|
|||
// TODO: ... | |||
connection->request.setBody((const uint8_t*)&at, length); |
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.
connection->request.setBody((const uint8_t*)&at, length);
That is something that we don't do. Because it is the easiest way to crash remotely the http server and the device. Just send a request with very long body. What we do is use body parsers and decide in there how to operate over the incoming response body.
That said, please, remove that new line.
d998e9a
to
1a4decf
Compare
@slaff I've reverted everything to do with the |
Tested with HttpServer_ConfigNetwork and works fine. Code is migrated from my dev. branch which it's tested on first. We're moving into trickier territory now, lots of dependencies. |
I guess that means that the PR is ready to be tested by me, right? |
Yes please, I've nothing else to add for this PR. |
@mikee47 That PR broke my HTTPS client connections... My wild guess is that either some data is sent before the handshake is over... or I will have to update my code which means that we should add more information how to migrate to the new code. Can you check it on your system? The HttpClient sample would be a good start. |
uint32_t getSslOptions(); | ||
HttpRequest* setSslOptions(uint32_t sslOptions) | ||
{ | ||
sslOptions = sslOptions; |
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.
That looks like a wrong code to me? Shouldn't it be this->sslOptions = sslOptions;
?
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.
Yep, it's wrong - my error - does it fix your problem?
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.
Yep, that was the problem. Can you put a PR with the small fix? Sorry for not noticing this earlier. There should be a way to detect such problems automatically.
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 made the error moving the code into the header - yes, it would be useful to be able to track those sorts of changes in diff. More recently I've been doing those changes (cut & paste) in an initial commit so shouldn't happen again.
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.
@slaff Thank you!
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.
The issue is fixed with #1504. No action is needed from your side.
yes, it would be useful to be able to track those sorts of changes in diff.
I guess my IDE, cpplint or codacy should be able to detect the issue. Will look tomorrow how to enable that in codacy by default.
HashMap[] const
method, thus ensuring missing values aren't added. Also more efficient as doesn't require two lookups (one for contains(), another for operator[]).WebHelpers/escape
structures.h
UrlencodedOutputStream