protocol-http 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protocol/http/reference.rb +34 -10
- data/lib/protocol/http/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc04ecccff6cd4f16fdc254fcc2b61052f3cd1922d1f2c6b131c2247f3ae725
|
4
|
+
data.tar.gz: aeb44e87fa81e9f545a009de98b2d895d408cd6ce67056f857f1ab5d2f35843f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7de2d5a3d9b7b2548b4258bf549a913f682c0e199bd11d466b50e439a67ce2443138b2bbb27a6da97c57c9b3bd5fa69a70b792f79cddc38c469f832d4ab91e0b
|
7
|
+
data.tar.gz: c54173c864bda0b4a9b6c5e8c282ec60790871a0a1bbbace5a1b53fe6c2a570d214d5f11d32723ee21ef1b5fe0e78ebf73d7dd223addbe424c3f664f805cf75c
|
@@ -24,7 +24,7 @@ require_relative 'url'
|
|
24
24
|
|
25
25
|
module Protocol
|
26
26
|
module HTTP
|
27
|
-
# A relative reference, excluding any authority.
|
27
|
+
# A relative reference, excluding any authority. The path part of an HTTP request.
|
28
28
|
class Reference
|
29
29
|
include Comparable
|
30
30
|
|
@@ -116,19 +116,28 @@ module Protocol
|
|
116
116
|
|
117
117
|
alias to_s to_str
|
118
118
|
|
119
|
+
# Merges two references as specified by RFC2396, similar to `URI.join`.
|
119
120
|
def + other
|
120
121
|
other = self.class[other]
|
121
122
|
|
122
123
|
self.class.new(
|
123
|
-
expand_path(self.path, other.path),
|
124
|
+
expand_path(self.path, other.path, true),
|
124
125
|
other.query_string,
|
125
126
|
other.fragment,
|
126
127
|
other.parameters,
|
127
128
|
)
|
128
129
|
end
|
129
130
|
|
130
|
-
|
131
|
-
|
131
|
+
# Just the base path, without any query string, parameters or fragment.
|
132
|
+
def base
|
133
|
+
self.class.new(@path, nil, nil, nil)
|
134
|
+
end
|
135
|
+
|
136
|
+
# @option path [String] Append the string to this reference similar to `File.join`.
|
137
|
+
# @option parameters [Hash] Append the parameters to this reference.
|
138
|
+
# @option fragment [String] Set the fragment to this value.
|
139
|
+
def with(path: nil, parameters: nil, fragment: @fragment)
|
140
|
+
if @parameters
|
132
141
|
if parameters
|
133
142
|
parameters = @parameters.merge(parameters)
|
134
143
|
else
|
@@ -137,12 +146,21 @@ module Protocol
|
|
137
146
|
end
|
138
147
|
|
139
148
|
if path
|
140
|
-
path = expand_path(@path, path)
|
149
|
+
path = expand_path(@path, path, false)
|
141
150
|
else
|
142
151
|
path = @path
|
143
152
|
end
|
144
153
|
|
145
|
-
self.class.new(path, @query_string,
|
154
|
+
self.class.new(path, @query_string, fragment, parameters)
|
155
|
+
end
|
156
|
+
|
157
|
+
# The arguments to this function are legacy, prefer to use `with`.
|
158
|
+
def dup(path = nil, parameters = nil, merge_parameters = true)
|
159
|
+
if merge_parameters
|
160
|
+
with(path: path, parameters: parameters)
|
161
|
+
else
|
162
|
+
self.base.with(path: path, parameters: parameters)
|
163
|
+
end
|
146
164
|
end
|
147
165
|
|
148
166
|
private
|
@@ -155,20 +173,26 @@ module Protocol
|
|
155
173
|
end
|
156
174
|
end
|
157
175
|
|
158
|
-
|
176
|
+
# @param pop [Boolean] whether to remove the last path component of the base path, to conform to URI merging behaviour, as defined by RFC2396.
|
177
|
+
def expand_path(base, relative, pop = true)
|
159
178
|
if relative.start_with? '/'
|
160
179
|
return relative
|
161
180
|
else
|
162
181
|
path = split(base)
|
163
|
-
|
164
|
-
#
|
165
|
-
path
|
182
|
+
|
183
|
+
# RFC2396 Section 5.2:
|
184
|
+
# 6) a) All but the last segment of the base URI's path component is
|
185
|
+
# copied to the buffer. In other words, any characters after the
|
186
|
+
# last (right-most) slash character, if any, are excluded.
|
187
|
+
path.pop if pop or path.last == ''
|
166
188
|
|
167
189
|
parts = split(relative)
|
168
190
|
|
169
191
|
parts.each do |part|
|
170
192
|
if part == '..'
|
171
193
|
path.pop
|
194
|
+
elsif part == '.'
|
195
|
+
# Do nothing.
|
172
196
|
else
|
173
197
|
path << part
|
174
198
|
end
|
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.7.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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: covered
|