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 sebb <se...@gmail.com> on 2007/02/03 17:41:46 UTC

Why does HttpClient.executeMethod() reset the host config if URI is absolute?

I'm trying to add relaxed certificate authentication to JMeter by
following the SSLProtocolFactory examples.

This works fine if I register the new protocol as a default, but fails
if I add it to the host configuration.

This is because of the following code in HttpClient.executeMethod():

    if (uri.isAbsoluteURI()) {
        hostconfig.setHost(uri);
     }

the setHost() method picks up the default protocol, rather than the
one from the current host configuration.

Why does executeMethod() need to reset the host details?

If it needs to, perhaps it should ensure that the protocol is not replaced.

Or perhaps the setHost(URI) method should use the current protocol if it exists?

S///

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


Re: Why does HttpClient.executeMethod() reset the host config if URI is absolute?

Posted by sebb <se...@gmail.com>.
On 03/02/07, Roland Weber <ht...@dubioso.net> wrote:
> Hi Sebastian,
>
> > I would have thought it was safe to allow the protocol to propagate,
> > so long as it was for the same scheme?
>
> It is hard to tell for what reason design decisions were made at the
> time. HostConfiguration is mostly used to specify a proxy, and all
> other required fields are just filled in from an absolute URI. Only
> if the URI is not absolute will the fields set manually take effect.
>
> I'm unable to tell what effect a change in this behavior would have
> on existing applications. I've learned recently that the scheme name
> is a bad attribute for identifying protocols, since you might have
> registered a protocol with id "https" for name "http" because you
> want to implicitly change an application's behavior to https.

Good point.

> I don't feel like touching anything in this area of the 3.x code,
> but I won't argue if somebody with more insight agrees with you.
> In the past, it happened maybe twice since I'm on the list that a
> user stumbled over this behavior, and we never did more than tell
> them it will work only for relative URIs.
>
> If you just cut off the "https:" part of the URI, you should see
> the protocol you've set take effect.

Thanks, I'll give it a try.

> cheers,
>  Roland
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>

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


Re: Why does HttpClient.executeMethod() reset the host config if URI is absolute?

Posted by Roland Weber <ht...@dubioso.net>.
Hi Sebastian,

> I would have thought it was safe to allow the protocol to propagate,
> so long as it was for the same scheme?

It is hard to tell for what reason design decisions were made at the
time. HostConfiguration is mostly used to specify a proxy, and all
other required fields are just filled in from an absolute URI. Only
if the URI is not absolute will the fields set manually take effect.

I'm unable to tell what effect a change in this behavior would have
on existing applications. I've learned recently that the scheme name
is a bad attribute for identifying protocols, since you might have
registered a protocol with id "https" for name "http" because you
want to implicitly change an application's behavior to https.

I don't feel like touching anything in this area of the 3.x code,
but I won't argue if somebody with more insight agrees with you.
In the past, it happened maybe twice since I'm on the list that a
user stumbled over this behavior, and we never did more than tell
them it will work only for relative URIs.

If you just cut off the "https:" part of the URI, you should see
the protocol you've set take effect.

cheers,
  Roland

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


Re: Why does HttpClient.executeMethod() reset the host config if URI is absolute?

Posted by sebb <se...@gmail.com>.
On 03/02/07, Roland Weber <ht...@dubioso.net> wrote:
> Hi Sebastian,
>
> in short: because it was designed that way.
>
> The values from the default HostConfiguration will be used if
> server-relative (=path-absolute) URIs are fed into HttpClient.
> You can either convert the URI to a relative one before feeding
> it to HttpClient, or you can modify it to have the protocol
> you want to be used.
> We can't change HttpClient to not update the protocol, just as
> we can't change it to not update the server, if an absolute
> URI is given. The values from the URI take precedence, that's
> the way it's supposed to be. If you send a request to an https
> URL, followed by a request to an http URL, you don't want the
> second request to use https just because it happens to be the
> second request instead of the first one.
>
> hope that helps,
>  Roland

Thanks - I understand that one cannot allow the scheme to propagate
from one request to the next. However, I don't understand why the
protocol for that scheme is reset to the default.

I would have thought it was safe to allow the protocol to propagate,
so long as it was for the same scheme?

Sebastian

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


Re: Why does HttpClient.executeMethod() reset the host config if URI is absolute?

Posted by Roland Weber <ht...@dubioso.net>.
Hi Sebastian,

in short: because it was designed that way.

The values from the default HostConfiguration will be used if
server-relative (=path-absolute) URIs are fed into HttpClient.
You can either convert the URI to a relative one before feeding
it to HttpClient, or you can modify it to have the protocol
you want to be used.
We can't change HttpClient to not update the protocol, just as
we can't change it to not update the server, if an absolute
URI is given. The values from the URI take precedence, that's
the way it's supposed to be. If you send a request to an https
URL, followed by a request to an http URL, you don't want the
second request to use https just because it happens to be the
second request instead of the first one.

hope that helps,
  Roland

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