fast-proxy-status 0.1.1 → 0.1.2

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: a07878cd3ad2645e1d6abeec97590e1cdb666cb26a10623f7773a780d845eadd
4
- data.tar.gz: e37471d7c08202ff325e8d6669a6e34dd5f028a1d85cf5bc0da5c6f6f7b94949
3
+ metadata.gz: 3325bf36d407d1cad4f565ffda62ef2358eafecb5c0ff829a84e502953b289f8
4
+ data.tar.gz: 01a0be193f81844cf14a1786377d01de1d4bb0e035e0ee46afcef70de0816f6d
5
5
  SHA512:
6
- metadata.gz: 06a7b8fb40b7a5fa7b96d8a41dee1c893894f56fc50a9d449bf1017c7084f0db1bec686034fa53ce5d73047304168952456246c21b933c39b39a6333da8fd12d
7
- data.tar.gz: 413de2b4b7964a3f0f482d3542d00a3a5acbdc993c49208941bfb5f768c04822caaf36a6b6ae655e0a7e789dce07e536741cca50c7edc3a0d8d2d23313c2bb17
6
+ metadata.gz: 562a526446eedc8952e56fe2659b5a098fe63e09c8a644ac4d4a47810109534af9c0771a8e138aeebace7bcbfa65efb397fde2e77bfe59ac67e04a4c30cbc83e
7
+ data.tar.gz: df456c907457e6d9edaecc1d809de216722bbf89f3cc6a1ade90a1b2707a3b40c3c579f8a656a9672b261727d547594d6f641e9d68513ebf1d45d09ea7aea729
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 (2026-11-27)
4
+
5
+ - Fixed: the parse, construction and emit boundaries never send a
6
+ message into the value they are checking — the parameter-value
7
+ predicates behind every field's `param_ok?` (Boolean, Token,
8
+ Integer, plain String, identifier, Byte Sequence), the
9
+ construction boundaries (a field's members Array, each member, its
10
+ identifier and its params Hash and keys) and the held-value entry
11
+ read the value with the never-dispatch forms (`case value when
12
+ Klass`, `Module#===`), so a classless value (a `BasicObject`
13
+ descendant) at a boundary raises the documented error class
14
+ instead of escaping the error contract as a raw `NoMethodError`.
15
+ The message names the value's class — or the placeholder "a
16
+ classless object" — never a method the value itself answers.
17
+ - Fixed: requirement messages lead with the requirement — "a
18
+ Proxy-Status member must be a String or Token, received …",
19
+ "fwd: the value must be a Token of the 2.2 set …", "<key>: the
20
+ value must be <rule>, received …" — so no message reads as if
21
+ the received value were the required one.
22
+
3
23
  ## 0.1.1 (2026-11-27)
4
24
 
5
25
  - Fixed: the strict `parse!` positions member and parameter errors
@@ -181,8 +181,8 @@ module Fast
181
181
  def param_ok?(key, value)
182
182
  case key
183
183
  when "hit", "stored", "collapsed" then boolean_value?(value)
184
- when "fwd" then value.is_a?(Token)
185
- when "fwd-status", "ttl" then value.is_a?(Integer)
184
+ when "fwd" then token_value?(value)
185
+ when "fwd-status", "ttl" then integer_value?(value)
186
186
  when "key" then plain_string?(value)
187
187
  when "detail" then identifier_value?(value)
188
188
  else true
@@ -201,7 +201,32 @@ module Fast
201
201
  # absence (§3's "collapsed=?0" example), so the check reads the
202
202
  # class, not the truth.
203
203
  def boolean_value?(value)
204
- value.is_a?(TrueClass) || value.is_a?(FalseClass)
204
+ case value
205
+ when true, false
206
+ true
207
+ else
208
+ false
209
+ end
210
+ end
211
+
212
+ # A Token, as a never-dispatch predicate.
213
+ def token_value?(value)
214
+ case value
215
+ when Token
216
+ true
217
+ else
218
+ false
219
+ end
220
+ end
221
+
222
+ # An Integer, as a never-dispatch predicate.
223
+ def integer_value?(value)
224
+ case value
225
+ when Integer
226
+ true
227
+ else
228
+ false
229
+ end
205
230
  end
206
231
 
207
232
  private
@@ -216,7 +241,14 @@ module Fast
216
241
  # a Token (a Token is a different wire type) and not a Byte
217
242
  # Sequence.
218
243
  def plain_string?(value)
219
- !value.is_a?(Token) && identifier_value?(value)
244
+ case value
245
+ when Token
246
+ false
247
+ when String
248
+ value.encoding != BINARY
249
+ else
250
+ false
251
+ end
220
252
  end
221
253
  end
222
254
 
@@ -336,10 +368,10 @@ module Fast
336
368
  # must not break an old gem version.
337
369
  def check_fwd!
338
370
  value = @params["fwd"]
339
- return unless value.is_a?(Token)
371
+ return unless self.class.token_value?(value)
340
372
  return if FWD.include?(value)
341
373
 
342
- raise SerializeError.new("fwd: the value is a Token of the 2.2 set (#{FWD.join(', ')})", 0)
374
+ raise SerializeError.new("fwd: the value must be a Token of the 2.2 set (#{FWD.join(', ')})", 0)
343
375
  end
344
376
  end
345
377
 
@@ -42,10 +42,10 @@ module Fast
42
42
  # §2.1).
43
43
  def param_ok?(key, value)
44
44
  case key
45
- when "error" then value.is_a?(Token)
45
+ when "error" then token_value?(value)
46
46
  when "next-hop" then identifier_value?(value)
47
47
  when "next-protocol" then byte_value?(value)
48
- when "received-status" then value.is_a?(Integer)
48
+ when "received-status" then integer_value?(value)
49
49
  when "details" then plain_string?(value)
50
50
  else true
51
51
  end
@@ -69,7 +69,34 @@ module Fast
69
69
  # a Token, or a String tagged ASCII-8BIT (the Byte Sequence
70
70
  # tag).
71
71
  def byte_value?(value)
72
- value.is_a?(Token) || (value.is_a?(String) && value.encoding == BINARY)
72
+ case value
73
+ when Token
74
+ true
75
+ when String
76
+ value.encoding == BINARY
77
+ else
78
+ false
79
+ end
80
+ end
81
+
82
+ # §2.1.1's shape, as a never-dispatch predicate: a Token.
83
+ def token_value?(value)
84
+ case value
85
+ when Token
86
+ true
87
+ else
88
+ false
89
+ end
90
+ end
91
+
92
+ # §2.1.4's shape, as a never-dispatch predicate: an Integer.
93
+ def integer_value?(value)
94
+ case value
95
+ when Integer
96
+ true
97
+ else
98
+ false
99
+ end
73
100
  end
74
101
 
75
102
  private
@@ -84,7 +111,14 @@ module Fast
84
111
  # String, not a Token (a Token is a different wire type) and not
85
112
  # a Byte Sequence.
86
113
  def plain_string?(value)
87
- !value.is_a?(Token) && identifier_value?(value)
114
+ case value
115
+ when Token
116
+ false
117
+ when String
118
+ value.encoding != BINARY
119
+ else
120
+ false
121
+ end
88
122
  end
89
123
  end
90
124
 
@@ -180,7 +180,9 @@ module Fast
180
180
  # The member constraint, positioned at the member's identifier.
181
181
  def fail_member!(input, index, member)
182
182
  offset = member_value_offset(input, index)
183
- raise self::ParseError.new("a #{field_label} member is a String or Token (got #{shown(member)})", offset)
183
+ raise self::ParseError.new(
184
+ "a #{field_label} member must be a String or Token, received #{shown(member)}", offset
185
+ )
184
186
  end
185
187
 
186
188
  # The field's parameter constraints over one member, in the
@@ -194,7 +196,7 @@ module Fast
194
196
  next if rule.nil? || member_class.param_ok?(key, value)
195
197
 
196
198
  offset = param_value_offset(input, index, key)
197
- raise self::ParseError.new("#{key}: the value is #{rule} (got #{value})", offset)
199
+ raise self::ParseError.new("#{key}: the value must be #{rule}, received #{value}", offset)
198
200
  end
199
201
  end
200
202
 
@@ -211,10 +213,14 @@ module Fast
211
213
  # leniently (a malformed field treated as absent). TypeError for
212
214
  # anything else.
213
215
  def held_value(input)
214
- return empty_value if input.nil?
215
- return input if input.is_a?(self)
216
-
217
- parse(input)
216
+ case input
217
+ when nil
218
+ empty_value
219
+ when self
220
+ input
221
+ else
222
+ parse(input)
223
+ end
218
224
  end
219
225
 
220
226
  # The value object behind members that already passed the
@@ -320,12 +326,22 @@ module Fast
320
326
 
321
327
  private
322
328
 
329
+ # The class of a value an error message names, or a placeholder
330
+ # when the value has none (a BasicObject descendant) — the
331
+ # message never calls a method on the value it is rejecting.
332
+ def shape(value)
333
+ defined?(value.class) ? value.class : "a classless object"
334
+ end
335
+
323
336
  # The construction boundary: an Array of the field's members, each
324
337
  # already validated at its own construction.
325
338
  def check_members!(members)
326
339
  klass = self.class.send(:member_class)
327
- unless members.is_a?(Array)
328
- raise self.class::SerializeError.new("members are an Array of #{klass} (got #{members.class})", 0)
340
+ case members
341
+ when Array
342
+ nil
343
+ else
344
+ raise self.class::SerializeError.new("members must be an Array of #{klass}, received #{shape(members)}", 0)
329
345
  end
330
346
 
331
347
  members.each { |member| check_member!(member) }
@@ -335,9 +351,12 @@ module Fast
335
351
  # its own construction was its validation.
336
352
  def check_member!(member)
337
353
  klass = self.class.send(:member_class)
338
- return if member.is_a?(klass)
339
-
340
- raise self.class::SerializeError.new("a member is a #{klass} (got #{member.class})", 0)
354
+ case member
355
+ when klass
356
+ nil
357
+ else
358
+ raise self.class::SerializeError.new("a member must be a #{klass}, received #{shape(member)}", 0)
359
+ end
341
360
  end
342
361
 
343
362
  # The one place the held state is written, then frozen: the
@@ -399,7 +418,14 @@ module Fast
399
418
  # not a String, so it fails here and the construction refuses
400
419
  # it.
401
420
  def identifier_value?(value)
402
- value.is_a?(Token) || (value.is_a?(String) && value.encoding != BINARY)
421
+ case value
422
+ when Token
423
+ true
424
+ when String
425
+ value.encoding != BINARY
426
+ else
427
+ false
428
+ end
403
429
  end
404
430
 
405
431
  # A bare Structured Fields type (RFC 9651 §3.3.1) — the value
@@ -474,6 +500,13 @@ module Fast
474
500
 
475
501
  private
476
502
 
503
+ # The class of a value an error message names, or a placeholder
504
+ # when the value has none (a BasicObject descendant) — the
505
+ # message never calls a method on the value it is rejecting.
506
+ def shape(value)
507
+ defined?(value.class) ? value.class : "a classless object"
508
+ end
509
+
477
510
  # The one place the held state is written, then frozen: the
478
511
  # parse path's already-frozen value and params, as parsed.
479
512
  def hold(value, params)
@@ -486,20 +519,24 @@ module Fast
486
519
  def check_value!(value)
487
520
  return if self.class.identifier_value?(value)
488
521
 
489
- raise self.class.send(:serialize_error, "a member identifier is a String or a Token (got #{value.inspect})")
522
+ raise self.class.send(:serialize_error,
523
+ "a member identifier must be a String or a Token, received #{shape(value)}")
490
524
  end
491
525
 
492
526
  # The params boundary: a Hash of Structured Fields keys, each
493
527
  # value the type its key's section allows (any bare type for an
494
528
  # unknown key), frozen IN PLACE.
495
529
  def check_params!(params)
496
- raise self.class.send(:serialize_error, "params are a Hash (got #{params.class})") unless params.is_a?(Hash)
497
-
498
- params.each do |key, value|
499
- check_key!(key)
500
- check_param!(key, value)
530
+ case params
531
+ when Hash
532
+ params.each do |key, value|
533
+ check_key!(key)
534
+ check_param!(key, value)
535
+ end
536
+ params.freeze
537
+ else
538
+ raise self.class.send(:serialize_error, "params must be a Hash, received #{shape(params)}")
501
539
  end
502
- params.freeze
503
540
  end
504
541
 
505
542
  # The parameter key grammar, RFC 9651 §4.2.3.3 read from the
@@ -508,24 +545,27 @@ module Fast
508
545
  def check_key!(key)
509
546
  return if valid_key?(key)
510
547
 
511
- raise self.class.send(:serialize_error, "#{key.inspect} is not a Structured Fields key")
548
+ raise self.class.send(:serialize_error, "#{shape(key)} is not a Structured Fields key")
512
549
  end
513
550
 
514
551
  # The walk behind check_key! — manual and allocation-free, the
515
552
  # shape the substrate's own key parse uses.
516
553
  def valid_key?(key)
517
- return false unless key.is_a?(String)
554
+ case key
555
+ when String
556
+ size = key.bytesize
557
+ return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
518
558
 
519
- size = key.bytesize
520
- return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
559
+ index = 1
560
+ while index < size
561
+ return false unless KEY_BODY[key.getbyte(index)]
521
562
 
522
- index = 1
523
- while index < size
524
- return false unless KEY_BODY[key.getbyte(index)]
525
-
526
- index += 1
563
+ index += 1
564
+ end
565
+ true
566
+ else
567
+ false
527
568
  end
528
- true
529
569
  end
530
570
 
531
571
  # One parameter's value at the boundary: a key the field's own
@@ -536,12 +576,12 @@ module Fast
536
576
  if rule
537
577
  return if self.class.param_ok?(key, value)
538
578
 
539
- raise self.class.send(:serialize_error, "#{key}: the value is #{rule} (got #{value.inspect})")
579
+ raise self.class.send(:serialize_error, "#{key}: the value must be #{rule}, received #{shape(value)}")
540
580
  end
541
581
  return if self.class.bare_type?(value)
542
582
 
543
583
  raise self.class.send(:serialize_error,
544
- "#{key}: the value is a bare Structured Fields type (got #{value.inspect})")
584
+ "#{key}: the value must be a bare Structured Fields type, received #{shape(value)})")
545
585
  end
546
586
  end
547
587
  end
@@ -62,10 +62,14 @@ module Fast
62
62
  # field, an existing value's hops (no re-parse), a String or
63
63
  # Array of lines parsed leniently. TypeError for anything else.
64
64
  def held_hops(input)
65
- return nil if input.nil?
66
- return input.hops if input.is_a?(ProxyStatus)
67
-
68
- parse(input).hops
65
+ case input
66
+ when nil
67
+ nil
68
+ when ProxyStatus
69
+ input.hops
70
+ else
71
+ parse(input).hops
72
+ end
69
73
  end
70
74
 
71
75
  # §2 step 1's walk: for each trailer member in order, the
@@ -293,7 +293,9 @@ module Fast
293
293
  # member), so it survives the members a private walk would
294
294
  # desync on.
295
295
  def fail_member!(key, member, input)
296
- raise ParseError.new("#{key}: the value is #{rule_for(key)} (got #{shown(member)})", value_offset(input, key))
296
+ raise ParseError.new(
297
+ "#{key}: the value must be #{rule_for(key)}, received #{shown(member)}", value_offset(input, key)
298
+ )
297
299
  end
298
300
 
299
301
  # The byte the effective (last-wins) +key+ member's VALUE starts
@@ -329,9 +331,9 @@ module Fast
329
331
  # flag, the strict raise and the emit refusal cannot drift.
330
332
  def value_ok?(key, value)
331
333
  case key
332
- when "max-age" then value.is_a?(Integer)
333
- when "must-revalidate", "no-store" then value == true
334
- when "no-cache", "private" then value == true || plain_string?(value)
334
+ when "max-age" then integer_value?(value)
335
+ when "must-revalidate", "no-store" then true_value?(value)
336
+ when "no-cache", "private" then true_value?(value) || plain_string?(value)
335
337
  else inferred?(value)
336
338
  end
337
339
  end
@@ -342,15 +344,47 @@ module Fast
342
344
  # or an inner list is outside the mapping.
343
345
  def inferred?(value)
344
346
  case value
345
- when true, false, Integer, Float, Token then true
346
- else value.is_a?(String) && value.encoding != BINARY
347
+ when true, false, Integer, Float, Token
348
+ true
349
+ when String
350
+ value.encoding != BINARY
351
+ else
352
+ false
347
353
  end
348
354
  end
349
355
 
350
356
  # §2.1's quoted-string mapping: a plain String — not a Token (a
351
357
  # different wire type) and not a Byte Sequence.
352
358
  def plain_string?(value)
353
- value.is_a?(String) && !value.is_a?(Token) && value.encoding != BINARY
359
+ case value
360
+ when Token
361
+ false
362
+ when String
363
+ value.encoding != BINARY
364
+ else
365
+ false
366
+ end
367
+ end
368
+
369
+ # An Integer, as a never-dispatch predicate.
370
+ def integer_value?(value)
371
+ case value
372
+ when Integer
373
+ true
374
+ else
375
+ false
376
+ end
377
+ end
378
+
379
+ # Boolean true exactly — the never-dispatch form of the
380
+ # value == true check: these directives carry true, never false.
381
+ def true_value?(value)
382
+ case value
383
+ when true
384
+ true
385
+ else
386
+ false
387
+ end
354
388
  end
355
389
 
356
390
  # The rule one directive's value must satisfy, worded for the
@@ -488,7 +522,12 @@ module Fast
488
522
  # value, then the one place the held state is written, frozen: the
489
523
  # members Hash, the keys view derived from it, the clean flag.
490
524
  def check_members!(members)
491
- raise SerializeError.new("members are a Hash (got #{members.class})", 0) unless members.is_a?(Hash)
525
+ case members
526
+ when Hash
527
+ nil
528
+ else
529
+ raise SerializeError.new("members must be a Hash, received #{shape(members)}", 0)
530
+ end
492
531
 
493
532
  held = {}
494
533
  members.each do |key, value|
@@ -506,24 +545,34 @@ module Fast
506
545
  def check_key!(key)
507
546
  return if valid_key?(key)
508
547
 
509
- raise SerializeError.new("#{key.inspect} is not a Structured Fields key", 0)
548
+ raise SerializeError.new("#{shape(key)} is not a Structured Fields key", 0)
510
549
  end
511
550
 
512
551
  # The walk behind check_key! — manual and allocation-free, the
513
552
  # shape the substrate's own key parse uses.
514
553
  def valid_key?(key)
515
- return false unless key.is_a?(String)
554
+ case key
555
+ when String
556
+ size = key.bytesize
557
+ return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
516
558
 
517
- size = key.bytesize
518
- return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
559
+ index = 1
560
+ while index < size
561
+ return false unless KEY_BODY[key.getbyte(index)]
519
562
 
520
- index = 1
521
- while index < size
522
- return false unless KEY_BODY[key.getbyte(index)]
523
-
524
- index += 1
563
+ index += 1
564
+ end
565
+ true
566
+ else
567
+ false
525
568
  end
526
- true
569
+ end
570
+
571
+ # The class of a value an error message names, or a placeholder
572
+ # when the value has none (a BasicObject descendant) — the
573
+ # message never calls a method on the value it is rejecting.
574
+ def shape(value)
575
+ defined?(value.class) ? value.class : "a classless object"
527
576
  end
528
577
 
529
578
  # One directive's value at the boundary: the constraint the parse
@@ -533,7 +582,7 @@ module Fast
533
582
  def check_value!(key, value)
534
583
  return if self.class.send(:value_ok?, key, value)
535
584
 
536
- raise SerializeError.new("#{key}: the value is #{rule_for(key)} (got #{value.inspect})", 0)
585
+ raise SerializeError.new("#{key}: the value must be #{rule_for(key)}, received #{shape(value)}", 0)
537
586
  end
538
587
 
539
588
  # The rule one directive's value must satisfy, worded for the
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  class ProxyStatus
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast-proxy-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Jacobs