Rad
Rad

Reputation: 5012

HTTP: what is the correct way to send "retry/redirect" response

I need to force the client to retry its request (meaning to send the same request one more time). What I'm thinking of is a response with status-code 307 and header Location: <original-url> (that's good enough for now, unless there's a better way).

My question is, from HTTP specification point of view, what is the correct value for Location in this specific context. Or more specifically in Java having request of type HttpServletRequest, which one should I use: getRequestURI (Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request) or getRequestURL (Reconstructs the URL the client used to make the request containing protocol, server name, port number, and server path, but it does not include query string parameters).

Any other suggestion/comment is appreciated.

Upvotes: 0

Views: 1243

Answers (2)

jishnu radhakrishnan
jishnu radhakrishnan

Reputation: 159

getRequestURL() returns complete URL used by the client where as getRequestURI() returns just the basic path resides in server. i am using this technique to redirect with a response status this is my code this is useful:-

httpServletResponse.reset();
httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
httpServletResponse.setHeader("SERVER-RESPONSE", "bad request");
return;

and also you can set headers in response.

Upvotes: 1

Julian Reschke
Julian Reschke

Reputation: 42075

I believe a redirect is the wrong status code in the first place.

Isn't this what 503 is for? (https://www.greenbytes.de/tech/webdav/rfc7231.html#status.503)

Upvotes: 0

Related Questions