Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server sometimes responds with HTTP 415 for GET requests which include Content-Type header #1845

Open
mcmasn-amzn opened this issue Oct 12, 2022 · 6 comments
Labels
server Rust server SDK

Comments

@mcmasn-amzn
Copy link
Contributor

After upgrading from 0.48 to 0.49, I started getting HTTP 415 for GET calls that include the Content-Type header. My interpretation of the RFCs on this header https://httpwg.org/specs/rfc9110.html#representation.metadata is that this behavior falls into an unspecified area.

It makes sense that -- strictly speaking -- this header should not be attached to requests without a message body.

But on the other hand, a common approach is to make servers lenient and ignore headers that don't matter. So, would it be better if the SmithyRs server simply ignored the "Content-Type" header for GET requests instead?

@82marbag
Copy link
Contributor

Does this happen only when your model input is empty? It's forbidden here. This could be a question for the smithy team

@mcmasn-amzn
Copy link
Contributor Author

Yes. That's an odd quirk. I noticed it happening on a "ping" API that I implemented with an empty operation

@http(uri: "/health-check", method: "GET")
operation GetHealthCheck {}
curl -i http://localhost:3000/health-check -H 'Content-Type: application/json'
HTTP/1.1 415 Unsupported Media Type
content-type: application/json
x-amzn-errortype: UnsupportedMediaTypeException
content-length: 2
date: Fri, 14 Oct 2022 05:57:57 GMT

{}

But the issue goes away if I add a dummy input structure.

@http(uri: "/health-check", method: "GET")
operation HealthCheckOperation {
    input:={
        @httpQuery("param1")
        param1: String
    }
}
curl -i http://localhost:3000/health-check -H 'Content-Type: application/json'
HTTP/1.1 200 OK
content-type: application/json
content-length: 0
date: Fri, 14 Oct 2022 06:07:50 GMT

@82marbag
Copy link
Contributor

We're complying with the Smithy spec here, it's not a smithy-rs specific behavior. You could ask to Smithy: https://github.com/awslabs/smithy

@82marbag
Copy link
Contributor

Note that if your operation has an empty input struct, this behavior does not apply. It does apply only when there is no input in the model

@mcmasn-amzn
Copy link
Contributor Author

Yes, it would be good to clarify with Smithy because the spec you linked to here only shows examples of POST requests.

In my case, I'm dealing with GET requests. It seems like inconsistent behavior from a user perspective. The exact same GET http://localhost:3000/health-check request might pass or fail, but it depends on whether there is something defined on the input model.

@mcmasn-amzn
Copy link
Contributor Author

smithy-lang/smithy#1450

@mcmasn-amzn mcmasn-amzn changed the title Server responds with HTTP 415 for GET requests which include Content-Type header Server sometimes responds with HTTP 415 for GET requests which include Content-Type header Oct 14, 2022
@jdisanti jdisanti added the server Rust server SDK label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

No branches or pull requests

3 participants