http-protocol 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http/protocol/http1/connection.rb +18 -16
- data/lib/http/protocol/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844a6b761eb8218e0b856cccefc1767cbac8db29ed703d1b8419a532b75bc7bf
|
4
|
+
data.tar.gz: 85dbf29d8cc3aefdbb79af289c0d8a9e91622f8bf13be6ca552cc7ec49acefb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8771480a7207e74671a33f05fe21143039b04458c11489c5f6ffa6d8f36e44c7c5193c938bb7ffdb47c024e70a3f7abce5f212225e97131f60ebb665d7127887
|
7
|
+
data.tar.gz: 16582bbbe013e74ce15db5e2aa61f0f6750bae5e28d43483998d0a9d0b54088ae5ae6771048ca02ff466daab42bc72af96ea7d3d400675d3a09fe6b77699c641
|
@@ -147,6 +147,8 @@ module HTTP
|
|
147
147
|
def read_response(method)
|
148
148
|
version, status, reason = read_line.split(/\s+/, 3)
|
149
149
|
|
150
|
+
status = Integer(status)
|
151
|
+
|
150
152
|
headers = read_headers
|
151
153
|
|
152
154
|
@persistent = persistent?(version, headers)
|
@@ -155,7 +157,7 @@ module HTTP
|
|
155
157
|
|
156
158
|
@count += 1
|
157
159
|
|
158
|
-
return version,
|
160
|
+
return version, status, reason, headers, body
|
159
161
|
end
|
160
162
|
|
161
163
|
def read_headers
|
@@ -315,7 +317,7 @@ module HTTP
|
|
315
317
|
# code is always terminated by the first empty line after the
|
316
318
|
# header fields, regardless of the header fields present in the
|
317
319
|
# message, and thus cannot contain a message body.
|
318
|
-
if method == "HEAD" or status == 204 or status == 304
|
320
|
+
if method == "HEAD" or (status >= 100 and status < 200) or status == 204 or status == 304
|
319
321
|
return nil
|
320
322
|
end
|
321
323
|
|
@@ -328,26 +330,16 @@ module HTTP
|
|
328
330
|
return read_tunnel_body
|
329
331
|
end
|
330
332
|
|
331
|
-
|
332
|
-
return body
|
333
|
-
else
|
334
|
-
# 7. Otherwise, this is a response message without a declared message
|
335
|
-
# body length, so the message body length is determined by the
|
336
|
-
# number of octets received prior to the server closing the
|
337
|
-
# connection.
|
338
|
-
return read_remainder_body
|
339
|
-
end
|
333
|
+
return read_body(headers, true)
|
340
334
|
end
|
341
335
|
|
342
336
|
def read_request_body(headers)
|
343
337
|
# 6. If this is a request message and none of the above are true, then
|
344
338
|
# the message body length is zero (no message body is present).
|
345
|
-
|
346
|
-
return body
|
347
|
-
end
|
339
|
+
return read_body(headers)
|
348
340
|
end
|
349
341
|
|
350
|
-
def read_body(headers)
|
342
|
+
def read_body(headers, remainder = false)
|
351
343
|
# 3. If a Transfer-Encoding header field is present and the chunked
|
352
344
|
# transfer coding (Section 4.1) is the final encoding, the message
|
353
345
|
# body length is determined by reading and decoding the chunked
|
@@ -387,12 +379,22 @@ module HTTP
|
|
387
379
|
# incomplete and close the connection.
|
388
380
|
if content_length = headers.delete(CONTENT_LENGTH)
|
389
381
|
length = Integer(content_length)
|
390
|
-
if length
|
382
|
+
if length > 0
|
391
383
|
return read_fixed_body(length)
|
384
|
+
elsif length == 0
|
385
|
+
return nil
|
392
386
|
else
|
393
387
|
raise BadRequest, "Invalid content length: #{content_length}"
|
394
388
|
end
|
395
389
|
end
|
390
|
+
|
391
|
+
if remainder
|
392
|
+
# 7. Otherwise, this is a response message without a declared message
|
393
|
+
# body length, so the message body length is determined by the
|
394
|
+
# number of octets received prior to the server closing the
|
395
|
+
# connection.
|
396
|
+
return read_remainder_body
|
397
|
+
end
|
396
398
|
end
|
397
399
|
end
|
398
400
|
end
|