Skip to content

Commit

Permalink
raise exception (for now) if transfer encodig is chunked - I'm workin…
Browse files Browse the repository at this point in the history
…g on support for this for requests *and* responses
  • Loading branch information
brianmario committed May 15, 2009
1 parent 4459338 commit 926eabb
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions lib/yajl/http_stream.rb
Expand Up @@ -28,11 +28,12 @@ def self.get(uri, opts = {})
user_agent = opts.has_key?(['User-Agent']) ? opts['User-Agent'] : "Yajl::HttpStream #{Yajl::VERSION}"

socket = TCPSocket.new(uri.host, uri.port)
request = "GET #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.0\r\n"
request = "GET #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.1\r\n"
request << "Host: #{uri.host}\r\n"
request << "Authorization: Basic #{[userinfo].pack('m')}\r\n" unless uri.userinfo.nil?
request << "User-Agent: #{user_agent}\r\n"
request << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
request << "Connection: close\r\n"
encodings = []
encodings << "bzip2" if defined?(Yajl::Bzip2)
encodings << "gzip" if defined?(Yajl::Gzip)
Expand Down Expand Up @@ -60,22 +61,26 @@ def self.get(uri, opts = {})
end
end
end
raise Exception, "Chunked responses not supported yet (I'm working on this)" if response_head[:headers]["Transfer-Encoding"] == 'chunked'
content_type = response_head[:headers]["Content-Type"].split('; ')
content_type = content_type.first
if ALLOWED_MIME_TYPES.include?(content_type)
case response_head[:headers]["Content-Encoding"]
when "gzip"
return Yajl::Gzip::StreamReader.parse(socket)
when "deflate"
return Yajl::Deflate::StreamReader.parse(socket, -Zlib::MAX_WBITS)
when "bzip2"
return Yajl::Bzip2::StreamReader.parse(socket)

if response_head[:headers]["Transfer-Encoding"] == 'chunked'
raise Exception, "Chunked responses not supported yet (I'm working on this)"
else
content_type = response_head[:headers]["Content-Type"].split('; ')
content_type = content_type.first
if ALLOWED_MIME_TYPES.include?(content_type)
case response_head[:headers]["Content-Encoding"]
when "gzip"
return Yajl::Gzip::StreamReader.parse(socket)
when "deflate"
return Yajl::Deflate::StreamReader.parse(socket, -Zlib::MAX_WBITS)
when "bzip2"
return Yajl::Bzip2::StreamReader.parse(socket)
else
return Yajl::Stream.parse(socket)
end
else
return Yajl::Stream.parse(socket)
raise InvalidContentType, "The response MIME type #{content_type}"
end
else
raise InvalidContentType, "The response MIME type #{content_type}"
end
ensure
socket.close
Expand Down

0 comments on commit 926eabb

Please sign in to comment.