-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add form data shortcut method to HTTP::Request
#9941
Comments
Which body IO needs to be consumed in a |
@jhass The form data is included in the request body. So like to do this currently you have to do: params = HTTP::Params.parse(request.body.not_nil!.gets_to_end) However once you do this you can't rewind |
But a helper method could not magically solve that. Not without making it way to easy to read way too much data into memory, think file-uploads. Also the big big difference is that any request URL always has query params implicitly, they just may be empty. This is not the case at all with an |
@jhass For the query param method we just return an empty I'm open to other suggestions as well. My use case is I have a series of @form_data : HTTP::Params?
def form_data : HTTP::Params
@form_data ||= self.parse_form_data
end
private def parse_form_data : HTTP::Params
HTTP::Params.parse self.body.try(&.gets_to_end) || ""
end 🤷. |
HTTP::Request
currently has a#query_params
method that lazily loads anHTTP::Params
object based on the request's query string. Thoughts on doing something similar for the requests' form data?The problem without this is that you have to consume the body IO in order create the
HTTP::Params
object, making it impossible to access the data again in a different context without exposing the original params object somehow.The text was updated successfully, but these errors were encountered: