httpi 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/httpi/response.rb +4 -1
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/response_spec.rb +71 -38
- metadata +4 -4
data/lib/httpi/response.rb
CHANGED
@@ -43,10 +43,13 @@ module HTTPI
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def decode_body
|
46
|
+
return @body = "" if !raw_body || raw_body.empty?
|
47
|
+
|
46
48
|
body = gzipped_response? ? decoded_gzip_body : raw_body
|
47
49
|
@body = dime_response? ? decoded_dime_body(body) : body
|
48
50
|
end
|
49
51
|
|
52
|
+
|
50
53
|
# Returns whether the response is gzipped.
|
51
54
|
def gzipped_response?
|
52
55
|
headers["Content-Encoding"] == "gzip" || raw_body[0..1] == "\x1f\x8b"
|
@@ -54,7 +57,7 @@ module HTTPI
|
|
54
57
|
|
55
58
|
# Returns whether this is a DIME response.
|
56
59
|
def dime_response?
|
57
|
-
headers[
|
60
|
+
headers["Content-Type"] == "application/dime"
|
58
61
|
end
|
59
62
|
|
60
63
|
# Returns the gzip decoded response body.
|
data/lib/httpi/version.rb
CHANGED
data/spec/httpi/response_spec.rb
CHANGED
@@ -2,68 +2,101 @@ require "spec_helper"
|
|
2
2
|
require "httpi/response"
|
3
3
|
|
4
4
|
describe HTTPI::Response do
|
5
|
-
let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.xml }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
response.code.should == 200
|
10
|
-
end
|
6
|
+
context "normal" do
|
7
|
+
let(:response) { HTTPI::Response.new 200, {}, Fixture.xml }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
describe "#error?" do
|
10
|
+
it "should return false" do
|
11
|
+
response.should_not be_an_error
|
12
|
+
end
|
15
13
|
end
|
16
|
-
end
|
17
14
|
|
18
|
-
|
15
|
+
describe "#headers" do
|
16
|
+
it "should return the HTTP response headers" do
|
17
|
+
response.headers.should == {}
|
18
|
+
end
|
19
|
+
end
|
19
20
|
|
20
|
-
describe
|
21
|
-
|
21
|
+
describe "#code" do
|
22
|
+
it "should return the HTTP response code" do
|
23
|
+
response.code.should == 200
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
it "should always return an Integer" do
|
27
|
+
response = HTTPI::Response.new "200", {}, ""
|
28
|
+
response.code.should == 200
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
context "empty" do
|
34
|
+
let(:response) { HTTPI::Response.new 204, {}, nil }
|
35
|
+
|
36
|
+
describe "#body" do
|
37
|
+
it "should return an empty String" do
|
38
|
+
response.body.should == ""
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
context "error" do
|
44
|
+
let(:response) { HTTPI::Response.new 404, {}, "" }
|
45
|
+
|
46
|
+
describe "#error?" do
|
47
|
+
it "should return true" do
|
48
|
+
response.should be_an_error
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
|
-
|
53
|
+
context "gzipped" do
|
54
|
+
let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.gzip }
|
42
55
|
|
43
|
-
describe
|
44
|
-
|
56
|
+
describe "#headers" do
|
57
|
+
it "should return the HTTP response headers" do
|
58
|
+
response.headers.should == { "Content-Encoding" => "gzip" }
|
59
|
+
end
|
60
|
+
end
|
45
61
|
|
46
|
-
|
47
|
-
|
48
|
-
|
62
|
+
describe "#body" do
|
63
|
+
it "should return the (gzip decoded) HTTP response body" do
|
64
|
+
response.body.should == Fixture.xml
|
65
|
+
end
|
49
66
|
end
|
50
|
-
end
|
51
67
|
|
52
|
-
|
53
|
-
|
54
|
-
|
68
|
+
describe "#raw_body" do
|
69
|
+
it "should return the raw HTML response body" do
|
70
|
+
response.raw_body.should == Fixture.gzip
|
71
|
+
end
|
55
72
|
end
|
56
73
|
end
|
57
74
|
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
context "DIME" do
|
76
|
+
let(:response) { HTTPI::Response.new 200, { "Content-Type" => "application/dime" }, Fixture.dime }
|
77
|
+
|
78
|
+
describe "#headers" do
|
79
|
+
it "should return the HTTP response headers" do
|
80
|
+
response.headers.should == { "Content-Type" => "application/dime" }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#body" do
|
85
|
+
it "should return the (dime decoded) HTTP response body" do
|
86
|
+
response.body.should == Fixture.xml_dime
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#raw_body" do
|
91
|
+
it "should return the raw HTML response body" do
|
92
|
+
response.raw_body.should == Fixture.dime
|
93
|
+
end
|
61
94
|
end
|
62
|
-
end
|
63
95
|
|
64
|
-
|
65
|
-
|
66
|
-
|
96
|
+
describe "#attachments" do
|
97
|
+
it "should return proper attachment when given a dime response" do
|
98
|
+
response.attachments.first.data == File.read(File.expand_path("../../fixtures/attachment.gif", __FILE__))
|
99
|
+
end
|
67
100
|
end
|
68
101
|
end
|
69
102
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 7
|
10
|
+
version: 0.7.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Harrington
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-01-
|
19
|
+
date: 2011-01-05 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|