@voxgig/sdkgen 4.48.1 → 4.49.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.
Files changed (119) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/secrets.aontu +3 -0
  4. package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
  5. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
  6. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
  7. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
  8. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
  9. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
  10. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
  11. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
  12. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
  13. package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
  14. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
  15. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
  16. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
  17. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
  18. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
  19. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
  20. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
  21. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
  22. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
  23. package/project/.sdk/tm/c/feature/cache.c +16 -1
  24. package/project/.sdk/tm/c/feature/secrets.c +149 -18
  25. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
  26. package/project/.sdk/tm/c/tests/feature_test.c +31 -0
  27. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
  28. package/project/.sdk/tm/clojure/src/sdk/core.clj +8 -1
  29. package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
  30. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
  31. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
  32. package/project/.sdk/tm/cpp/core/types.hpp +1 -11
  33. package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
  34. package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
  35. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
  36. package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
  37. package/project/.sdk/tm/csharp/core/Control.cs +0 -5
  38. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
  39. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
  40. package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
  41. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
  42. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
  43. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
  44. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
  45. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
  46. package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
  47. package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
  48. package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
  49. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
  50. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  51. package/project/.sdk/tm/go/utility/media.go +2 -2
  52. package/project/.sdk/tm/java/core/Control.java +0 -5
  53. package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
  54. package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
  55. package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
  56. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
  57. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
  58. package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
  59. package/project/.sdk/tm/java/utility/Media.java +2 -2
  60. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
  61. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
  62. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
  63. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  64. package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
  65. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
  66. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
  67. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
  68. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
  69. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
  70. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
  71. package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
  72. package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
  73. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
  74. package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
  75. package/project/.sdk/tm/lua/utility/clean.lua +1 -0
  76. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
  77. package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
  78. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
  79. package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
  80. package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
  81. package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
  82. package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
  83. package/project/.sdk/tm/perl/t/feature.t +24 -0
  84. package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
  85. package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
  86. package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
  87. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
  88. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
  89. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
  90. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
  91. package/project/.sdk/tm/py/test/test_feature.py +18 -0
  92. package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
  93. package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
  94. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
  95. package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
  96. package/project/.sdk/tm/rust/feature/cache.rs +15 -1
  97. package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
  98. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
  99. package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
  100. package/project/.sdk/tm/scala/core/Control.scala +0 -5
  101. package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
  102. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
  103. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
  104. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
  105. package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
  106. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
  107. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
  108. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
  109. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
  110. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
  111. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
  112. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
  113. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
  114. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  115. package/project/.sdk/tm/zig/feature/cache.zig +15 -1
  116. package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
  117. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
  118. package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
  119. package/project/sdkgen-package.json +1 -1
@@ -5,6 +5,7 @@ import java.util.function.Supplier
5
5
  import KOTLINPACKAGE.core.Context
6
6
  import KOTLINPACKAGE.core.FetcherFn
7
7
  import KOTLINPACKAGE.core.SdkClient
8
+ import KOTLINPACKAGE.utility.Media
8
9
 
9
10
  // Response caching for safe (read) requests. Wraps the active transport and
10
11
  // serves a fresh cached snapshot instead of hitting the network when the same
@@ -91,6 +92,12 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
91
92
  throw err
92
93
  }
93
94
 
95
+ // A body that declares another type than JSON passes by, unread.
96
+ if (storable(res) && !json(res)) {
97
+ this.bypass++
98
+ return res
99
+ }
100
+
94
101
  if (storable(res)) {
95
102
  val snapshot = snapshot(res)
96
103
  val ttl = FeatureOptions.foptInt(this.options, "ttl", 5000)
@@ -114,6 +121,11 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
114
121
  return status in 200..299 && (res as Map<*, *>)["unreadable"] != true
115
122
  }
116
123
 
124
+ private fun json(res: Any?): Boolean {
125
+ val type = FeatureOptions.fresHeader(res, "content-type")
126
+ return "" == type || Media.isJsonMedia(type)
127
+ }
128
+
117
129
  private fun snapshot(res: Any?): CacheSnapshot {
118
130
  val rm = if (res is MutableMap<*, *>) res as MutableMap<String, Any?> else null
119
131
 
@@ -1,5 +1,7 @@
1
1
  package KOTLINPACKAGE.feature
2
2
 
3
+ import java.net.URI
4
+ import java.util.Base64
3
5
  import java.util.concurrent.locks.ReentrantLock
4
6
  import java.util.function.BiFunction
5
7
  import java.util.function.Supplier
@@ -20,6 +22,7 @@ import KOTLINPACKAGE.feature.secrets.sekreto.envkey
20
22
  import KOTLINPACKAGE.feature.secrets.sekreto.specof
21
23
  import KOTLINPACKAGE.feature.secrets.sekreto.Json as SekJson
22
24
  import KOTLINPACKAGE.utility.defaultHttpFetch
25
+ import KOTLINPACKAGE.utility.resolveLocation
23
26
  import KOTLINPACKAGE.utility.struct.Struct
24
27
 
25
28
  // Secret access via a vendored @voxgig/sekreto provider chain, and the
@@ -74,6 +77,8 @@ import KOTLINPACKAGE.utility.struct.Struct
74
77
  // buys another and retries the same request once. Concurrent purchases
75
78
  // share the one in-flight exchange; test mode buys nothing and answers with
76
79
  // a deterministic fake token.
80
+ private const val REDIRECT_MAX = 5
81
+
77
82
  @Suppress("UNCHECKED_CAST")
78
83
  class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
79
84
 
@@ -91,6 +96,11 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
91
96
  // SdkClient holds). READ ONLY: this feature never writes to it.
92
97
  private var liveopts: MutableMap<String, Any?> = linkedMapOf()
93
98
 
99
+ // What prepareAuth was generated from: the config declares auth only
100
+ // where it places a credential, and Basic only where it composes one.
101
+ private var declared: Boolean = false
102
+ private var basic: Boolean = false
103
+
94
104
  private var secretname: String = "apikey"
95
105
  private var cache: Boolean = true
96
106
  private var sek: Sekreto? = null
@@ -126,6 +136,7 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
126
136
  val response: String,
127
137
  val statuses: List<Int>,
128
138
  val retries: Int,
139
+ val redirect: String,
129
140
  )
130
141
 
131
142
  // One shared in-flight resolution: late arrivals wait on `done` and read
@@ -163,6 +174,10 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
163
174
  this.liveopts = ctx.options ?: linkedMapOf()
164
175
  this.active = FeatureOptions.foptBool(options, "active", false)
165
176
 
177
+ val authdecl = (ctx.config?.get("options") as? Map<*, *>)?.get("auth") as? Map<*, *>
178
+ this.declared = null != authdecl
179
+ this.basic = true == authdecl?.get("basic")
180
+
166
181
  if (!this.active) {
167
182
  return
168
183
  }
@@ -188,6 +203,8 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
188
203
  response = FeatureOptions.foptStr(xopts, "response", "access_token"),
189
204
  statuses = statuses,
190
205
  retries = FeatureOptions.foptInt(xopts, "retries", 1),
206
+ redirect = if ("same-origin" == FeatureOptions.foptStr(xopts, "redirect", "refuse"))
207
+ "same-origin" else "refuse",
191
208
  )
192
209
  }
193
210
 
@@ -353,11 +370,18 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
353
370
  }
354
371
  }
355
372
 
373
+ // prepareAuth's decision: auth the config declares, not suppressed by
374
+ // `auth: null`.
375
+ private fun authon(): Boolean = this.declared && null != this.liveopts["auth"]
376
+
356
377
  // Resolve once, reporting whether a credential came out of it. That
357
378
  // boolean is the whole of what resolve() needs to tell a cacheable HIT
358
379
  // from a miss it must not keep.
359
380
  private fun resolveonce(): Boolean {
360
381
  val s = this.sek ?: return false
382
+ if (!authon()) {
383
+ return false
384
+ }
361
385
 
362
386
  // A provider ERROR throws out of here and fails the op (via the
363
387
  // transport gate); only a MISS (null) falls through.
@@ -400,17 +424,6 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
400
424
  return true
401
425
  }
402
426
 
403
- // `auth: null` is the documented way to send NO credential, and a
404
- // purchase is a credential-bearing call: the refresh token goes to the
405
- // token endpoint in the request body. withrefresh honours suppression
406
- // for the RETRY, but it runs after this - by then the refresh token has
407
- // already left the process, and no later check can call it back. The
408
- // suppression has to be honoured here, before the first purchase, or it
409
- // only ever half-held.
410
- if (null == this.liveopts["auth"]) {
411
- return false
412
- }
413
-
414
427
  buy()
415
428
 
416
429
  return true
@@ -465,12 +478,9 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
465
478
  fetchdef: MutableMap<String, Any?>,
466
479
  inner: FetcherFn,
467
480
  ): Any? {
468
- // `auth: null` is the documented way to send NO credential, and
469
- // prepareAuth honours it by removing the header. A refusal of a
470
- // deliberately unauthenticated request is not an expired token and
471
- // cannot be fixed by buying one - retrying would transmit exactly the
472
- // credential the caller suppressed.
473
- if (null == this.liveopts["auth"]) {
481
+ // A refusal of an unauthenticated request is not an expired token, and
482
+ // retrying would transmit the credential that auth off withholds.
483
+ if (!authon()) {
474
484
  return inner(ctx, url, fetchdef)
475
485
  }
476
486
 
@@ -538,7 +548,7 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
538
548
  // construction (this feature never writes it), so the raw read is safe
539
549
  // on any thread.
540
550
  val auth = this.liveopts["auth"]
541
- if (auth !is Map<*, *>) {
551
+ if (!authon() || auth !is Map<*, *>) {
542
552
  headers.remove("authorization")
543
553
  return
544
554
  }
@@ -548,9 +558,19 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
548
558
  val name =
549
559
  if (rawname is String && "" != rawname) rawname.lowercase() else "authorization"
550
560
 
561
+ val value = if (this.basic && true == auth["basic"]) pair(token) else token
562
+
551
563
  val prefix = auth["prefix"]
552
564
  headers[name] =
553
- if (prefix is String && "" != prefix) "$prefix $token" else token
565
+ if (prefix is String && "" != prefix) "$prefix $value" else value
566
+ }
567
+
568
+ // Under Basic the token is the key half, as apikey is: prepareAuth's pair.
569
+ private fun pair(token: String): String {
570
+ val secret = this.liveopts["secret"] as? String ?: ""
571
+ val pair = Base64.getEncoder().encodeToString("$token:$secret".toByteArray(Charsets.UTF_8))
572
+ register(pair)
573
+ return pair
554
574
  }
555
575
 
556
576
  // buy an access token with the refresh token. Concurrent callers share the
@@ -629,6 +649,33 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
629
649
  return token
630
650
  }
631
651
 
652
+ // Where a 307 or 308 points, when that is on the exchange's own origin. Any
653
+ // other redirect would drop the body or leave the origin.
654
+ private fun moved(url: String, at: String, res: Any?): String? {
655
+ val status = FeatureOptions.fresStatus(res)
656
+ if (307 != status && 308 != status) {
657
+ return null
658
+ }
659
+ val location = FeatureOptions.fresHeader(res, "location")
660
+ if ("" == location) {
661
+ return null
662
+ }
663
+ return try {
664
+ val next = resolveLocation(URI.create(at), location)
665
+ val origin = originOf(next)
666
+ if (null != origin && origin == originOf(URI.create(url))) next.toString() else null
667
+ } catch (e: RuntimeException) {
668
+ null
669
+ }
670
+ }
671
+
672
+ private fun originOf(uri: URI): String? {
673
+ val scheme = uri.scheme?.lowercase() ?: return null
674
+ val host = uri.host?.lowercase() ?: return null
675
+ val port = if (uri.port < 0) (if ("https" == scheme) 443 else 80) else uri.port
676
+ return scheme + "://" + host + ":" + port
677
+ }
678
+
632
679
  private fun buyonce(): String {
633
680
  val x = this.exchange!!
634
681
 
@@ -655,7 +702,7 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
655
702
  "method" to x.method,
656
703
  "headers" to linkedMapOf<String, Any?>("content-type" to "application/json"),
657
704
  "body" to body,
658
- // Never followed: a redirect would carry the refresh token on.
705
+ // Never followed by the client: a redirect would carry the refresh token on.
659
706
  "redirect" to "manual",
660
707
  )
661
708
 
@@ -671,10 +718,23 @@ class SecretsFeature : BaseFeature("secrets", "0.1.0", true) {
671
718
  sysFetch = null
672
719
  }
673
720
 
674
- val res: Any? = if (sysFetch is BiFunction<*, *, *>) {
675
- (sysFetch as BiFunction<String, MutableMap<String, Any?>, Any?>).apply(url, fetchdef)
676
- } else {
677
- defaultHttpFetch(url, fetchdef)
721
+ val ask = { at: String ->
722
+ if (sysFetch is BiFunction<*, *, *>) {
723
+ (sysFetch as BiFunction<String, MutableMap<String, Any?>, Any?>).apply(at, fetchdef)
724
+ } else {
725
+ defaultHttpFetch(at, fetchdef)
726
+ }
727
+ }
728
+
729
+ var res: Any? = ask(url)
730
+
731
+ // By option alone, and only while the exchange stays on its own origin.
732
+ var at = url
733
+ var hops = 0
734
+ while ("same-origin" == x.redirect && hops < REDIRECT_MAX) {
735
+ at = moved(url, at, res) ?: break
736
+ res = ask(at)
737
+ hops++
678
738
  }
679
739
 
680
740
  val status = FeatureOptions.fresStatus(res)
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Assertions.assertFalse
15
15
  import org.junit.jupiter.api.Assertions.assertNotEquals
16
16
  import org.junit.jupiter.api.Assertions.assertNotNull
17
17
  import org.junit.jupiter.api.Assertions.assertNull
18
+ import org.junit.jupiter.api.Assertions.assertSame
18
19
  import org.junit.jupiter.api.Assertions.assertTrue
19
20
  import org.junit.jupiter.api.Assumptions
20
21
  import org.junit.jupiter.api.Test
@@ -406,6 +407,29 @@ class FeatureTest {
406
407
  assertEquals(2, f.bypass, "expected 2 bypasses")
407
408
  }
408
409
 
410
+ @Test
411
+ fun cache_aBodyThatDeclaresAnotherTypeThanJsonPassesByUnread() {
412
+ assumeFeatures("cache")
413
+ val sent = mutableListOf<MutableMap<String, Any?>>()
414
+ val rec = FhRecorder()
415
+ rec.reply = { _, _ ->
416
+ val res = fhResponse(200, null, mapOf("content-type" to "audio/wav"))
417
+ res["body"] = "RIFF".toByteArray()
418
+ sent.add(res)
419
+ res
420
+ }
421
+ val f = CacheFeature()
422
+ val h = fhMake(rec::fetch, fhF(f, fhMap("ttl", 10000)))
423
+ val a = h.op(fhOp("load").path("/w/1/audio"))
424
+ val b = h.op(fhOp("load").path("/w/1/audio"))
425
+ assertEquals(2, rec.calls.size, "the body was stored")
426
+ assertSame(sent[0]["body"], a.ctx?.response?.body, "the cache handed on a copy it had read")
427
+ assertSame(sent[0]["headers"], a.ctx?.response?.headers)
428
+ assertSame(sent[1]["body"], b.ctx?.response?.body)
429
+ assertSame(sent[1]["headers"], b.ctx?.response?.headers)
430
+ assertEquals(2, f.bypass, "expected 2 bypasses")
431
+ }
432
+
409
433
  @Test
410
434
  fun cache_refetchesAfterTtl() {
411
435
  assumeFeatures("cache")
@@ -451,6 +451,41 @@ class PrimaryUtilityTest {
451
451
  }
452
452
  }
453
453
 
454
+ // A Location of a query alone keeps the path that answered.
455
+ @Test
456
+ fun fetcherRedirectToAQueryKeepsThePath() {
457
+ val seen = java.util.Collections.synchronizedList(mutableListOf<String>())
458
+ val server = com.sun.net.httpserver.HttpServer.create(java.net.InetSocketAddress("127.0.0.1", 0), 0)
459
+ server.createContext("/") { exchange ->
460
+ val query = exchange.requestURI.rawQuery
461
+ seen.add(exchange.requestURI.rawPath + (if (query == null) "" else "?" + query))
462
+ if (query == null) {
463
+ exchange.responseHeaders.set("Location", "?step=2")
464
+ exchange.sendResponseHeaders(302, -1L)
465
+ } else {
466
+ val body = "{\"id\":\"q1\"}".toByteArray()
467
+ exchange.responseHeaders.set("Content-Type", "application/json")
468
+ exchange.sendResponseHeaders(200, body.size.toLong())
469
+ exchange.responseBody.write(body)
470
+ }
471
+ exchange.close()
472
+ }
473
+ server.start()
474
+ val base = "http://127.0.0.1:" + server.address.port
475
+ try {
476
+ val liveClient = ProjectNameSDK(fhMap("base", base))
477
+ val liveUtility = liveClient.getUtility()
478
+ val ctx = liveUtility.makeContext(
479
+ fhMap("opname", "load", "client", liveClient, "utility", liveUtility), null)
480
+ val res = liveUtility.fetcher(ctx, "$base/redirect/q1",
481
+ fhMap("method", "GET", "headers", linkedMapOf<String, Any?>())) as Map<*, *>
482
+ assertEquals(200, res["status"])
483
+ assertEquals(listOf("/redirect/q1", "/redirect/q1?step=2"), seen.toList())
484
+ } finally {
485
+ server.stop(0)
486
+ }
487
+ }
488
+
454
489
  // The API's origin, which redirects, and another origin, which records
455
490
  // what reaches it: another port on the same host is another origin.
456
491
  class RedirectOrigins : AutoCloseable {