Commits

Mahlon Smith committed a733dfe

Allow entity-bodies for HTTP verbs that don't explicitly forbid them in
RFC.

Comments (0)

Files changed (2)

lib/strelka/httprequest.rb

 
 
 	### Parse the request parameters and return them as a Hash. For GET requests, these are
-	### take from the query arguments, and for POST requests, from the
+	### taken from the query arguments.  For requests that commonly
+	### contain an entity-body, try and parse that.
 	###
 	###   # For a handler with a route of '/user', for the request:
 	###   # "GET /user/1/profile?checkbox=1&checkbox=2&text=foo HTTP/1.1"
 				@params = self.parse_query_args
 			when :POST, :PUT
 				@params = self.parse_form_data
+			when :TRACE
+				self.log.debug "No parameters for a TRACE request."
 			else
-				self.log.debug "No parameters for a %s request." % [ self.verb ]
+				@params = self.parse_form_data if self.content_type
 			end
 		end
 

spec/strelka/httprequest_spec.rb

 		end
 
 
+		context "a DELETE request without a content type" do
+			before( :each ) do
+				@req = @request_factory.delete( '/directory/path' )
+			end
+
+
+			it "Doesn't respond with a 400 (BAD_REQUEST)" do
+				@req.params.should be_nil
+			end
+		end
+
+
+		context "a DELETE request with a 'multipart/form-data' body" do
+
+			before( :each ) do
+				@req = @request_factory.delete( '/directory/path',
+					'Content-type' => 'multipart/form-data; boundary=--a_boundary' )
+			end
+
+			it "returns a hash for form parameters" do
+				@req.body = "----a_boundary\r\n" +
+					%{Content-Disposition: form-data; name="reason"\r\n} +
+					%{\r\n} +
+					%{I really don't like this path.\r\n} +
+					%{----a_boundary--\r\n}
+
+				@req.params.should == {'reason' => "I really don't like this path."}
+			end
+
+		end
+
+
+
 		context "a POST request without a content type" do
 			before( :each ) do
 				@req = @request_factory.post( '/directory/path', '' )