You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by Servalan eq <se...@hotmail.com> on 2012/04/16 16:59:14 UTC
Redirection (302 or 301) from a non remap plugin.
Is there a way to do a (302) redirection from the non remap plugin?
I have a remap plugin where this works - by setting he elements of the URL and then setting redirect = 1 on the TSRemapRequestInfo object.
>From a standard plugin hooked to the TS_EVENT_HTTP_READ_REQUEST_HDR Ihave my two servers being reverse proxied by calling TSUrlHostSet, TSUrlPathSetand then
TSSkipRemappingSet(txnp, 1); but in some cases I need to issue a redirect request.
I think I need to set the RedirectInfo redirect_info; in the State struct, in "HttpTransact.h but I can't see how do do this?
Has anyone else tried this?
thanks very much,Servalan
RE: Redirection (302 or 301) from a non remap plugin.
Posted by Servalan eq <se...@hotmail.com>.
> Date: Mon, 16 Apr 2012 14:59:53 -0600
> From: zwoop@apache.org
> To: users@trafficserver.apache.org
> CC: servalaneq@hotmail.com
> Subject: Re: Redirection (302 or 301) from a non remap plugin.
>
> On 4/16/12 8:59 AM, Servalan eq wrote:
> > Is there a way to do a (302) redirection from the non remap plugin?
> >
> > I have a remap plugin where this works - by setting he elements of the URL
> > and then setting redirect = 1 on the TSRemapRequestInfo object.
> >
> > From a standard plugin hooked to the TS_EVENT_HTTP_READ_REQUEST_HDR I
> > have my two servers being reverse proxied by calling TSUrlHostSet,
> > TSUrlPathSet
> > and then
> >
> > TSSkipRemappingSet(txnp, 1);
> > but in some cases I need to issue a redirect request.
> >
>
> You can not use any o fthe "RRI" stuff in anything but a remap plugin (it
> simply doesn't apply or map to anything in the core). You should however
> just have to set the appopriate response headers, and response codes.
> There's for example a blacklist plugin example, which shows one way to do this.
>
> -- Leif
>
>
Thanks Leif, that worked once I realised I needed to add the status with
TSHttpHdrStatusSet(bufp, hdr_loc, TS_HTTP_STATUS_MOVED_TEMPORARILY);TSUrlHostGetand the location header using (say)TSMimeHdrFieldCreateNamed(reqp, hdr_loc, TS_MIME_FIELD_LOCATION,
TS_MIME_LEN_LOCATION , &new_field);TSMimeHdrFieldValueStringInsert(reqp, hdr_loc, new_field, -1, val, val_len);TSMimeHdrFieldAppend(reqp, hdr_loc, new_field);
To the _response_ header buffer, and so I had to hook my continuation to the TS_EVENT_HTTP_SEND_RESPONSE_HDR event and wait till then.
The only problem I now have is that my TSUrlHostGet in the TS_EVENT_HTTP_READ_REQUEST_HDR handler is failing, even though getting it manually with
TSMimeHdrFieldFind(..
is working, and returns the Host (and port).
thanks very much for all your help
Servalan
Re: Redirection (302 or 301) from a non remap plugin.
Posted by Leif Hedstrom <zw...@apache.org>.
On 4/16/12 8:59 AM, Servalan eq wrote:
> Is there a way to do a (302) redirection from the non remap plugin?
>
> I have a remap plugin where this works - by setting he elements of the URL
> and then setting redirect = 1 on the TSRemapRequestInfo object.
>
> From a standard plugin hooked to the TS_EVENT_HTTP_READ_REQUEST_HDR I
> have my two servers being reverse proxied by calling TSUrlHostSet,
> TSUrlPathSet
> and then
>
> TSSkipRemappingSet(txnp, 1);
> but in some cases I need to issue a redirect request.
>
You can not use any o fthe "RRI" stuff in anything but a remap plugin (it
simply doesn't apply or map to anything in the core). You should however
just have to set the appopriate response headers, and response codes.
There's for example a blacklist plugin example, which shows one way to do this.
-- Leif