WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

jaayer
But this addition to WebResponse seems to do the trick (even when the request was redirected):
finalUrl
        ^ 'http://', (request headerAt: 'Host'), request rawUrl

I kind of think


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

jaayer


---- On Mon, 23 Aug 2010 19:48:27 -0700 jaayer  wrote ----

>But this addition to WebResponse seems to do the trick (even when the request was redirected):
>finalUrl
>    ^ 'http://', (request headerAt: 'Host'), request rawUrl
>
>I kind of think

got cutoff there. I was going to say that perhaps there ought to be a method in WebRequest to get the absolute URL of a request, and maybe this method in WebResponse can be reimplemented in terms of it.


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

Andreas.Raab
Hi -

Can you say a little more what you need this URL for? I don't think it
makes quite sense to implement it in the way you're suggesting since the
scheme would be guesswork (what if it's https or rtsp or something
else?) and the host-header might not be present. It seems to me that
some context needs be provided (probably) via WebServer to fill in what
is needed but for that I'd need to know where you're trying to use the
url (i.e., in a server or a client?).

Cheers,
   - Andreas

On 8/23/2010 7:53 PM, jaayer wrote:

>
>
> ---- On Mon, 23 Aug 2010 19:48:27 -0700 jaayer  wrote ----
>
>> But this addition to WebResponse seems to do the trick (even when the request was redirected):
>> finalUrl
>>      ^ 'http://', (request headerAt: 'Host'), request rawUrl
>>
>> I kind of think
>
> got cutoff there. I was going to say that perhaps there ought to be a method in WebRequest to get the absolute URL of a request, and maybe this method in WebResponse can be reimplemented in terms of it.
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

jaayer


---- On Mon, 23 Aug 2010 20:20:14 -0700 Andreas Raab  wrote ----

>Hi -
>
>Can you say a little more what you need this URL for? I don't think it
>makes quite sense to implement it in the way you're suggesting since the
>scheme would be guesswork (what if it's https or rtsp or something
>else?) and the host-header might not be present. It seems to me that
>some context needs be provided (probably) via WebServer to fill in what
>is needed but for that I'd need to know where you're trying to use the
>url (i.e., in a server or a client?).

I need to be able to write something like this:

aResponse := WebClient httpGet: aUrl.

and have some message I can send to aResponse to get the URL of the resource at which the request terminated. That means if aUrl was "http://google.com", then sending the proposed message to aResponse should yield "http://www.google.com," as a request for the former results in a redirection (301) to the latter. This is doable with HTTPSocket:

(HTTPSocket httpGetDocument: 'http://google.com') url
 
(which yields "http://www.google.com")

The information for the scheme could come from WebClient itself, as could the hostname (although HTTP 1.1 makes the Host field mandatory). I think it would be nice if both WebRequest and WebResponse could give you absolute URLs representing them. "finalUrl" was probably a poor choice of name; "absoluteUrl" would be better.


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

Andreas.Raab
On 8/24/2010 2:12 AM, jaayer wrote:

> I need to be able to write something like this:
>
> aResponse := WebClient httpGet: aUrl.
>
> and have some message I can send to aResponse to get the URL of the resource at which the request terminated. That means if aUrl was "http://google.com", then sending the proposed message to aResponse should yield "http://www.google.com," as a request for the former results in a redirection (301) to the latter. This is doable with HTTPSocket:
>
> (HTTPSocket httpGetDocument: 'http://google.com') url
>
> (which yields "http://www.google.com")
>
> The information for the scheme could come from WebClient itself, as could the hostname (although HTTP 1.1 makes the Host field mandatory). I think it would be nice if both WebRequest and WebResponse could give you absolute URLs representing them. "finalUrl" was probably a poor choice of name; "absoluteUrl" would be better.

I've done just that, and if you update WebClient from the repository you
will now be able to find out the final url by doing:

resp := WebClient httpGet: 'http://squeaksource.com/WebClient.html'.
resp url

=>'http://squeaksource.com/@qvbZrGJEgfjgaKS8/FoGS9Ilj'

Thank you for this suggestion.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

jaayer


---- On Tue, 24 Aug 2010 21:50:54 -0700 Andreas Raab  wrote ----

>On 8/24/2010 2:12 AM, jaayer wrote:
>> I need to be able to write something like this:
>>
>> aResponse := WebClient httpGet: aUrl.
>>
>> and have some message I can send to aResponse to get the URL of the resource at which the request terminated. That means if aUrl was "http://google.com", then sending the proposed message to aResponse should yield "http://www.google.com," as a request for the former results in a redirection (301) to the latter. This is doable with HTTPSocket:
>>
>> (HTTPSocket httpGetDocument: 'http://google.com') url
>>
>> (which yields "http://www.google.com")
>>
>> The information for the scheme could come from WebClient itself, as could the hostname (although HTTP 1.1 makes the Host field mandatory). I think it would be nice if both WebRequest and WebResponse could give you absolute URLs representing them. "finalUrl" was probably a poor choice of name; "absoluteUrl" would be better.
>
>I've done just that, and if you update WebClient from the repository you
>will now be able to find out the final url by doing:
>
>resp := WebClient httpGet: 'http://squeaksource.com/WebClient.html'.
>resp url
>
>=>'http://squeaksource.com/@qvbZrGJEgfjgaKS8/FoGS9Ilj' 
>
>Thank you for this suggestion.
>
>Cheers,
> - Andreas

Thaks; that is exactly what I need. I have also sent you a package containing minor fixes for WebClient-Core.


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

Andreas.Raab
On 8/24/2010 11:24 PM, jaayer wrote:
> Thaks; that is exactly what I need. I have also sent you a package containing minor fixes for WebClient-Core.

You did? I didn't see that. It was probably marked as spam because of
the attachment or something (I seem to be having more problems than
usual recently; I'm wondering if the thunderbird update had anything to
do with it...) Can you resend?

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

jaayer


---- On Tue, 24 Aug 2010 23:33:44 -0700 Andreas Raab  wrote ----

>On 8/24/2010 11:24 PM, jaayer wrote:
>> Thaks; that is exactly what I need. I have also sent you a package containing minor fixes for WebClient-Core.
>
>You did? I didn't see that. It was probably marked as spam because of
>the attachment or something (I seem to be having more problems than
>usual recently; I'm wondering if the thunderbird update had anything to
>do with it...) Can you resend?
>
>Cheers,
> - Andreas

Done.


Reply | Threaded
Open this post in threaded view
|

Re: WebClient does not seem to provide any way of getting the terminating, absolute URL of a response

Andreas.Raab
On 8/25/2010 5:36 PM, jaayer wrote:

>
>
> ---- On Tue, 24 Aug 2010 23:33:44 -0700 Andreas Raab  wrote ----
>
>> On 8/24/2010 11:24 PM, jaayer wrote:
>>> Thaks; that is exactly what I need. I have also sent you a package containing minor fixes for WebClient-Core.
>>
>> You did? I didn't see that. It was probably marked as spam because of
>> the attachment or something (I seem to be having more problems than
>> usual recently; I'm wondering if the thunderbird update had anything to
>> do with it...) Can you resend?
>>
>> Cheers,
>> - Andreas
>
> Done.

Thanks, got it (and yes it was in the spam folder). While sifting
through my spam folder I also found a couple of other (Squeak-related)
messages that I had missed. If you've sent me emails with attachments
and have not heard back, you might want to send me a reminder without
attachment; I think Thunderbird 3's spam filter may assign a *heavy*
penalty for attachments.

Cheers,
   - Andreas