protocol-http 0.19.0 → 0.20.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0af75765a43c5fb19b3071937a6162477ebdb206811be34f5d74c7881688117e
4
- data.tar.gz: 7eef98e2de4c86ddb2f4cd5a77d61f8a2ca3998e30d8bef61d95d7c4bb902c34
3
+ metadata.gz: 155e5d73168b2ff9c429d2677150ae8a30e87ee8fb25a582ac30671f8e015ad2
4
+ data.tar.gz: c3ae63c177fc673100717c5f2c81bbde8e8a3192de7d010e903593f82d68f2e4
5
5
  SHA512:
6
- metadata.gz: 7f42ab4cd4bf8bf144ced1758316ab181a78687b89882e6d63d10ac190112dfc6aaa02800af6048d7ee12f510d8c805736a412bdb32926c81baaf85f46994dd3
7
- data.tar.gz: 020bc0c0ff0d2b687117cbbdd09fe38e0c7e5510f3b94f96f3de6e3eed3ecf32fad35cc408cd3fd3af63fdb0500aae841fba67c6835272b9a06b2b7d0c36b7f9
6
+ metadata.gz: '08db581bcc0840a176039b99f8a9bb31c9db02fb9476ef318c26db8b37d73626754d929efd3cddc70446c5dbecb1708d8bb0347c873a0328b79fe6a0faf6fcdb'
7
+ data.tar.gz: 64a7ff013c2e459c594f9c87dcd19d0056d9492136b9c97121d411ebafd74cfe47feacc76842863af7e40d9c38a877ef143e6d0253cf052a63648091f829f8d0
@@ -40,7 +40,7 @@ module Protocol
40
40
  URL.escape(@value)
41
41
  end
42
42
 
43
- def to_str
43
+ def to_s
44
44
  buffer = String.new.b
45
45
 
46
46
  buffer << encoded_name << '=' << encoded_value
@@ -26,21 +26,23 @@ module Protocol
26
26
  module HTTP
27
27
  module Header
28
28
  # Used for basic authorization.
29
- # @example headers.add('authorization', Authorization.new("samuel", "password"))
30
- class Authorization
31
- KEY = "Authorization"
32
-
33
- def initialize(username, password)
34
- @username = username
35
- @password = password
36
- end
37
-
38
- def encoded
39
- "#{@username}:#{@password}"
29
+ #
30
+ # ~~~ ruby
31
+ # headers.add('authorization', Authorization.basic("my_username", "my_password"))
32
+ # ~~~
33
+ class Authorization < String
34
+ # Splits the header and
35
+ # @return [Tuple(String, String)]
36
+ def credentials
37
+ self.split(/\s+/, 2)
40
38
  end
41
39
 
42
- def to_str
43
- 'Basic %s' % Base64.strict_encode64(self.encoded)
40
+ def self.basic(username, password)
41
+ encoded = "#{username}:#{password}"
42
+
43
+ self.new(
44
+ "Basic #{Base64.strict_encode64(encoded)}"
45
+ )
44
46
  end
45
47
  end
46
48
  end
@@ -20,8 +20,6 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require_relative 'split'
24
-
25
23
  module Protocol
26
24
  module HTTP
27
25
  module Header
@@ -28,6 +28,7 @@ require_relative 'header/cache_control'
28
28
  require_relative 'header/etag'
29
29
  require_relative 'header/etags'
30
30
  require_relative 'header/vary'
31
+ require_relative 'header/authorization'
31
32
 
32
33
  module Protocol
33
34
  module HTTP
@@ -170,6 +171,7 @@ module Protocol
170
171
  end
171
172
 
172
173
  # Add the specified header key value pair.
174
+ #
173
175
  # @param key [String] the header key.
174
176
  # @param value [String] the header value to assign.
175
177
  def add(key, value)
@@ -216,8 +218,6 @@ module Protocol
216
218
  'user-agent' => false,
217
219
  'referer' => false,
218
220
  'host' => false,
219
- 'authorization' => false,
220
- 'proxy-authorization' => false,
221
221
  'if-modified-since' => false,
222
222
  'if-unmodified-since' => false,
223
223
  'from' => false,
@@ -233,6 +233,10 @@ module Protocol
233
233
  'via' => Split,
234
234
  'x-forwarded-for' => Split,
235
235
 
236
+ # Authorization headers:
237
+ 'authorization' => Header::Authorization,
238
+ 'proxy-authorization' => Header::Authorization,
239
+
236
240
  # Cache validations:
237
241
  'etag' => Header::ETag,
238
242
  'if-match' => Header::ETags,
@@ -53,7 +53,7 @@ module Protocol
53
53
  self.each do |name, value|
54
54
  define_method(name.downcase) do |location, headers = nil, body = nil|
55
55
  self.call(
56
- Request[value, location.to_str, Headers[headers], body]
56
+ Request[value, location.to_s, Headers[headers], body]
57
57
  )
58
58
  end
59
59
  end
@@ -110,12 +110,10 @@ module Protocol
110
110
  return buffer
111
111
  end
112
112
 
113
- def to_str
113
+ def to_s
114
114
  append(String.new)
115
115
  end
116
116
 
117
- alias to_s to_str
118
-
119
117
  # Merges two references as specified by RFC2396, similar to `URI.join`.
120
118
  def + other
121
119
  other = self.class[other]
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.19.0"
25
+ VERSION = "0.20.0"
26
26
  end
27
27
  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.19.0
4
+ version: 0.20.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: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: covered