protocol-http 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/protocol/http/error.rb +3 -1
- data/lib/protocol/http/headers.rb +18 -6
- data/lib/protocol/http/methods.rb +12 -10
- data/lib/protocol/http/reference.rb +40 -19
- data/lib/protocol/http/url.rb +2 -0
- data/lib/protocol/http/version.rb +1 -1
- metadata +2 -3
- data/lib/protocol/http/cgi.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 152ed75f85cb113b719ac90857bcd9e1cc0a8e87ae509c552a1de0086817295e
|
4
|
+
data.tar.gz: 48b3bef0834d0eb325433b53007a44b9d57f1b327301ac427ab9ef7303e8f11e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a71ba59c41375ab3002b65a4d7bc517ccb45e5a7d44b0a9e6e7fce7bb80806ecc9c60bf102619cfb32629642d609bda5cb92ca1dee51768dc90ff32173da7ad1
|
7
|
+
data.tar.gz: 7483f5278eb4d49b646eca43aabd38717f183359ef0be143c670fee21b2fcd993c721c36340923d74242c8b8cd207414fe146ab9ceea534c3e41fb8e54145671
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Protocol::HTTP
|
2
2
|
|
3
|
-
Provides abstractions for working with the HTTP protocol
|
3
|
+
Provides abstractions for working with the HTTP protocol.
|
4
4
|
|
5
5
|
[![Build Status](https://secure.travis-ci.com/socketry/protocol-http.svg)](http://travis-ci.com/socketry/protocol-http)
|
6
6
|
|
@@ -70,7 +70,6 @@ parameters = Protocol::HTTP::URL.decode(reference.query_string)
|
|
70
70
|
Released under the MIT license.
|
71
71
|
|
72
72
|
Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
73
|
-
Copyright, 2013, by Ilya Grigorik.
|
74
73
|
|
75
74
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
76
75
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/protocol/http/error.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
1
3
|
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
# Copyright, 2013, by Ilya Grigorik.
|
3
4
|
#
|
4
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -21,6 +22,7 @@
|
|
21
22
|
|
22
23
|
module Protocol
|
23
24
|
module HTTP
|
25
|
+
# A generic, HTTP protocol error.
|
24
26
|
class Error < StandardError
|
25
27
|
end
|
26
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -22,7 +24,7 @@ module Protocol
|
|
22
24
|
module HTTP
|
23
25
|
# Headers are an array of key-value pairs. Some header keys represent multiple values.
|
24
26
|
class Headers
|
25
|
-
#
|
27
|
+
# Header value which is split by commas.
|
26
28
|
class Split < Array
|
27
29
|
COMMA = /\s*,\s*/
|
28
30
|
|
@@ -31,7 +33,7 @@ module Protocol
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def << value
|
34
|
-
|
36
|
+
self.push(*value.split(COMMA))
|
35
37
|
end
|
36
38
|
|
37
39
|
def to_s
|
@@ -39,7 +41,7 @@ module Protocol
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
#
|
44
|
+
# Header value which is split by newline charaters (e.g. cookies).
|
43
45
|
class Multiple < Array
|
44
46
|
def initialize(value)
|
45
47
|
super()
|
@@ -80,9 +82,12 @@ module Protocol
|
|
80
82
|
def freeze
|
81
83
|
return if frozen?
|
82
84
|
|
83
|
-
#
|
85
|
+
# Ensure @indexed is generated:
|
84
86
|
self.to_h
|
85
87
|
|
88
|
+
@fields.freeze
|
89
|
+
@indexed.freeze
|
90
|
+
|
86
91
|
super
|
87
92
|
end
|
88
93
|
|
@@ -222,21 +227,28 @@ module Protocol
|
|
222
227
|
end
|
223
228
|
|
224
229
|
def == other
|
225
|
-
|
230
|
+
case other
|
231
|
+
when Hash
|
226
232
|
to_h == other
|
227
|
-
|
233
|
+
when Headers
|
228
234
|
@fields == other.fields
|
235
|
+
else
|
236
|
+
@fields == other
|
229
237
|
end
|
230
238
|
end
|
231
239
|
|
232
240
|
# Used for merging objects into a sequential list of headers. Normalizes header keys and values.
|
233
241
|
class Merged
|
242
|
+
include Enumerable
|
243
|
+
|
234
244
|
def initialize(*all)
|
235
245
|
@all = all
|
236
246
|
end
|
237
247
|
|
238
248
|
def << headers
|
239
249
|
@all << headers
|
250
|
+
|
251
|
+
return self
|
240
252
|
end
|
241
253
|
|
242
254
|
# @yield [String, String] header key (lower case) and value (as string).
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
1
3
|
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -22,16 +24,16 @@ module Protocol
|
|
22
24
|
module HTTP
|
23
25
|
# HTTP method verbs
|
24
26
|
module Methods
|
25
|
-
GET = 'GET'
|
26
|
-
POST = 'POST'
|
27
|
-
PUT = 'PUT'
|
28
|
-
PATCH = 'PATCH'
|
29
|
-
DELETE = 'DELETE'
|
30
|
-
HEAD = 'HEAD'
|
31
|
-
OPTIONS = 'OPTIONS'
|
32
|
-
LINK = 'LINK'
|
33
|
-
UNLINK = 'UNLINK'
|
34
|
-
TRACE = 'TRACE'
|
27
|
+
GET = 'GET'
|
28
|
+
POST = 'POST'
|
29
|
+
PUT = 'PUT'
|
30
|
+
PATCH = 'PATCH'
|
31
|
+
DELETE = 'DELETE'
|
32
|
+
HEAD = 'HEAD'
|
33
|
+
OPTIONS = 'OPTIONS'
|
34
|
+
LINK = 'LINK'
|
35
|
+
UNLINK = 'UNLINK'
|
36
|
+
TRACE = 'TRACE'
|
35
37
|
|
36
38
|
# Use Methods.constants to get all constants.
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
1
3
|
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -24,6 +26,8 @@ module Protocol
|
|
24
26
|
module HTTP
|
25
27
|
# A relative reference, excluding any authority.
|
26
28
|
class Reference
|
29
|
+
include Comparable
|
30
|
+
|
27
31
|
# Generate a reference from a path and user parameters. The path may contain a `#fragment` or `?query=parameters`.
|
28
32
|
def self.parse(path = '/', parameters = nil)
|
29
33
|
base, fragment = path.split('#', 2)
|
@@ -32,32 +36,51 @@ module Protocol
|
|
32
36
|
self.new(path, query_string, fragment, parameters)
|
33
37
|
end
|
34
38
|
|
35
|
-
def initialize(path, query_string = nil, fragment = nil, parameters = nil)
|
39
|
+
def initialize(path = '/', query_string = nil, fragment = nil, parameters = nil)
|
36
40
|
@path = path
|
37
41
|
@query_string = query_string
|
38
42
|
@fragment = fragment
|
39
43
|
@parameters = parameters
|
40
44
|
end
|
41
45
|
|
42
|
-
def self.[] reference
|
43
|
-
if reference.is_a? self
|
44
|
-
return reference
|
45
|
-
else
|
46
|
-
return self.parse(reference)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
46
|
# The path component, e.g. /foo/bar/index.html
|
51
|
-
|
47
|
+
attr_accessor :path
|
52
48
|
|
53
49
|
# The un-parsed query string, e.g. 'x=10&y=20'
|
54
|
-
|
50
|
+
attr_accessor :query_string
|
55
51
|
|
56
52
|
# A fragment, the part after the '#'
|
57
|
-
|
53
|
+
attr_accessor :fragment
|
58
54
|
|
59
55
|
# User supplied parameters that will be appended to the query part.
|
60
|
-
|
56
|
+
attr_accessor :parameters
|
57
|
+
|
58
|
+
def freeze
|
59
|
+
return self if frozen?
|
60
|
+
|
61
|
+
@path.freeze
|
62
|
+
@query_string.freeze
|
63
|
+
@fragment.freeze
|
64
|
+
@parameters.freeze
|
65
|
+
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_ary
|
70
|
+
[@path, @query_string, @fragment, @parameters]
|
71
|
+
end
|
72
|
+
|
73
|
+
def <=> other
|
74
|
+
to_ary <=> other.to_ary
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.[] reference
|
78
|
+
if reference.is_a? self
|
79
|
+
return reference
|
80
|
+
else
|
81
|
+
return self.parse(reference)
|
82
|
+
end
|
83
|
+
end
|
61
84
|
|
62
85
|
def parameters?
|
63
86
|
@parameters and !@parameters.empty?
|
@@ -104,12 +127,8 @@ module Protocol
|
|
104
127
|
)
|
105
128
|
end
|
106
129
|
|
107
|
-
def [] parameters
|
108
|
-
self.dup(nil, parameters)
|
109
|
-
end
|
110
|
-
|
111
130
|
def dup(path = nil, parameters = nil, merge = true)
|
112
|
-
if
|
131
|
+
if merge and @parameters
|
113
132
|
if parameters
|
114
133
|
parameters = @parameters.merge(parameters)
|
115
134
|
else
|
@@ -132,7 +151,9 @@ module Protocol
|
|
132
151
|
if relative.start_with? '/'
|
133
152
|
return relative
|
134
153
|
else
|
135
|
-
path = base.split('/')
|
154
|
+
path = base.split('/', -1)
|
155
|
+
path.pop
|
156
|
+
|
136
157
|
parts = relative.split('/')
|
137
158
|
|
138
159
|
parts.each do |part|
|
data/lib/protocol/http/url.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: covered
|
@@ -81,7 +81,6 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/protocol/http.rb
|
84
|
-
- lib/protocol/http/cgi.rb
|
85
84
|
- lib/protocol/http/error.rb
|
86
85
|
- lib/protocol/http/headers.rb
|
87
86
|
- lib/protocol/http/methods.rb
|
data/lib/protocol/http/cgi.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
module Protocol
|
22
|
-
module HTTP
|
23
|
-
# CGI keys (https://tools.ietf.org/html/rfc3875#section-4.1)
|
24
|
-
module CGI
|
25
|
-
AUTH_TYPE = "AUTH_TYPE".freeze
|
26
|
-
CONTENT_LENGTH = "CONTENT_LENGTH".freeze
|
27
|
-
CONTENT_TYPE = "CONTENT_TYPE".freeze
|
28
|
-
GATEWAY_INTERFACE = "GATEWAY_INTERFACE".freeze
|
29
|
-
PATH_INFO = "PATH_INFO".freeze
|
30
|
-
PATH_TRANSLATED = "PATH_TRANSLATED".freeze
|
31
|
-
QUERY_STRING = "QUERY_STRING".freeze
|
32
|
-
REMOTE_ADDR = "REMOTE_ADDR".freeze
|
33
|
-
REMOTE_HOST = "REMOTE_HOST".freeze
|
34
|
-
REMOTE_IDENT = "REMOTE_IDENT".freeze
|
35
|
-
REMOTE_USER = "REMOTE_USER".freeze
|
36
|
-
REQUEST_METHOD = "REQUEST_METHOD".freeze
|
37
|
-
SCRIPT_NAME = "SCRIPT_NAME".freeze
|
38
|
-
SERVER_NAME = "SERVER_NAME".freeze
|
39
|
-
SERVER_PORT = "SERVER_PORT".freeze
|
40
|
-
SERVER_PROTOCOL = "SERVER_PROTOCOL".freeze
|
41
|
-
SERVER_SOFTWARE = "SERVER_SOFTWARE".freeze
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|