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

Support for custom status code and message in HTTP response #27326

Closed
balaji-itorix opened this issue Aug 26, 2021 · 3 comments
Closed

Support for custom status code and message in HTTP response #27326

balaji-itorix opened this issue Aug 26, 2021 · 3 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@balaji-itorix
Copy link

We are using spring boot backend service and require to publish custom status code and status message in response. As per current spec spring supports sending custom status code in ResponseEntity's builder ResponseEntity.status(int statusCode) but doesn't have a mechanism to send custom status message along with it.

Sending the code and status message in the response body isn't an option for our use case.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 26, 2021
@snicoll snicoll changed the title Enhancement Request : Spring doesn't support Custom Status Message. Support for custom status code and message in HTTP response Aug 26, 2021
@bclozel
Copy link
Member

bclozel commented Aug 26, 2021

I'm not sure this is something we can support.
The Servlet API provides setStatus(int sc) for non-error statuses and void sendError(int sc, String msg) for errors - those triggger the Servlet container error page, I'm not sure if the message is written on the HTTP status line.

If you can show a consistent way to achieve that with plain Servlet API we can consider it. Could you give it a try?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Aug 26, 2021
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Sep 2, 2021
@bclozel
Copy link
Member

bclozel commented Sep 3, 2021

After reviewing possible solutions, I'm closing this issue.

The Servlet API doesn't allow setting the message on the status line - as said previously, the void sendError(int sc, String msg) will trigger an error HTML page with the provided message. This is defined in the Servlet spec, so there's no way around it.

If you'd like to to provide custom error messages, you can add them in the response body (as serialized JSON, for example). Spring Boot is returning such errors to HTTP clients. We're also consider existing specs for error messages in #27052.

Thanks!

@bclozel bclozel closed this as completed Sep 3, 2021
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants