HTTP Redirect with different response code

Poster Content
nk4um Moderator
Posts: 763
January 3, 2012 09:30

Hi Chris,

Firstly everything in SE is also in EE - the EE module just imports and relays on the SE module with a superset of extras like the asynchronous handler.

httpResponse:/redirect is a one stop shop for issuing 302's - it wasn't intended to be an API. Since, as you've shown, you can control the full feature set either by setting the appropriate headers, or by using the advanced servlet response interface.

Your solution can be improved by not SINKing but by setting NK response headers on your response...

resp=aContext.createResponseFrom(foo);
resp.setHeader("httpResponse:/header/Location", "/my-path");
resp.setHeader("httpResponse:/code", 301);

This eliminates two requests and does exactly the same thing.

Hope this helps.

Peter

nk4um User
Posts: 158
December 22, 2011 13:13HTTP Redirect with different response code

Is it possible to do a SINK to httpResponse:/redirect and specify to use a 301 code (instead of the default 302)?

I've looked at the source code of the SE version of the HTTP transport and spotted org.netkernel.http.rep.IHttpRedirect, but I can't see if there is the same in the EE version of the module. Ideally I'd like to be able to compile my code so it works on SE and EE.

I also tried:

aContext.sink("httpResponse:/redirect", "/my-path");
aContext.sink("httpResponse:/code", 301);

but the setting of the code seems to take precedence over the redirect and so it disappears.

The only workaround I can see is:

aContext.sink("httpResponse:/header/Location", "/my-path");
aContext.sink("httpResponse:/code", 301);

but this feels less that ideal.

Any thoughts?

-cc