Skip to content

Commit a976fa1

Browse files
committed
Followed up ruby/net-http@002441da1e for ruby/spec
1 parent 82e3312 commit a976fa1

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

spec/ruby/library/net-http/http/post_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
response.should be_kind_of(Net::HTTPResponse)
2626
end
2727

28-
it "sends Content-Type: application/x-www-form-urlencoded by default" do
29-
response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
30-
response.body.should include({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}"))
28+
ruby_version_is ""..."3.5" do
29+
it "sends Content-Type: application/x-www-form-urlencoded by default" do
30+
response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
31+
response.body.should include({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}"))
32+
end
3133
end
3234

3335
it "does not support HTTP Basic Auth" do

spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@
3131
end
3232

3333
describe "when a request body is set" do
34-
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
35-
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
36-
request.body = "Some Content"
37-
38-
request.exec(@buffered_socket, "1.1", "/some/other/path")
39-
str = @socket.string
40-
41-
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
42-
str.should =~ %r[Accept: \*/\*\r\n]
43-
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
44-
str.should =~ %r[Content-Length: 12\r\n]
45-
str[-16..-1].should == "\r\n\r\nSome Content"
34+
ruby_version_is ""..."3.5" do
35+
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
36+
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
37+
request.body = "Some Content"
38+
39+
request.exec(@buffered_socket, "1.1", "/some/other/path")
40+
str = @socket.string
41+
42+
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
43+
str.should =~ %r[Accept: \*/\*\r\n]
44+
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
45+
str.should =~ %r[Content-Length: 12\r\n]
46+
str[-16..-1].should == "\r\n\r\nSome Content"
47+
end
4648
end
4749

4850
it "correctly sets the 'Content-Length' header and includes the body" do
@@ -62,19 +64,21 @@
6264
end
6365

6466
describe "when a body stream is set" do
65-
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
66-
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
67-
"Content-Length" => "10")
68-
request.body_stream = StringIO.new("a" * 20)
69-
70-
request.exec(@buffered_socket, "1.1", "/some/other/path")
71-
str = @socket.string
72-
73-
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
74-
str.should =~ %r[Accept: \*/\*\r\n]
75-
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
76-
str.should =~ %r[Content-Length: 10\r\n]
77-
str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
67+
ruby_version_is ""..."3.5" do
68+
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
69+
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
70+
"Content-Length" => "10")
71+
request.body_stream = StringIO.new("a" * 20)
72+
73+
request.exec(@buffered_socket, "1.1", "/some/other/path")
74+
str = @socket.string
75+
76+
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
77+
str.should =~ %r[Accept: \*/\*\r\n]
78+
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
79+
str.should =~ %r[Content-Length: 10\r\n]
80+
str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
81+
end
7882
end
7983

8084
it "sends the whole stream, regardless of the 'Content-Length' header" do

0 commit comments

Comments
 (0)