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

Creating a buffer for parseHeader and parsePostData #622

Merged
merged 2 commits into from
Mar 31, 2016

Conversation

patrickjahns
Copy link
Member

This addresses #615 and also prepares for working on multipart requests

The previous implementation did not account that header information could be split between several packets. Also post data can be split across several TCP packets.

The changes address this by storing not processed data in a temporary buffer and pre pending the new tcp buffer so it will be parsed together

Has been tested with several requests (GET/POST including Cookies and large headers)

@patrickjahns
Copy link
Member Author

@hreintke

any comments so far?

do
{
nextLine = NetUtils::pbufFindStr(buf, "\r\n", line);

nextLine = tmpbuf.indexOf("\r\n", line+2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the last parenthesis be placed before the "+" operator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I`ll verify it again

@PTDreamer
Copy link

No comments regarding coding style since I found no reference to the style adopted by this project. Linux Kernel style is the most common for this kind of projects and this PR doesn't conform in several places.
I don't fully understand the idea behind processing data chunks as they come instead of just increment (append data to) a buffer waiting for a complete header and process that. It would simplify code and increase readability (IMHO) without any performance impact.
PS: Don't know if my comments are welcomed or not since I haven't contributed with any code to this repo/project, but honestly I had nothing better to do :).

@patrickjahns
Copy link
Member Author

@PTDreamer

See the Summary on the first page - there is the compatibility listed to arduino libraries ...
Any further discussion in regard to this should rather be in a different ISSUE - to keep things related to this PR

In regards to processing packets as they arrive (actually you can relate to this as a concept of processing a stream) - it is more memory friendly. While header data might be "small" (compared to post requests) - it requires more ram than just keeping unprocessed packet data in a buffer.

Before this PR there was no processing of headers split accross packets - (see #615 )
This is also meant as basis for processing multipart/post requests - a feature which I am working on in a different PR. While your idea of processing the header at once works for the header - it will not properly work for POST bodies - especially not for multipart requests - latest then I would need to implement the concept - and why not process both the same way? It is more intuitive than to process header and post requests differently

@PTDreamer
Copy link

See the Summary on the first page - there is the compatibility listed to arduino libraries ...
Any further discussion in regard to this should rather be in a different ISSUE - to keep things related to this PR

Not sure if the comment is related to the coding style or discussion about the substring function.

it is more memory friendly. While header data might be "small" (compared to post requests) - it requires more ram than just keeping unprocessed packet data in a buffer

It is not obvious to me how that is true. You are trading raw data buffer space with hash stored values which looking at the implementation bloats the amount of memory needed to store the data (which is true for all hash implementations).

Before this PR there was no processing of headers split accross packets - (see #615 )

No argument there. It is obvious there was a bug, the data will need to be appended to a buffer between callback calls or it will get ditched.

While your idea of processing the header at once works for the header - it will not properly work for POST bodies

Why not? You can just buffer the stream until you find "delimiter "--"" and parse it then.

In the end your code should work fine (although I still think you have a misplaced parenthesis), it is just a matter of personal coding style. Long do/whiles and lots of global variables are not my thing, also I found this PR hard to read not only by the code style but also by the variable naming.
Good job though, I hope I can find something to contribute with so you can take a turn at bashing my code.

@patrickjahns
Copy link
Member Author

Not sure if the comment is related to the coding style or discussion about the substring function.

It was related to the discussion in regards to substring and compatibility with arduino libraries. And as suggested - i think this is best suited to be discussed in it`s own issue since it is not related to this PR

It is not obvious to me how that is true. You are trading raw data buffer space with hash stored values which looking at the implementation bloats the amount of memory needed to store the data (which is true for all hash implementations).

You need to differentiate between the buffer and the Hashmap - the Hashmap implementation was already in use even before I suggested the buffer. When keeping everything in one buffer before parsing, you would need the space for the buffer and the hashmap at the same time. Parsing as far as it goes, the buffer data needed can be smaller and leave room for the final hashmap to be worked with.

Why not? You can just buffer the stream until you find "delimiter "--"" and parse it then.

Since multipart requests are not only variables/fields to be kept in memory, but also can be files - I don`t see your suggestion viable - it would need again 2 different implementations for one task. For suggestions/discussion on multipart and file uploads please join #552

In the end your code should work fine (although I still think you have a misplaced parenthesis), it is just a matter of personal coding style. Long do/whiles and lots of global variables are not my thing, also I found this PR hard to read not only by the code style but also by the variable naming.

Please compare the version before and after my PR - I based my solution on the already exiting coding style. In what way would you improve the current implementation ?

Good job though, I hope I can find something to contribute with so you can take a turn at bashing my code.

I hope you dont see this discussion as a need for bashing code - as long as it improves code and usability in the end - its good to discuss it. And I am not too well suited for doing c/c++ code - I am more home with python. But since I am working on a project with an esp - I might as well help to improve it right? ;-)

@hreintke
Copy link
Contributor

hreintke commented Mar 3, 2016

@patrickjahns :

In the end your code should work fine (although I still think you have a misplaced parenthesis)
Is there still an update needed from your code.?

On In the PR now there is

Merge pull request #1 from SmingHub/develop …
That contains (part of ?) another PR.
I am not the most experienced in git so am not sure how that effects the merging.
Any change that you can update the PR for that ?

@patrickjahns
Copy link
Member Author

@hreintke

I had trouble squashing - will try again later and update accordingly. Please wait with merging until then. I still want to verify the part with the misplaced parenthesis - didn`t get around to it until now

@hreintke
Copy link
Contributor

hreintke commented Mar 3, 2016

OK Clear

@patrickjahns
Copy link
Member Author

@PTDreamer
Thanks for the hint with the line numbers - the +2 calculation was unnecessary and was a leftover from previous testing. Removed and now the PR is clean

@hreintke
squashed and ready to merge - I can prepare another PR for RTOS then

@patrickjahns
Copy link
Member Author

@avr39-ripe
Mentioned that query parameters are not parsed/parsed correctly - will need to have another look

@avr39-ripe
Copy link
Contributor

Nither queryParameter nor urlencoded form data DO NOT work ;(( switching to regular sming/develop solve the problem.. and introduce new one with packet hassle

@patrickjahns
Copy link
Member Author

@avr39-ripe

pushed the proposed fix - please test and confirm that query and post parameters are working now as expected (please test only this branch and don`t include rawbody yet)

@avr39-ripe
Copy link
Contributor

cherry-pick last two commits on top of develop and it works. tested by using response.getQueryParameter(). Thanks!

@patrickjahns
Copy link
Member Author

patrickjahns commented Mar 15, 2016 via email

@avr39-ripe
Copy link
Contributor

If @dobrishinov try this and confirm.. He expect problems with split/truncated data.. but it needs rawBody fix also..

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.

4 participants