http-protocol 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e259d3cffa653715457b5ecae02b116b4ab063bb837828370ac87d5ae5ec6c70
4
- data.tar.gz: 3e4044515e54d35934d1fa90be3c518c5baee318fe7c01f8237dfb0411076f39
3
+ metadata.gz: 844a6b761eb8218e0b856cccefc1767cbac8db29ed703d1b8419a532b75bc7bf
4
+ data.tar.gz: 85dbf29d8cc3aefdbb79af289c0d8a9e91622f8bf13be6ca552cc7ec49acefb9
5
5
  SHA512:
6
- metadata.gz: 8eeddbf50275851a6aa5958cf9efc0f07a004c438b0ef6eb8780819ac1ff5816736d7c0214adbec05d2e387c89f8e3e6077e93913369cac5858139e9168c52b0
7
- data.tar.gz: c05014726647a9fe13f716d119e578f7793e22d496ab29670a3523d5b65cdaed8e5c67114e6614e9c04a41274c2e58cadb2752b89c5e3d73ab33c74e1684f473
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, Integer(status), reason, headers, body
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
- if body = read_body(headers)
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
- if body = read_body(headers)
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 >= 0
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
@@ -20,6 +20,6 @@
20
20
 
21
21
  module HTTP
22
22
  module Protocol
23
- VERSION = "0.8.0"
23
+ VERSION = "0.8.1"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams