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

post request params broken #257

Closed
kostya opened this issue Nov 23, 2016 · 16 comments
Closed

post request params broken #257

kostya opened this issue Nov 23, 2016 · 16 comments
Labels

Comments

@kostya
Copy link

kostya commented Nov 23, 2016

seems this is after crystal update.

require "kemal"

post "/bla" do |env|
  p env.params.body["x"]?
end

Kemal.run

curl -s http://127.0.0.1:3000/bla -X POST --data 'x%3D1'
curl -s http://127.0.0.1:3000/bla -X POST --data 'x=1'

nil
nil

works in previous crystal, kemal

@sdogruyol
Copy link
Member

Now this is strange, all the specs are passing 😢

@airinfection
Copy link

My mother always says "don't trust the specs".

@Fusion
Copy link

Fusion commented Nov 24, 2016

I can confirm this is broken.
The only way I can retrieve these params is:

puts env.request.body.as(IO).gets_to_end

I suspect this has to do with Crystal now supporting streaming...

@Fusion
Copy link

Fusion commented Nov 24, 2016

(note: for now, one can use this but really I hope we get a cleaner fix ;) )

env.request.body.as(IO).gets_to_end.split("&").each { |r| k,v=r.split("="); env.params.body[k] ||= v }

@sdogruyol
Copy link
Member

This is now fixed 👍 Thanks everyone for reporting ❤️

@airinfection
Copy link

❤️S❤️E❤️R❤️D❤️A❤️R❤️ ❤️D❤️O❤️G❤️R❤️U❤️Y❤️O❤️L❤️

@kostya
Copy link
Author

kostya commented Nov 24, 2016

what about spec?

@sdogruyol
Copy link
Member

@kostya the specs are correct, this was due to a behaviour change in HTTP::Request.body in Crystal std

@Fusion
Copy link

Fusion commented Nov 24, 2016

I think Kostya was asking whether you are going to add a test case for params.body to the specs.

@sdogruyol
Copy link
Member

@Fusion
Copy link

Fusion commented Nov 24, 2016

Ooh, nice.
Question: are we definitely comfortable using gets_to_end? I mean, depending on the change in Crystal, you may, down the road, get something other than a FixedLengthContent object.

@kostya
Copy link
Author

kostya commented Nov 24, 2016

this is unit test, i think better to add integration test also, run http server, and run requests. in crystal its quite easy. i do it in many projects. example in msgpack: https://github.com/benoist/msgpack-crystal/blob/master/spec/socket_spec.cr#L15

@sdogruyol
Copy link
Member

sdogruyol commented Nov 24, 2016

@Fusion i don't think that HTTP::Server will get another rewrite like this.

@kostya you are right. I've thought of that but not sure.

@Fusion
Copy link

Fusion commented Nov 24, 2016

Thanks, Serdar. That was definitely a nitpick 👍

@rdp
Copy link

rdp commented Oct 4, 2018

FWIW this should also work:

curl -X POST -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" -d $'------------------------------4ebf00fbcf09\r\nContent-Disposition: form-data; name="x"\r\n\r\ntest\r\n------------------------------4ebf00fbcf09--\r\n' http://localhost:3000/bla

However the first example and this one both fail currently...it gives empty env.params.body second example works though :)

@rdp
Copy link

rdp commented Oct 6, 2018

OK after some research it appears that --data 'x%3D1' should be nil (that's a very long named key, named x=1, with no value) https://stackoverflow.com/questions/52641356/can-you-escape-the-equals-sign-in-post-data for the form-data one filed a new issue, seems unrelated.

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

5 participants