Context parameters are all lowercase
I have a url that has a case sensitive path parameter and is getting mangled when retrieving parameters.
...
routerGroup.get("/recorded/:file", use: recordedStream)
...
@Sendable
private func recordedStream(from request: Request, context: C) async throws -> some ResponseGenerator {
...
let filename = try context.parameters.require("file", as: String.self) // caps mismatch
...
The value is always lowercased when retrieved this way, but should be able to contain all valid ASCII characters. I debugged it back to find context.parameters being generated by the trie, but I have not yet wrapped my head around the trie data structure and got lost in there.
Do you have the router option .caseInsensitve set?
False alarm. Nothing to see here. I will punish myself appropriately.

You know, I actually think my confusion is justified, now that I had a chance to think about it.
If I set the router to .caseInsensitive, I would only expect that endpoint matching would be case insensitive. However, I would still expect endpoint parameters to get passed through untouched.
For example, for the following router config:
router
.get("/foo/:bar", use: handleFoo)
and the handling of the following example URLs:
-
host/foo/asdf -
host/FOO/asdf -
host/FoO/ASdf
I would expect the following when case sensitive
-
let barValue = context.parameters.get("bar", as: UUID.self) // "asdf" - 404
- 404
However, when case insensitive, I would expect
-
let barValue = context.parameters.get("bar", as: UUID.self) // "asdf" -
let barValue = context.parameters.get("bar", as: UUID.self) // "asdf" -
let barValue = context.parameters.get("bar", as: UUID.self) // "ASdf"
Basically, the case sensitivity would only apply to the matching, but the original value be treated immutably.
Edit: I just checked the doc comment for .caseInsensitive and it says the following
Router path comparisons will be case insensitive
While I won't claim to have checked that originally, if I had, I'd still take that to expect the behavior I outlined above. It says nothing about converting and passing parameter values to lowercase, just that the comparisons will be handled case insensitively.
@adam-fowler I do think we should fix this. I'm just wondering if it'd be a breaking change. Depending on that I can make a PR
Whether or not anyone is depending on it, it would definitely be a change in behavior. I'd personally make the argument for breaking change, even if it's considered as "fixing a bug". What if there was an additive behavioral option, akin to the previously mentioned .caseInsensitive?
@adam-fowler I do think we should fix this. I'm just wondering if it'd be a breaking change. Depending on that I can make a PR
I think it will be ok. If someone if relying on parameters being lowercased when .caseInsensitive is set they are relying on an undocumented effect.
I personally think the change is unnecessary. If you are relying on the case of parameters you shouldn't be saying your URIs are case insensitive and use another method for passing the information like query parameters.