protocol-http 0.24.7 → 0.25.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: 8883fd0b19af80ae8276396f1f122822a8091ab5472a4b474cab27d99000d3ed
4
- data.tar.gz: a3460cb8df3b9a75e43e6dffb81bd4784b6b3b50d5d88b19c9495c0368f8f9ed
3
+ metadata.gz: 6354e91389524cbc79fb186bb3d5f3a3bc87ff3a904fc1540635ec8bf89db448
4
+ data.tar.gz: f83f86976e9dfb6ed8f8adab3f587acf0359377f6254627099ecbc504a3145db
5
5
  SHA512:
6
- metadata.gz: 05f87c3e94f646878d73ab53121c716df5476fa70523d45605e2ad2d83cc52bd36ecca9a59b34d4f3d7b28d44a6a5d6c60dd20b47f542caa97f9f29374cd4591
7
- data.tar.gz: d975d277a0d58ab7b1d94b36c60aafefac781e5da84623e7abdb928c81734166f2469a08f6bde0747596452652e58d7044d93d6d1902a37d915f60e1f68238a9
6
+ metadata.gz: 72fdbf93d17bf20fae9591620b0c64a99f02026e677311486a0e7ee94d6b2fdce62063b3bbd31a0e6941ba3f324acc99a0957edba610d659fce1e1e9247ad34e
7
+ data.tar.gz: 3280e4a0d39fa6a4ab58ab08c1dfeb2cad6e5ddbddc73906f00552a6c32dab3669e67c86d22f92dafa236745f11d8d75961c398f932cf4790cbe67deeb6807d0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
@@ -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.25.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -8,6 +8,7 @@ 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.
11
12
 
12
13
  Permission is hereby granted, free of charge, to any person obtaining a copy
13
14
  of this software and associated documentation files (the "Software"), to deal
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
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.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -44,7 +44,7 @@ cert_chain:
44
44
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
45
45
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
46
  -----END CERTIFICATE-----
47
- date: 2023-08-03 00:00:00.000000000 Z
47
+ date: 2023-09-12 00:00:00.000000000 Z
48
48
  dependencies: []
49
49
  description:
50
50
  email:
metadata.gz.sig CHANGED
Binary file