protocol-http1 0.14.6 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of protocol-http1 might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http1/body/fixed.rb +6 -3
- data/lib/protocol/http1/connection.rb +22 -27
- data/lib/protocol/http1/error.rb +5 -1
- data/lib/protocol/http1/version.rb +1 -1
- data/license.md +3 -1
- data.tar.gz.sig +0 -0
- metadata +8 -36
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1c040780ba6a7bae3e921d5a7ff40ba5e656ce66d8a138d2c5382ce42efc317
|
4
|
+
data.tar.gz: 551dbe0ecbc187b7b3c0c86507d737eace6b41c4f3b62f0d8a7c6f6d8b0bd0a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57fcfd40cf929f6e6a096d07513378b6631d5dbdab25431c9c8763fea9e4a1967e77adc8bddc55a2ca8eb5b3232088bbaf9d0af1fed8dad05af20e3702e4ef2
|
7
|
+
data.tar.gz: f736986596addfec4908e05d9bf632f79f906cf1508076ec7e5dd5de1e08efee33c9c1edd512aef50c4f483db92b92481ba68929edbefe454db57b445b969f8c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'protocol/http/body/readable'
|
7
7
|
|
@@ -23,6 +23,7 @@ module Protocol
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def close(error = nil)
|
26
|
+
# If we are closing the body without fully reading it, the underlying connection is now in an undefined state.
|
26
27
|
if @remaining != 0
|
27
28
|
@stream.close
|
28
29
|
end
|
@@ -30,14 +31,16 @@ module Protocol
|
|
30
31
|
super
|
31
32
|
end
|
32
33
|
|
34
|
+
# @raises EOFError if the stream is closed before the expected length is read.
|
33
35
|
def read
|
34
36
|
if @remaining > 0
|
37
|
+
# `readpartial` will raise `EOFError` if the stream is closed/finished:
|
35
38
|
if chunk = @stream.readpartial(@remaining)
|
36
39
|
@remaining -= chunk.bytesize
|
37
40
|
|
38
41
|
return chunk
|
39
|
-
else
|
40
|
-
|
42
|
+
# else
|
43
|
+
# raise EOFError, "Stream closed with #{@remaining} bytes remaining!"
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2019, by Brian Morearty.
|
5
6
|
# Copyright, 2020, by Bruno Sutic.
|
6
7
|
|
7
8
|
require 'protocol/http/headers'
|
@@ -31,7 +32,7 @@ module Protocol
|
|
31
32
|
UPGRADE = 'upgrade'
|
32
33
|
|
33
34
|
# HTTP/1.x request line parser:
|
34
|
-
TOKEN = /[!#$%&'
|
35
|
+
TOKEN = /[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
|
35
36
|
REQUEST_LINE = /\A(#{TOKEN}) ([^\s]+) (HTTP\/\d.\d)\z/.freeze
|
36
37
|
|
37
38
|
# HTTP/1.x header parser:
|
@@ -63,12 +64,6 @@ module Protocol
|
|
63
64
|
# The number of requests processed.
|
64
65
|
attr :count
|
65
66
|
|
66
|
-
def upgrade?(headers)
|
67
|
-
if upgrade = headers[UPGRADE]
|
68
|
-
return upgrade
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
67
|
def persistent?(version, method, headers)
|
73
68
|
if method == HTTP::Methods::CONNECT
|
74
69
|
return false
|
@@ -281,7 +276,7 @@ module Protocol
|
|
281
276
|
chunk_length += chunk.bytesize
|
282
277
|
|
283
278
|
if chunk_length > length
|
284
|
-
raise
|
279
|
+
raise ContentLengthError, "Trying to write #{chunk_length} bytes, but content length was #{length} bytes!"
|
285
280
|
end
|
286
281
|
|
287
282
|
@stream.write(chunk)
|
@@ -291,7 +286,7 @@ module Protocol
|
|
291
286
|
@stream.flush
|
292
287
|
|
293
288
|
if chunk_length != length
|
294
|
-
raise
|
289
|
+
raise ContentLengthError, "Wrote #{chunk_length} bytes, but content length was #{length} bytes!"
|
295
290
|
end
|
296
291
|
end
|
297
292
|
|
@@ -400,13 +395,19 @@ module Protocol
|
|
400
395
|
read_remainder_body
|
401
396
|
end
|
402
397
|
|
403
|
-
def read_upgrade_body(protocol)
|
404
|
-
read_remainder_body
|
405
|
-
end
|
406
|
-
|
407
398
|
HEAD = "HEAD"
|
408
399
|
CONNECT = "CONNECT"
|
409
400
|
|
401
|
+
def extract_content_length(headers)
|
402
|
+
if content_length = headers.delete(CONTENT_LENGTH)
|
403
|
+
if length = Integer(content_length, exception: false) and length >= 0
|
404
|
+
yield length
|
405
|
+
else
|
406
|
+
raise BadRequest, "Invalid content length: #{content_length}"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
410
411
|
def read_response_body(method, status, headers)
|
411
412
|
# RFC 7230 3.3.3
|
412
413
|
# 1. Any response to a HEAD request and any response with a 1xx
|
@@ -415,19 +416,16 @@ module Protocol
|
|
415
416
|
# header fields, regardless of the header fields present in the
|
416
417
|
# message, and thus cannot contain a message body.
|
417
418
|
if method == HTTP::Methods::HEAD
|
418
|
-
|
419
|
-
length = Integer(content_length)
|
420
|
-
|
419
|
+
extract_content_length(headers) do |length|
|
421
420
|
if length > 0
|
422
421
|
return read_head_body(length)
|
423
|
-
elsif length == 0
|
424
|
-
return nil
|
425
422
|
else
|
426
|
-
|
423
|
+
return nil
|
427
424
|
end
|
428
|
-
else
|
429
|
-
return nil
|
430
425
|
end
|
426
|
+
|
427
|
+
# There is no body for a HEAD request if there is no content length:
|
428
|
+
return nil
|
431
429
|
end
|
432
430
|
|
433
431
|
if (status >= 100 and status < 200) or status == 204 or status == 304
|
@@ -499,14 +497,11 @@ module Protocol
|
|
499
497
|
# the recipient times out before the indicated number of octets are
|
500
498
|
# received, the recipient MUST consider the message to be
|
501
499
|
# incomplete and close the connection.
|
502
|
-
|
503
|
-
length = Integer(content_length)
|
500
|
+
extract_content_length(headers) do |length|
|
504
501
|
if length > 0
|
505
502
|
return read_fixed_body(length)
|
506
|
-
elsif length == 0
|
507
|
-
return nil
|
508
503
|
else
|
509
|
-
|
504
|
+
return nil
|
510
505
|
end
|
511
506
|
end
|
512
507
|
|
data/lib/protocol/http1/error.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'protocol/http/error'
|
7
7
|
|
@@ -13,6 +13,10 @@ module Protocol
|
|
13
13
|
class InvalidRequest < Error
|
14
14
|
end
|
15
15
|
|
16
|
+
# The specified content length and the given content's length do not match.
|
17
|
+
class ContentLengthError < Error
|
18
|
+
end
|
19
|
+
|
16
20
|
# The request was parsed correctly, but was invalid for some other reason.
|
17
21
|
class BadRequest < Error
|
18
22
|
end
|
data/license.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# MIT License
|
2
2
|
|
3
|
-
Copyright, 2019-
|
3
|
+
Copyright, 2019-2023, by Samuel Williams.
|
4
|
+
Copyright, 2019, by Brian Morearty.
|
5
|
+
Copyright, 2020, by Olle Jonsson.
|
4
6
|
Copyright, 2020, by Bruno Sutic.
|
5
7
|
|
6
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -40,7 +40,7 @@ cert_chain:
|
|
40
40
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
41
41
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
42
42
|
-----END CERTIFICATE-----
|
43
|
-
date:
|
43
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
44
44
|
dependencies:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: protocol-http
|
@@ -85,47 +85,19 @@ dependencies:
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
88
|
+
name: sus
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- - "
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '3.0'
|
94
|
-
type: :development
|
95
|
-
prerelease: false
|
96
|
-
version_requirements: !ruby/object:Gem::Requirement
|
97
|
-
requirements:
|
98
|
-
- - "~>"
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: '3.0'
|
101
|
-
- !ruby/object:Gem::Dependency
|
102
|
-
name: rspec-files
|
103
|
-
requirement: !ruby/object:Gem::Requirement
|
104
|
-
requirements:
|
105
|
-
- - "~>"
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
version: '1.0'
|
108
|
-
type: :development
|
109
|
-
prerelease: false
|
110
|
-
version_requirements: !ruby/object:Gem::Requirement
|
111
|
-
requirements:
|
112
|
-
- - "~>"
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: '1.0'
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
|
-
name: rspec-memory
|
117
|
-
requirement: !ruby/object:Gem::Requirement
|
118
|
-
requirements:
|
119
|
-
- - "~>"
|
91
|
+
- - ">="
|
120
92
|
- !ruby/object:Gem::Version
|
121
|
-
version: '
|
93
|
+
version: '0'
|
122
94
|
type: :development
|
123
95
|
prerelease: false
|
124
96
|
version_requirements: !ruby/object:Gem::Requirement
|
125
97
|
requirements:
|
126
|
-
- - "
|
98
|
+
- - ">="
|
127
99
|
- !ruby/object:Gem::Version
|
128
|
-
version: '
|
100
|
+
version: '0'
|
129
101
|
description:
|
130
102
|
email:
|
131
103
|
executables: []
|
@@ -161,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
133
|
- !ruby/object:Gem::Version
|
162
134
|
version: '0'
|
163
135
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.4.1
|
165
137
|
signing_key:
|
166
138
|
specification_version: 4
|
167
139
|
summary: A low level implementation of the HTTP/1 protocol.
|
metadata.gz.sig
CHANGED
Binary file
|