protocol-http1 0.11.0 → 0.13.2
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.
Potentially problematic release.
This version of protocol-http1 might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/protocol/http1/body/chunked.rb +0 -2
- data/lib/protocol/http1/connection.rb +19 -7
- data/lib/protocol/http1/version.rb +1 -1
- metadata +12 -35
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -21
- data/Gemfile +0 -6
- data/README.md +0 -92
- data/examples/http1/request.rb +0 -39
- data/protocol-http1.gemspec +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95b00d4f51351bedac2db6576b3117c37f6de76ab3d06b7535c19bdb45f8c3c5
|
4
|
+
data.tar.gz: d715bee3904278d4e043029aac21032316b7e43f57987a2b50ab5d51bf5d2e77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 481a4d626cdaa358f53f13c3d000aab1512bde51a6bf9f18d5e72310fd6011796b9c037492ed544bb63ebe26a5b009a922d69531440fef1cd65796a236fef812
|
7
|
+
data.tar.gz: e14d62075c96f88ed45bdaedf63b3740ee55c94478c76bc12368671134b1172a83d85480904bdb109d7f1107b3e18718abe9257565f55570699d9df602e203e8
|
@@ -281,14 +281,17 @@ module Protocol
|
|
281
281
|
|
282
282
|
def write_fixed_length_body(body, length, head)
|
283
283
|
@stream.write("content-length: #{length}\r\n\r\n")
|
284
|
-
@stream.flush
|
285
284
|
|
286
285
|
if head
|
286
|
+
@stream.flush
|
287
|
+
|
287
288
|
body.close
|
288
289
|
|
289
290
|
return
|
290
291
|
end
|
291
292
|
|
293
|
+
@stream.flush unless body.ready?
|
294
|
+
|
292
295
|
chunk_length = 0
|
293
296
|
body.each do |chunk|
|
294
297
|
chunk_length += chunk.bytesize
|
@@ -309,21 +312,25 @@ module Protocol
|
|
309
312
|
|
310
313
|
def write_chunked_body(body, head, trailers = nil)
|
311
314
|
@stream.write("transfer-encoding: chunked\r\n\r\n")
|
312
|
-
@stream.flush
|
313
315
|
|
314
316
|
if head
|
317
|
+
@stream.flush
|
318
|
+
|
315
319
|
body.close
|
316
320
|
|
317
321
|
return
|
318
322
|
end
|
319
323
|
|
324
|
+
@stream.flush unless body.ready?
|
325
|
+
|
320
326
|
body.each do |chunk|
|
321
327
|
next if chunk.size == 0
|
322
328
|
|
323
329
|
@stream.write("#{chunk.bytesize.to_s(16).upcase}\r\n")
|
324
330
|
@stream.write(chunk)
|
325
331
|
@stream.write(CRLF)
|
326
|
-
|
332
|
+
|
333
|
+
@stream.flush unless body.ready?
|
327
334
|
end
|
328
335
|
|
329
336
|
if trailers
|
@@ -342,14 +349,15 @@ module Protocol
|
|
342
349
|
@persistent = false
|
343
350
|
|
344
351
|
@stream.write("\r\n")
|
345
|
-
@stream.flush
|
352
|
+
@stream.flush unless body.ready?
|
346
353
|
|
347
354
|
if head
|
348
355
|
body.close
|
349
356
|
else
|
350
357
|
body.each do |chunk|
|
351
358
|
@stream.write(chunk)
|
352
|
-
|
359
|
+
|
360
|
+
@stream.flush unless body.ready?
|
353
361
|
end
|
354
362
|
end
|
355
363
|
|
@@ -357,12 +365,16 @@ module Protocol
|
|
357
365
|
end
|
358
366
|
|
359
367
|
def write_body(version, body, head = false, trailers = nil)
|
360
|
-
if body.nil?
|
368
|
+
if body.nil?
|
361
369
|
write_connection_header(version)
|
362
370
|
write_empty_body(body)
|
363
|
-
elsif length = body.length
|
371
|
+
elsif length = body.length and trailers.nil?
|
364
372
|
write_connection_header(version)
|
365
373
|
write_fixed_length_body(body, length, head)
|
374
|
+
elsif body.empty?
|
375
|
+
# Even thought this code is the same as the first clause `body.nil?`, HEAD responses have an empty body but still carry a content length. `write_fixed_length_body` takes care of this appropriately.
|
376
|
+
write_connection_header(version)
|
377
|
+
write_empty_body(body)
|
366
378
|
elsif @persistent and version == HTTP11
|
367
379
|
write_connection_header(version)
|
368
380
|
# We specifically ensure that non-persistent connections do not use chunked response, so that hijacking works as expected.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: protocol-http
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.19'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: covered
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '0.19'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +39,7 @@ dependencies:
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: covered
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
@@ -81,7 +67,7 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '3.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec-
|
70
|
+
name: rspec-files
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
@@ -95,7 +81,7 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '1.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec-
|
84
|
+
name: rspec-memory
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
@@ -108,20 +94,12 @@ dependencies:
|
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '1.0'
|
111
|
-
description:
|
97
|
+
description:
|
112
98
|
email:
|
113
|
-
- samuel.williams@oriontransfer.co.nz
|
114
99
|
executables: []
|
115
100
|
extensions: []
|
116
101
|
extra_rdoc_files: []
|
117
102
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
|
-
- Gemfile
|
123
|
-
- README.md
|
124
|
-
- examples/http1/request.rb
|
125
103
|
- lib/protocol/http1.rb
|
126
104
|
- lib/protocol/http1/body/chunked.rb
|
127
105
|
- lib/protocol/http1/body/fixed.rb
|
@@ -130,18 +108,17 @@ files:
|
|
130
108
|
- lib/protocol/http1/error.rb
|
131
109
|
- lib/protocol/http1/reason.rb
|
132
110
|
- lib/protocol/http1/version.rb
|
133
|
-
- protocol-http1.gemspec
|
134
111
|
homepage: https://github.com/socketry/protocol-http1
|
135
112
|
licenses:
|
136
113
|
- MIT
|
137
114
|
metadata: {}
|
138
|
-
post_install_message:
|
115
|
+
post_install_message:
|
139
116
|
rdoc_options: []
|
140
117
|
require_paths:
|
141
118
|
- lib
|
142
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
120
|
requirements:
|
144
|
-
- - "
|
121
|
+
- - ">="
|
145
122
|
- !ruby/object:Gem::Version
|
146
123
|
version: '2.4'
|
147
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -151,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
128
|
version: '0'
|
152
129
|
requirements: []
|
153
130
|
rubygems_version: 3.1.2
|
154
|
-
signing_key:
|
131
|
+
signing_key:
|
155
132
|
specification_version: 4
|
156
133
|
summary: A low level implementation of the HTTP/1 protocol.
|
157
134
|
test_files: []
|
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: xenial
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
script: bundle exec rspec
|
6
|
-
|
7
|
-
matrix:
|
8
|
-
include:
|
9
|
-
- rvm: 2.5
|
10
|
-
- rvm: 2.6
|
11
|
-
- rvm: 2.7
|
12
|
-
- rvm: 2.6
|
13
|
-
env: COVERAGE=PartialSummary,Coveralls
|
14
|
-
- rvm: truffleruby
|
15
|
-
- rvm: jruby-head
|
16
|
-
env: JRUBY_OPTS="--debug -X+O"
|
17
|
-
- rvm: ruby-head
|
18
|
-
allow_failures:
|
19
|
-
- rvm: truffleruby
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# Protocol::HTTP1
|
2
|
-
|
3
|
-
Provides a low-level implementation of the HTTP/1 protocol.
|
4
|
-
|
5
|
-
[](https://travis-ci.com/socketry/protocol-http1)
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'protocol-http1'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install protocol-http1
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
Here is a basic HTTP/1.1 client:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
require 'async'
|
29
|
-
require 'async/io/stream'
|
30
|
-
require 'async/http/endpoint'
|
31
|
-
require 'protocol/http1/connection'
|
32
|
-
|
33
|
-
Async do
|
34
|
-
endpoint = Async::HTTP::Endpoint.parse("https://www.google.com/search?q=kittens", alpn_protocols: ["http/1.1"])
|
35
|
-
|
36
|
-
peer = endpoint.connect
|
37
|
-
|
38
|
-
puts "Connected to #{peer} #{peer.remote_address.inspect}"
|
39
|
-
|
40
|
-
# IO Buffering...
|
41
|
-
stream = Async::IO::Stream.new(peer)
|
42
|
-
client = Protocol::HTTP1::Connection.new(stream)
|
43
|
-
|
44
|
-
def client.read_line
|
45
|
-
@stream.read_until(Protocol::HTTP1::Connection::CRLF) or raise EOFError
|
46
|
-
end
|
47
|
-
|
48
|
-
puts "Writing request..."
|
49
|
-
client.write_request("www.google.com", "GET", "/search?q=kittens", "HTTP/1.1", [["Accept", "*/*"]])
|
50
|
-
client.write_body(nil)
|
51
|
-
|
52
|
-
puts "Reading response..."
|
53
|
-
response = client.read_response("GET")
|
54
|
-
|
55
|
-
puts "Got response: #{response.inspect}"
|
56
|
-
|
57
|
-
puts "Closing client..."
|
58
|
-
client.close
|
59
|
-
end
|
60
|
-
```
|
61
|
-
|
62
|
-
## Contributing
|
63
|
-
|
64
|
-
1. Fork it
|
65
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
-
5. Create new Pull Request
|
69
|
-
|
70
|
-
## License
|
71
|
-
|
72
|
-
Released under the MIT license.
|
73
|
-
|
74
|
-
Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
75
|
-
|
76
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
77
|
-
of this software and associated documentation files (the "Software"), to deal
|
78
|
-
in the Software without restriction, including without limitation the rights
|
79
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
80
|
-
copies of the Software, and to permit persons to whom the Software is
|
81
|
-
furnished to do so, subject to the following conditions:
|
82
|
-
|
83
|
-
The above copyright notice and this permission notice shall be included in
|
84
|
-
all copies or substantial portions of the Software.
|
85
|
-
|
86
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
87
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
88
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
89
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
90
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
91
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
92
|
-
THE SOFTWARE.
|
data/examples/http1/request.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
|
4
|
-
|
5
|
-
require 'async'
|
6
|
-
require 'async/io/stream'
|
7
|
-
require 'async/http/endpoint'
|
8
|
-
require 'protocol/http1/connection'
|
9
|
-
require 'pry'
|
10
|
-
|
11
|
-
Async do
|
12
|
-
endpoint = Async::HTTP::Endpoint.parse("https://www.google.com/search?q=kittens", alpn_protocols: ["http/1.1"])
|
13
|
-
|
14
|
-
peer = endpoint.connect
|
15
|
-
|
16
|
-
puts "Connected to #{peer} #{peer.remote_address.inspect}"
|
17
|
-
|
18
|
-
# IO Buffering...
|
19
|
-
stream = Async::IO::Stream.new(peer)
|
20
|
-
client = Protocol::HTTP1::Connection.new(stream)
|
21
|
-
|
22
|
-
def client.read_line
|
23
|
-
@stream.read_until(Protocol::HTTP1::Connection::CRLF) or raise EOFError
|
24
|
-
end
|
25
|
-
|
26
|
-
puts "Writing request..."
|
27
|
-
client.write_request("www.google.com", "GET", "/search?q=kittens", "HTTP/1.1", [["Accept", "*/*"]])
|
28
|
-
client.write_body(nil)
|
29
|
-
|
30
|
-
puts "Reading response..."
|
31
|
-
response = client.read_response("GET")
|
32
|
-
|
33
|
-
puts "Got response: #{response.inspect}"
|
34
|
-
|
35
|
-
puts "Closing client..."
|
36
|
-
client.close
|
37
|
-
end
|
38
|
-
|
39
|
-
puts "Exiting."
|
data/protocol-http1.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'lib/protocol/http1/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "protocol-http1"
|
6
|
-
spec.version = Protocol::HTTP1::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
|
10
|
-
spec.summary = "A low level implementation of the HTTP/1 protocol."
|
11
|
-
spec.homepage = "https://github.com/socketry/protocol-http1"
|
12
|
-
spec.license = "MIT"
|
13
|
-
|
14
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
-
end
|
17
|
-
|
18
|
-
spec.required_ruby_version = "~> 2.4"
|
19
|
-
|
20
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_dependency "protocol-http", "~> 0.16.3"
|
24
|
-
|
25
|
-
spec.add_development_dependency "covered"
|
26
|
-
spec.add_development_dependency "bundler"
|
27
|
-
spec.add_development_dependency "bake-bundler"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
-
spec.add_development_dependency "rspec-memory", "~> 1.0"
|
30
|
-
spec.add_development_dependency "rspec-files", "~> 1.0"
|
31
|
-
end
|