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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c5839148e12cf89cbdc454de6155fd7d9a7a515208bdd83ffba741388591dc7
4
- data.tar.gz: 58bb3176945607e04975f4132da07900deeda442d8709d0e458cdb4c093c621e
3
+ metadata.gz: 5bc04ecccff6cd4f16fdc254fcc2b61052f3cd1922d1f2c6b131c2247f3ae725
4
+ data.tar.gz: aeb44e87fa81e9f545a009de98b2d895d408cd6ce67056f857f1ab5d2f35843f
5
5
  SHA512:
6
- metadata.gz: 1a71227da852e031044b11bb2a6f6eb7b362129144394eacae489cf7bf14576705ed221eac73b4fa6020a80fb959842719858714f8537b978c35dd1da881454f
7
- data.tar.gz: 34ab52b88c502e04b72df8373a23256d3a290efc9cfe933e28d9b4ea87f95242acf1de9a271426cc7eb10fb6e15cb14779be19ebef08855014c542a53ecd3e29
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
- def dup(path = nil, parameters = nil, merge = true)
131
- if merge and @parameters
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, @fragment, parameters)
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
- def expand_path(base, relative)
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
- # drop the last path element for relative computations, e.g.
164
- # /foo/bar/index.html -> /foo/bar/#{relative}
165
- path.pop
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
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module HTTP
23
- VERSION = "0.6.0"
23
+ VERSION = "0.7.0"
24
24
  end
25
25
  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.6.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-30 00:00:00.000000000 Z
11
+ date: 2019-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: covered