This also sets the content-length for GET requests (and other requests that don't have a body). I think this should also check See this for an example: require 'net/http'
h = Net::HTTP.new 'localhost', 8000
h.set_debug_output $stderr
h.get '/'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
When you're done you should create a ticket on bugs.ruby-lang.org that references this pull request. You don't need to submit the patch.
Sorry holidays got in the way. Yes I am but I'm having trouble writing a proper test. After chatting with drbrain I thought that instead of looking at the http response code, I would check the headers in the request, but I can't seem to figure out how to do that. Any pointers anyone could give me?
|
gregors |
add check for request body permitted
…
We don't want get requests to have a content-length header |
cb4df80
|
add check for request body permitted …
We don't want get requests to have a content-length header
@@ -75,6 +75,9 @@ def body_stream=(input) | ||
def set_body_internal(str) #:nodoc: internal use only | ||
raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream) | ||
self.body = str if str | ||
+ if @body.nil? && @body_stream.nil? && @body_data.nil? && request_body_permitted? | ||
This also sets the content-length for GET requests (and other requests that don't have a body). I think this should also check See this for an example: require 'net/http'
h = Net::HTTP.new 'localhost', 8000
h.set_debug_output $stderr
h.get '/'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
||
+ self.body = '' | ||
+ end | ||
end | ||
# | ||
It is bad form to not set the content-length header on empty post requests. This will most likely end with a 411 response from the server. Sometimes post requests will be empty e.g. the initial request during a challenge-response authentication scenario.
I've also included a test. It checks to see that webrick does not return the 411 response code. This is a resubmitted pull request. I initially dev'd on the 1.9.3 branch pull request #200. Sorry about that - still trying to figure out the workflow around here.