lib/httpx/response.rb in httpx-0.2.1 vs lib/httpx/response.rb in httpx-0.3.0
- old
+ new
@@ -39,15 +39,11 @@
@body.write(data)
end
def bodyless?
@request.verb == :head ||
- @status < 200 ||
- @status == 201 ||
- @status == 204 ||
- @status == 205 ||
- @status == 304
+ no_data?
end
def content_type
ContentType.parse(@headers["content-type"])
end
@@ -63,10 +59,23 @@
def raise_for_status
return if @status < 400
raise HTTPError, self
end
+ private
+
+ def no_data?
+ @status < 200 ||
+ @status == 204 ||
+ @status == 205 ||
+ @status == 304 || begin
+ content_length = @headers["content-length"]
+ return false if content_length.nil?
+ content_length == "0"
+ end
+ end
+
class Body
def initialize(response, threshold_size:, window_size: 1 << 14)
@response = response
@headers = response.headers
@threshold_size = threshold_size
@@ -168,10 +177,10 @@
@buffer = StringIO.new("".b, File::RDWR)
end
when :memory
if @length > @threshold_size
aux = @buffer
- @buffer = Tempfile.new("palanca", encoding: @encoding, mode: File::RDWR)
+ @buffer = Tempfile.new("httpx", encoding: @encoding, mode: File::RDWR)
aux.rewind
::IO.copy_stream(aux, @buffer)
# TODO: remove this if/when minor ruby is 2.3
# (this looks like a bug from older versions)
@buffer.pos = aux.pos #######################