You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Josh Gordineer <jo...@gmail.com> on 2010/07/08 01:14:21 UTC

Redirect on POST with a custom redirect handler?

I'm looking for a way to handle a redirect on POST, obviously HttpClient
doesn't handle them automatically.

"HttpClient handles all types of redirects automatically, except those
explicitly prohibited by the HTTP specification as requiring user
intervention. See Other (status code 303) redirects on POST and PUT requests
are converted to GET requests as required by the HTTP specification."

http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199

The above states that the requests are automatically converted to GETs.  I
was wondering if that logic to convert the requests to GETs exists in a
place where I can customize such as a custom RedirectHandler or is the best
approach to turn off automatic redirects and write custom logic to handle
each redirect response?

Thanks in advance..

--Josh

Re: Redirect on POST with a custom redirect handler?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-07-08 at 16:27 -0700, Josh Gordineer wrote:
> Wow, I'll definitely check out the new RedirectStrategy Oleg.  How stable is
> 4.1 alpha? 

It is pretty much as reliable as the stable branch but new APIs
introduced in the 4.1 branch can still change without prior notice or a
deprecation period, hence ALPHA status. 


>  When is the release target?  I am usually a little hesitant to
> go with alpha packages but if this saves us some work it might be worth a
> shot.
> 

Q4 2010 / Q1 2011

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Redirect on POST with a custom redirect handler?

Posted by Josh Gordineer <jo...@gmail.com>.
Wow, I'll definitely check out the new RedirectStrategy Oleg.  How stable is
4.1 alpha?  When is the release target?  I am usually a little hesitant to
go with alpha packages but if this saves us some work it might be worth a
shot.

Thanks..

--Josh


On Thu, Jul 8, 2010 at 12:45 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Thu, 2010-07-08 at 10:27 -0700, Josh Gordineer wrote:
> > Thanks Sam.  We don't control the target server so looks like I'll be
> doing
> > manual redirect following.
> >
> > --Josh
> >
>
> Josh,
>
> If you do not mind using alpha versions, HttpClient 4.1 comes with a new
> RedirectStrategy interface that can be used instead of the
> RedirectHandler. Both RedirectStrategy / RedirectHandler can be used to
> override protocol restrictions on the automatic redirect handling, but
> RedirectStrategy also allows for redirects without conversion to GET
> (POSTs/PUTs can be redirected as POSTs/PUTs)
>
> Oleg
>
> > On Wed, Jul 7, 2010 at 4:25 PM, <sa...@gmail.com> wrote:
> >
> > > If you know/control the behaviour of the target server you can use the
> > > expect-continue handshake (google for it). HttpClient supports this.
> > >
> > > If not, I'd disable following of redirects (which will result in a GET,
> as
> > > you rightly say) and write a small bit of code to capture the response
> code
> > > and loop until we got a 200 (or a limit was reached).
> > >
> > > Thanks
> > >
> > > Sam
> > >
> > > -----Original Message-----
> > > From: Josh Gordineer <jo...@gmail.com>
> > > Date: Wed, 7 Jul 2010 16:14:21
> > > To: <ht...@hc.apache.org>
> > > Reply-To: "HttpClient User Discussion" <httpclient-users@hc.apache.org
> >
> > > Subject: Redirect on POST with a custom redirect handler?
> > >
> > > I'm looking for a way to handle a redirect on POST, obviously
> HttpClient
> > > doesn't handle them automatically.
> > >
> > > "HttpClient handles all types of redirects automatically, except those
> > > explicitly prohibited by the HTTP specification as requiring user
> > > intervention. See Other (status code 303) redirects on POST and PUT
> > > requests
> > > are converted to GET requests as required by the HTTP specification."
> > >
> > >
> > >
> http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199
> > >
> > > The above states that the requests are automatically converted to GETs.
>  I
> > > was wondering if that logic to convert the requests to GETs exists in a
> > > place where I can customize such as a custom RedirectHandler or is the
> best
> > > approach to turn off automatic redirects and write custom logic to
> handle
> > > each redirect response?
> > >
> > > Thanks in advance..
> > >
> > > --Josh
> > >
> > >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: Redirect on POST with a custom redirect handler?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-07-08 at 10:27 -0700, Josh Gordineer wrote:
> Thanks Sam.  We don't control the target server so looks like I'll be doing
> manual redirect following.
> 
> --Josh
> 

Josh,

If you do not mind using alpha versions, HttpClient 4.1 comes with a new
RedirectStrategy interface that can be used instead of the
RedirectHandler. Both RedirectStrategy / RedirectHandler can be used to
override protocol restrictions on the automatic redirect handling, but
RedirectStrategy also allows for redirects without conversion to GET
(POSTs/PUTs can be redirected as POSTs/PUTs) 

Oleg

> On Wed, Jul 7, 2010 at 4:25 PM, <sa...@gmail.com> wrote:
> 
> > If you know/control the behaviour of the target server you can use the
> > expect-continue handshake (google for it). HttpClient supports this.
> >
> > If not, I'd disable following of redirects (which will result in a GET, as
> > you rightly say) and write a small bit of code to capture the response code
> > and loop until we got a 200 (or a limit was reached).
> >
> > Thanks
> >
> > Sam
> >
> > -----Original Message-----
> > From: Josh Gordineer <jo...@gmail.com>
> > Date: Wed, 7 Jul 2010 16:14:21
> > To: <ht...@hc.apache.org>
> > Reply-To: "HttpClient User Discussion" <ht...@hc.apache.org>
> > Subject: Redirect on POST with a custom redirect handler?
> >
> > I'm looking for a way to handle a redirect on POST, obviously HttpClient
> > doesn't handle them automatically.
> >
> > "HttpClient handles all types of redirects automatically, except those
> > explicitly prohibited by the HTTP specification as requiring user
> > intervention. See Other (status code 303) redirects on POST and PUT
> > requests
> > are converted to GET requests as required by the HTTP specification."
> >
> >
> > http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199
> >
> > The above states that the requests are automatically converted to GETs.  I
> > was wondering if that logic to convert the requests to GETs exists in a
> > place where I can customize such as a custom RedirectHandler or is the best
> > approach to turn off automatic redirects and write custom logic to handle
> > each redirect response?
> >
> > Thanks in advance..
> >
> > --Josh
> >
> >



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Redirect on POST with a custom redirect handler?

Posted by Josh Gordineer <jo...@gmail.com>.
Thanks Sam.  We don't control the target server so looks like I'll be doing
manual redirect following.

--Josh

On Wed, Jul 7, 2010 at 4:25 PM, <sa...@gmail.com> wrote:

> If you know/control the behaviour of the target server you can use the
> expect-continue handshake (google for it). HttpClient supports this.
>
> If not, I'd disable following of redirects (which will result in a GET, as
> you rightly say) and write a small bit of code to capture the response code
> and loop until we got a 200 (or a limit was reached).
>
> Thanks
>
> Sam
>
> -----Original Message-----
> From: Josh Gordineer <jo...@gmail.com>
> Date: Wed, 7 Jul 2010 16:14:21
> To: <ht...@hc.apache.org>
> Reply-To: "HttpClient User Discussion" <ht...@hc.apache.org>
> Subject: Redirect on POST with a custom redirect handler?
>
> I'm looking for a way to handle a redirect on POST, obviously HttpClient
> doesn't handle them automatically.
>
> "HttpClient handles all types of redirects automatically, except those
> explicitly prohibited by the HTTP specification as requiring user
> intervention. See Other (status code 303) redirects on POST and PUT
> requests
> are converted to GET requests as required by the HTTP specification."
>
>
> http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199
>
> The above states that the requests are automatically converted to GETs.  I
> was wondering if that logic to convert the requests to GETs exists in a
> place where I can customize such as a custom RedirectHandler or is the best
> approach to turn off automatic redirects and write custom logic to handle
> each redirect response?
>
> Thanks in advance..
>
> --Josh
>
>

Re: Redirect on POST with a custom redirect handler?

Posted by sa...@gmail.com.
If you know/control the behaviour of the target server you can use the expect-continue handshake (google for it). HttpClient supports this.

If not, I'd disable following of redirects (which will result in a GET, as you rightly say) and write a small bit of code to capture the response code and loop until we got a 200 (or a limit was reached).

Thanks

Sam

-----Original Message-----
From: Josh Gordineer <jo...@gmail.com>
Date: Wed, 7 Jul 2010 16:14:21 
To: <ht...@hc.apache.org>
Reply-To: "HttpClient User Discussion" <ht...@hc.apache.org>
Subject: Redirect on POST with a custom redirect handler?

I'm looking for a way to handle a redirect on POST, obviously HttpClient
doesn't handle them automatically.

"HttpClient handles all types of redirects automatically, except those
explicitly prohibited by the HTTP specification as requiring user
intervention. See Other (status code 303) redirects on POST and PUT requests
are converted to GET requests as required by the HTTP specification."

http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199

The above states that the requests are automatically converted to GETs.  I
was wondering if that logic to convert the requests to GETs exists in a
place where I can customize such as a custom RedirectHandler or is the best
approach to turn off automatic redirects and write custom logic to handle
each redirect response?

Thanks in advance..

--Josh