swift-url-routing icon indicating copy to clipboard operation
swift-url-routing copied to clipboard

Request header unexpectedly mutated

Open eappel opened this issue 3 years ago • 4 comments

In this example, I'm supplying an uppercased request header but it's getting lowercased somewhere within the parsing library. I couldn't easily figure out where this was happening to fix with a PR so opening as an issue!

enum TestRoute {
    case testing(value: String)
}

let testingRouter = Route(.case(TestRoute.testing)) {
    Path {
        "testing"
    }
    Headers {
        Field("UPPERCASED-HEADER")
    }
}

func test() async throws {
    let request = try testingRouter.request(
        for: TestRoute.testing(value: "VALUE")
    )
    print(request.allHTTPHeaderFields!)
}

printed: ["uppercased-header": "VALUE"]

expected: ["UPPERCASED-HEADER": "VALUE"]

eappel avatar May 11 '22 19:05 eappel

@eappel HTTP header names are case insensitive, so the library currently lowercases things for consistency. Have you encountered an issue in the wild where this is a problem?

stephencelis avatar May 11 '22 19:05 stephencelis

Yeah the API I'm dealing with is case-sensitive 😞

I definitely agree that it shouldn't matter though so I'll file a ticket on the backend 👍

eappel avatar May 11 '22 19:05 eappel

@eappel I think we should probably change this behavior on our end, too!

stephencelis avatar May 11 '22 20:05 stephencelis

@eappel We have an idea that should make it easy to fix this in the future, but we haven't quite finalized the tools yet. We'll leave the issue open for now, but will hopefully get to close it in the next month or two!

stephencelis avatar May 12 '22 15:05 stephencelis