protocol-http 0.24.7 → 0.26.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: 8883fd0b19af80ae8276396f1f122822a8091ab5472a4b474cab27d99000d3ed
4
- data.tar.gz: a3460cb8df3b9a75e43e6dffb81bd4784b6b3b50d5d88b19c9495c0368f8f9ed
3
+ metadata.gz: 6401497cd3f38196e5a3144d558cf78de63f078910be38a62424178d9602fe16
4
+ data.tar.gz: b8c117fc812d042322c0dec7cf40e3d6e52b0920935ab1ddde954ac7caed94f0
5
5
  SHA512:
6
- metadata.gz: 05f87c3e94f646878d73ab53121c716df5476fa70523d45605e2ad2d83cc52bd36ecca9a59b34d4f3d7b28d44a6a5d6c60dd20b47f542caa97f9f29374cd4591
7
- data.tar.gz: d975d277a0d58ab7b1d94b36c60aafefac781e5da84623e7abdb928c81734166f2469a08f6bde0747596452652e58d7044d93d6d1902a37d915f60e1f68238a9
6
+ metadata.gz: 7fe7771ac9a21b2724b6f037dcce2eeb4bcae573d61634aabfa631304a70bbc661635221cf10371c755fa06d6d4ab1dac926a3ca342422aa380b529954ad941f
7
+ data.tar.gz: 05cd0d1cf17525d9c525158e76687440f607fc34c23e25a055e4f97f1fe20b4af0c8b0e4bedd91ef8bd705c3a1711ee365bdc3cc539fa9f85638cc66040c2ea9
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2023, by Genki Takiuchi.
6
6
 
7
7
  require_relative 'buffered'
@@ -98,6 +98,10 @@ module Protocol
98
98
  return buffer
99
99
  end
100
100
 
101
+ def readpartial(length)
102
+ read_partial(length) or raise EOFError, "End of file reached!"
103
+ end
104
+
101
105
  def read_nonblock(length, buffer = nil)
102
106
  @buffer ||= read_next
103
107
  chunk = nil
@@ -2,6 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2020-2023, by Samuel Williams.
5
+ # Copyright, 2023, by Thomas Morgan.
5
6
 
6
7
  require_relative 'split'
7
8
 
@@ -14,11 +15,15 @@ module Protocol
14
15
  NO_CACHE = 'no-cache'
15
16
  NO_STORE = 'no-store'
16
17
  MAX_AGE = 'max-age'
18
+ S_MAXAGE = 's-maxage'
17
19
 
18
20
  STATIC = 'static'
19
21
  DYNAMIC = 'dynamic'
20
22
  STREAMING = 'streaming'
21
23
 
24
+ MUST_REVALIDATE = 'must-revalidate'
25
+ PROXY_REVALIDATE = 'proxy-revalidate'
26
+
22
27
  def initialize(value = nil)
23
28
  super(value&.downcase)
24
29
  end
@@ -55,11 +60,40 @@ module Protocol
55
60
  self.include?(NO_STORE)
56
61
  end
57
62
 
63
+ # Indicates that a response must not be used once it is stale.
64
+ # See https://www.rfc-editor.org/rfc/rfc9111.html#name-must-revalidate
65
+ def must_revalidate?
66
+ self.include?(MUST_REVALIDATE)
67
+ end
68
+
69
+ # Like must-revalidate, but for shared caches only.
70
+ # See https://www.rfc-editor.org/rfc/rfc9111.html#name-proxy-revalidate
71
+ def proxy_revalidate?
72
+ self.include?(PROXY_REVALIDATE)
73
+ end
74
+
75
+ # The maximum time, in seconds, a response should be considered fresh.
76
+ # See https://www.rfc-editor.org/rfc/rfc9111.html#name-max-age-2
58
77
  def max_age
59
- if value = self.find{|value| value.start_with?(MAX_AGE)}
78
+ find_integer_value(MAX_AGE)
79
+ end
80
+
81
+ # Like max-age, but for shared caches only, which should use it before
82
+ # max-age when present.
83
+ # See https://www.rfc-editor.org/rfc/rfc9111.html#name-s-maxage
84
+ def s_maxage
85
+ find_integer_value(S_MAXAGE)
86
+ end
87
+
88
+ private
89
+
90
+ def find_integer_value(value_name)
91
+ if value = self.find{|value| value.start_with?(value_name)}
60
92
  _, age = value.split('=', 2)
61
93
 
62
- return Integer(age)
94
+ if age =~ /\A[0-9]+\z/
95
+ return Integer(age)
96
+ end
63
97
  end
64
98
  end
65
99
  end
@@ -22,7 +22,7 @@ module Protocol
22
22
  end
23
23
 
24
24
  def keep_alive?
25
- self.include?(KEEP_ALIVE)
25
+ self.include?(KEEP_ALIVE) && !close?
26
26
  end
27
27
 
28
28
  def close?
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2020-2023, by Samuel Williams.
4
+ # Copyright, 2023, by Samuel Williams.
5
5
 
6
6
  require 'time'
7
7
 
@@ -2,21 +2,42 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2020-2023, by Samuel Williams.
5
+ # Copyright, 2023, by Thomas Morgan.
5
6
 
6
7
  require_relative 'split'
7
8
 
8
9
  module Protocol
9
10
  module HTTP
10
11
  module Header
11
- # This implementation is not strictly correct according to the RFC-specified format.
12
12
  class ETags < Split
13
13
  def wildcard?
14
14
  self.include?('*')
15
15
  end
16
16
 
17
+ # This implementation is not strictly correct according to the RFC-specified format.
17
18
  def match?(etag)
18
19
  wildcard? || self.include?(etag)
19
20
  end
21
+
22
+ # Useful with If-Match
23
+ def strong_match?(etag)
24
+ wildcard? || (!weak_tag?(etag) && self.include?(etag))
25
+ end
26
+
27
+ # Useful with If-None-Match
28
+ def weak_match?(etag)
29
+ wildcard? || self.include?(etag) || self.include?(opposite_tag(etag))
30
+ end
31
+
32
+ private
33
+
34
+ def opposite_tag(etag)
35
+ weak_tag?(etag) ? etag[2..-1] : "W/#{etag}"
36
+ end
37
+
38
+ def weak_tag?(tag)
39
+ tag&.start_with? 'W/'
40
+ end
20
41
  end
21
42
  end
22
43
  end
@@ -29,42 +29,63 @@ module Protocol
29
29
  false
30
30
  end
31
31
 
32
+ # Whether the status is 100 (continue).
32
33
  def continue?
33
34
  @status == 100
34
35
  end
35
36
 
37
+ # Whether the status is considered informational.
38
+ def informational?
39
+ @status and @status >= 100 && @status < 200
40
+ end
41
+
42
+ # Whether the status is considered final. Note that 101 is considered final.
43
+ def final?
44
+ # 101 is effectively a final status.
45
+ @status and @status >= 200 || @status == 101
46
+ end
47
+
48
+ # Whether the status is 200 (ok).
36
49
  def ok?
37
50
  @status == 200
38
51
  end
39
52
 
53
+ # Whether the status is considered successful.
40
54
  def success?
41
55
  @status and @status >= 200 && @status < 300
42
56
  end
43
57
 
58
+ # Whether the status is 206 (partial content).
44
59
  def partial?
45
60
  @status == 206
46
61
  end
47
62
 
63
+ # Whether the status is considered a redirection.
48
64
  def redirection?
49
65
  @status and @status >= 300 && @status < 400
50
66
  end
51
67
 
68
+ # Whether the status is 304 (not modified).
52
69
  def not_modified?
53
70
  @status == 304
54
71
  end
55
72
 
73
+ # Whether the status is 307 (temporary redirect) and should preserve the method of the request when following the redirect.
56
74
  def preserve_method?
57
75
  @status == 307 || @status == 308
58
76
  end
59
77
 
78
+ # Whether the status is considered a failure.
60
79
  def failure?
61
80
  @status and @status >= 400 && @status < 600
62
81
  end
63
82
 
83
+ # Whether the status is 400 (bad request).
64
84
  def bad_request?
65
85
  @status == 400
66
86
  end
67
87
 
88
+ # Whether the status is 500 (internal server error).
68
89
  def internal_server_error?
69
90
  @status == 500
70
91
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.24.7"
8
+ VERSION = "0.26.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2018-2023, by Samuel Williams.
3
+ Copyright, 2018-2024, by Samuel Williams.
4
4
  Copyright, 2019, by Yuta Iwama.
5
5
  Copyright, 2020, by Olle Jonsson.
6
6
  Copyright, 2020, by Bryan Powell.
@@ -8,6 +8,8 @@ Copyright, 2020-2023, by Bruno Sutic.
8
8
  Copyright, 2022, by Herrick Fang.
9
9
  Copyright, 2022, by Dan Olson.
10
10
  Copyright, 2023, by Genki Takiuchi.
11
+ Copyright, 2023, by Thomas Morgan.
12
+ Copyright, 2023, by Marcelo Junior.
11
13
 
12
14
  Permission is hereby granted, free of charge, to any person obtaining a copy
13
15
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -8,18 +8,15 @@ Provides abstractions for working with the HTTP protocol.
8
8
 
9
9
  - General abstractions for HTTP requests and responses.
10
10
  - Symmetrical interfaces for client and server.
11
- - Light-weight middlewar model for building applications.
11
+ - Light-weight middleware model for building applications.
12
12
 
13
13
  ## Usage
14
14
 
15
- Please see the [project documentation](https://github.com/socketry/protocol-http) for more details.
15
+ Please see the [project documentation](https://socketry.github.io/protocol-http/) for more details.
16
16
 
17
- - [Getting Started](https://github.com/socketry/protocol-httpguides/getting-started/index) - This guide explains how
18
- to use `protocol-http` for building abstract HTTP interfaces.
17
+ - [Getting Started](https://socketry.github.io/protocol-http/guides/getting-started/index) - This guide explains how to use `protocol-http` for building abstract HTTP interfaces.
19
18
 
20
- - [Design Overview](https://github.com/socketry/protocol-httpguides/design-overview/index) - The interfaces provided
21
- by <code class="language-ruby">Protocol::HTTP</code> underpin all downstream implementations. Therefore, we provide
22
- some justification for the design choices.
19
+ - [Design Overview](https://socketry.github.io/protocol-http/guides/design-overview/index) - This guide explains the high level design of `protocol-http` in the context of wider design patterns that can be used to implement HTTP clients and servers.
23
20
 
24
21
  ## Contributing
25
22
 
@@ -37,7 +34,7 @@ This project uses the [Developer Certificate of Origin](https://developercertifi
37
34
 
38
35
  ### Contributor Covenant
39
36
 
40
- This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
37
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
41
38
 
42
39
  ## See Also
43
40
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.7
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Bruno Sutic
9
9
  - Herrick Fang
10
+ - Thomas Morgan
10
11
  - Bryan Powell
11
12
  - Dan Olson
12
13
  - Genki Takiuchi
14
+ - Marcelo Junior
13
15
  - Olle Jonsson
14
16
  - Yuta Iwama
15
17
  autorequire:
@@ -44,8 +46,22 @@ cert_chain:
44
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
45
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
48
  -----END CERTIFICATE-----
47
- date: 2023-08-03 00:00:00.000000000 Z
48
- dependencies: []
49
+ date: 2024-01-26 00:00:00.000000000 Z
50
+ dependencies:
51
+ - !ruby/object:Gem::Dependency
52
+ name: base64
53
+ requirement: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ type: :runtime
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
49
65
  description:
50
66
  email:
51
67
  executables: []
@@ -94,7 +110,8 @@ files:
94
110
  homepage: https://github.com/socketry/protocol-http
95
111
  licenses:
96
112
  - MIT
97
- metadata: {}
113
+ metadata:
114
+ documentation_uri: https://socketry.github.io/protocol-http/
98
115
  post_install_message:
99
116
  rdoc_options: []
100
117
  require_paths:
@@ -103,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
120
  requirements:
104
121
  - - ">="
105
122
  - !ruby/object:Gem::Version
106
- version: 2.7.6
123
+ version: '3.0'
107
124
  required_rubygems_version: !ruby/object:Gem::Requirement
108
125
  requirements:
109
126
  - - ">="
110
127
  - !ruby/object:Gem::Version
111
128
  version: '0'
112
129
  requirements: []
113
- rubygems_version: 3.4.10
130
+ rubygems_version: 3.5.3
114
131
  signing_key:
115
132
  specification_version: 4
116
133
  summary: Provides abstractions to handle HTTP protocols.
metadata.gz.sig CHANGED
Binary file