Skip to content

Parsing Post Requests twice fails (HTTPURLEncodedBodyParser) #84

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

Closed
JM-FRANCE opened this issue Apr 14, 2020 · 2 comments
Closed

Parsing Post Requests twice fails (HTTPURLEncodedBodyParser) #84

JM-FRANCE opened this issue Apr 14, 2020 · 2 comments
Labels

Comments

@JM-FRANCE
Copy link

I'm trying to use your library (https) and my web site uses POST for all requests.

A POST always include a session UUID that lets me identify which session is making a request, which I use to establish a server side context in which my call back will be executed.

So When I get an incoming request, I call a function which creates a parser and walk through the request to find my UUID entry. I compare it with known UUIDs, setup a context and return.

Then the callback proceeds and in some cases I need to parse again the POST data to extract other elements of the request.

--> that's where I'm having an issue, it seems that creating a new parser on the same request fails, there is no more attributes to read.

Is that intended behavior ? does parsing the request once kills the post data ???

thx

(as a side note, it would be great to not instantiate so many strings and give us const pointers into the body to extract the data we are interested in).

@fhessel
Copy link
Owner

fhessel commented Apr 14, 2020

Is that intended behavior ? does parsing the request once kills the post data?

Yes, it is. The BodyParsers consume the body. Otherwise you wouldn't be able to handle large requests that don't fit in memory.

If you need random field access an you know that everything will fit into memory, my suggestion would be to create a struct for all required variables and assign them while iterating through the body. Alternatively, you could use a container like std::map, if you don't know the number or name of keys in advance.

(as a side note, it would be great to not instantiate so many strings and give us const pointers into the body to extract the data we are interested in).

For the same reason as above, there is no time at which the whole body is guaranteed to be present in memory. If I would implement such an interface now, that implementation would break as soon as the library can handle different content encoding for request bodies, where all input needs to be converted on the fly. My focus is more on reducing redundant buffers on different layers of processing.

@JM-FRANCE
Copy link
Author

JM-FRANCE commented Apr 14, 2020

Thanks for explaining the rationale, that makes sense.
I’ll update serialization/deserialisation of my context - maybe as a JSON and work from there
Thx for the good work
Question closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants