httpi 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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['Content-Type'] == 'application/dime'
60
+ headers["Content-Type"] == "application/dime"
58
61
  end
59
62
 
60
63
  # Returns the gzip decoded response body.
@@ -1,5 +1,5 @@
1
1
  module HTTPI
2
2
 
3
- VERSION = "0.7.6"
3
+ VERSION = "0.7.7"
4
4
 
5
5
  end
@@ -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
- describe "#code" do
8
- it "should return the HTTP response code" do
9
- response.code.should == 200
10
- end
6
+ context "normal" do
7
+ let(:response) { HTTPI::Response.new 200, {}, Fixture.xml }
11
8
 
12
- it "should always return an Integer" do
13
- response = HTTPI::Response.new "200", {}, ""
14
- response.code.should == 200
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
- end
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 HTTPI::Response, "gzip" do
21
- let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.gzip }
21
+ describe "#code" do
22
+ it "should return the HTTP response code" do
23
+ response.code.should == 200
24
+ end
22
25
 
23
- describe "#headers" do
24
- it "should return the HTTP response headers" do
25
- response.headers.should == { "Content-Encoding" => "gzip" }
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
- describe "#body" do
30
- it "should return the (gzip decoded) HTTP response body" do
31
- response.body.should == Fixture.xml
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
- describe "#raw_body" do
36
- it "should return the raw HTML response body" do
37
- response.raw_body.should == Fixture.gzip
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
- end
53
+ context "gzipped" do
54
+ let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.gzip }
42
55
 
43
- describe HTTPI::Response, "DIME" do
44
- let(:response) { HTTPI::Response.new 200, { "Content-Type" => "application/dime" }, Fixture.dime }
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
- describe "#headers" do
47
- it "should return the HTTP response headers" do
48
- response.headers.should == { "Content-Type" => "application/dime" }
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
- describe "#body" do
53
- it "should return the (dime decoded) HTTP response body" do
54
- response.body.should == Fixture.xml_dime
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
- describe "#raw_body" do
59
- it "should return the raw HTML response body" do
60
- response.raw_body.should == Fixture.dime
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
- describe "#attachments" do
65
- it "should return proper attachment when given a dime response" do
66
- response.attachments.first.data == File.read(File.expand_path("../../fixtures/attachment.gif", __FILE__))
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 6
10
- version: 0.7.6
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-03 00:00:00 +01:00
19
+ date: 2011-01-05 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency