linkerd / linkerd2

Ultralight, security-first service mesh for Kubernetes. Main repo for Linkerd 2.x.
https://linkerd.io
Apache License 2.0
10.65k stars 1.28k forks source link

Linkerd changes the HTTP response codes #7498

Closed majidghs closed 2 years ago

majidghs commented 2 years ago

What is the issue?

The issue is that linkerd change the HTTP response status phrase. For example, my web application response code is 400 Only Managers Can Do This, but linkerd response to this request is 400 Bad Request. And in the case of custom HTTP codes, they are all shown as none.

How can it be reproduced?

Create a web application that returns a custom http response, inject linkerd and then call the API.

Logs, error output, etc

In my application, I have this API:

curl 'https://<URL>/apiv1/tokens' -X 'POST' --data-raw '{"email":"xxxxx@gmail.com","password":"xxxx"}'

The response is:

{"stackTrace":"Traceback:  File /path/to/stacktrace/file exceptions.HTTPIncorrectEmailOrPassword: 603 Incorrect Email Or Password"}

But the returned response from linkerd is as follow:

HTTP/1.1 603 <none>
Server: nginx/1.10.3 (Ubuntu)
Date: Sun, 19 Dec 2021 13:21:28 GMT
Transfer-Encoding: chunked
Connection: keep-alive

output of linkerd check -o short

Linkerd core checks
===================

Status check results are √

Linkerd extensions checks
=========================

Status check results are √

Environment

Possible solution

No response

Additional context

No response

Would you like to work on fixing this bug?

No response

olix0r commented 2 years ago

Our underlying libraries (hyperium/http, hyperium/h2, etc) don't give us much control over this. And, in fact, in the HTTP/2 ecosystem, I don't think that there's any sort of support for custom messages for HTTP status codes.

I think we're unlikely to support this. It's probably more robust to convey this type of information in response payloads rather than status message.

majidghs commented 2 years ago

@olix0r Thanks for your reply. What about the 400 status code? why linkerd changes the description to Bad Request?

olix0r commented 2 years ago

Linkerd uses Rust's http crate. When it parses responses into a StatusCode it only preserves the numeric status code value and when it serializes the response it uses the canonical status code message (e.g., "Bad Request").

I'm going to close this issue, since there's nothing we can do about this in the Linkerd project. As I mentioned, it's probably best to encode your application-specific information in response headers or bodies.