Skip to content

Commit

Permalink
Fix bug where header field value may be wrapped in quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsl committed May 25, 2009
1 parent b240153 commit a252f1e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions http_headers.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Gem::Specification.new do |s|
s.name = "http_headers"
s.version = "0.0.2"
s.date = "2009-05-22"
s.version = "0.0.2.1"
s.date = "2009-05-25"
s.summary = "Library for parsing the Curl header_str into attributes"
s.email = "justin@phq.org"
s.homepage = "http://github.com/jsl/hashback"
s.description = "Creates an object from the attributes in a header_str from Curl"
s.description = "Parses a HTTP header string into individual header fields"
s.has_rdoc = true
s.authors = ["Justin Leitgeb"]
s.files = [
Expand Down
5 changes: 4 additions & 1 deletion lib/http_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def detect_multi_value_keys(tag)
# Returns the key from this tag, which should be a string with key separated
# from val by ':'
def value_from(tag)
tag.split(/:\W+/)[1]
val = tag.split(/:\s+/)[1]

# Value may be surrounded by quotes in some cases. Remove these extra quotes here.
val =~ /^\"(.*)\"$/ ? $1 : val
end
end
13 changes: 13 additions & 0 deletions spec/fixtures/headers3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HTTP/1.1 200 OK
Date: Mon, 25 May 2009 12:36:53 GMT
Server: Apache/2
Last-Modified: Wed, 01 Sep 2004 13:24:52 GMT
ETag: "1edec-3e3073913b100"
Accept-Ranges: bytes
Content-Length: 126444
Cache-Control: max-age=21600
Expires: Mon, 25 May 2009 18:36:53 GMT
P3P: policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Connection: close
Content-Type: text/html; charset=iso-8859-1

7 changes: 7 additions & 0 deletions spec/http_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
before do
@h = HttpHeaders.new(File.read(File.join(File.dirname(__FILE__), %w[fixtures headers.txt])))
@h2 = HttpHeaders.new(File.read(File.join(File.dirname(__FILE__), %w[fixtures headers2.txt])))
@h3 = HttpHeaders.new(File.read(File.join(File.dirname(__FILE__), %w[fixtures headers3.txt])))
end

it "should have text/html as the content_type" do
Expand All @@ -22,6 +23,12 @@
@h2.etag.should == 'pnDSjJtGvlc2WrX6VND/w0qxEc8'
end

# @h3 tests stripping an etag from a value section of a header where the value is wrapped in
# quotes as given by the HTTP server.
it "should have an etag of 1edec-3e3073913b100 for headers3" do
@h3.etag.should == '1edec-3e3073913b100'
end

it "should have Fri, 22 May 2009 18:18:08 GMT for date" do
@h2.date.should == 'Fri, 22 May 2009 18:18:08 GMT'
end
Expand Down

0 comments on commit a252f1e

Please sign in to comment.