You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Michael Peters <mp...@plusthree.com> on 2006/04/21 17:49:19 UTC

retrieving the anchor tags in internal redirects

I have a application with mod_perl Authen/Authz handlers that will
redirect to a login screen (via ErrorDocument) if the user is not logged
in. Users follow links in emails and these links occasionally have
anchors in them:
  http://mysite.com/app?foo=bar#123

For the ErrorDocument 403 page that displays the login, it populates a
'back' param into a hidden form input so that after a login we can take
the user to exactly where they want to go. Pretty standard stuff. To
create this 'back' URL I use something like

  my $url = $r->prev->uri . '?' . $r->prev->args;

Which works fine except that the anchor info (#123) is lost. Is there
anyway to get this from the original request's URL?

-- 
Michael Peters
Developer
Plus Three, LP


Re: retrieving the anchor tags in internal redirects

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> That's what I just found out too. I tried Fred's suggestions of using
> Apache::URI's fragment, but nothing seemed to work. So I decided to just
> make sure it was being passed to the server. It seems that the browser
> (tried with FF 1.5 and wget) doesn't pass the #fragment.
> 
> If this is true, why do we even have these methods in Apache::URI ?

because manipulating a passed uri is only one way to use the API.  another
is to create a uri (with all it's pieces, including the fragment) for use
someplace.

--Geoff

Re: retrieving the anchor tags in internal redirects

Posted by Michael Peters <mp...@plusthree.com>.

David Wright wrote:
>> fragment() is also discussed in chapter 5 of the mpdc.  it's been a
>> while,
>> but I'm pretty sure that what it says in 5.3 is true, that the browser
>> holds
>> on to it (as it does auth information) and won't let the server know.
> 
> Yeah, it's oddly hard to find references to this. The best I found was:
> 
> http://www.w3.org/TR/webarch/#media-type-fragid
> 
> "Interpretation of the fragment identifier is performed solely by the
> agent that dereferences a URI; the fragment identifier is not passed to
> other systems during the process of retrieval."

That's what I just found out too. I tried Fred's suggestions of using
Apache::URI's fragment, but nothing seemed to work. So I decided to just
make sure it was being passed to the server. It seems that the browser
(tried with FF 1.5 and wget) doesn't pass the #fragment.

If this is true, why do we even have these methods in Apache::URI ?

-- 
Michael Peters
Developer
Plus Three, LP


Re: retrieving the anchor tags in internal redirects

Posted by David Wright <da...@dexy.org>.
> fragment() is also discussed in chapter 5 of the mpdc.  it's been a while,
> but I'm pretty sure that what it says in 5.3 is true, that the browser holds
> on to it (as it does auth information) and won't let the server know.

Yeah, it's oddly hard to find references to this. The best I found was:

http://www.w3.org/TR/webarch/#media-type-fragid

"Interpretation of the fragment identifier is performed solely by the
agent that dereferences a URI; the fragment identifier is not passed to
other systems during the process of retrieval."


david

Re: retrieving the anchor tags in internal redirects

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Fred Moyer wrote:
> On Fri, 21 Apr 2006 9:31 am, Fred Moyer wrote:
> 
>> Michael Peters wrote:
>>
>>> Frank Wiles wrote:
>>
>> [...]
>>
>>>>> Which works fine except that the anchor info (#123) is lost. Is there
>>>>> anyway to get this from the original request's URL?
>>
>>
>> The 2.0 docs seem to indicate that this piece is called the 'fragment'
>> [1], and there is a corresponding fragment method in mod_perl1 [2] but
>> is not described in as much detail.  I haven't tried that method but
>> it might be what you're looking for.
> 
> 
> Sorry use these links instead please, cannot guarantee the freshness of
> the other ones always:
> 
> [1]
> http://perl.apache.org/docs/2.0/api/APR/URI.html#C_fragment_
> [2]
> http://perl.apache.org/docs/1.0/api/Apache/URI.html

fragment() is also discussed in chapter 5 of the mpdc.  it's been a while,
but I'm pretty sure that what it says in 5.3 is true, that the browser holds
on to it (as it does auth information) and won't let the server know.  so,
whether you can glean that information really depends on where you're
building and parsing your uri and what the source is.

HTH

--Geoff

Re: retrieving the anchor tags in internal redirects

Posted by Fred Moyer <fr...@redhotpenguin.com>.
On Fri, 21 Apr 2006 9:31 am, Fred Moyer wrote:
> Michael Peters wrote:
>> Frank Wiles wrote:
> [...]
>>>> Which works fine except that the anchor info (#123) is lost. Is there
>>>> anyway to get this from the original request's URL?
>
> The 2.0 docs seem to indicate that this piece is called the 'fragment' 
> [1], and there is a corresponding fragment method in mod_perl1 [2] but 
> is not described in as much detail.  I haven't tried that method but it 
> might be what you're looking for.

Sorry use these links instead please, cannot guarantee the freshness of 
the other ones always:

[1]
http://perl.apache.org/docs/2.0/api/APR/URI.html#C_fragment_
[2]
http://perl.apache.org/docs/1.0/api/Apache/URI.html

Re: retrieving the anchor tags in internal redirects

Posted by Fred Moyer <fr...@taperfriendlymusic.org>.
Michael Peters wrote:
> 
> Frank Wiles wrote:
[...]
>>>Which works fine except that the anchor info (#123) is lost. Is there
>>>anyway to get this from the original request's URL?
>>
>>  I think you're looking for $r->prev->unparsed_uri 
> 
> 
> Thanks, but I guess I should have mentioned that I'm using mod_perl 1
> and this method doesn't exist. Is there some equivalent that I can do,
> or is this information just lost?
> 

The 2.0 docs seem to indicate that this piece is called the 'fragment' 
[1], and there is a corresponding fragment method in mod_perl1 [2] but 
is not described in as much detail.  I haven't tried that method but it 
might be what you're looking for.

[1]
http://redhotpenguin.com/mirrors/perl.apache.org/docs/2.0/api/APR/URI.html#C_fragment_
[2]
http://redhotpenguin.com/mirrors/perl.apache.org/docs/1.0/api/Apache/URI.html

Re: retrieving the anchor tags in internal redirects

Posted by Michael Peters <mp...@plusthree.com>.

Frank Wiles wrote:
> On Fri, 21 Apr 2006 11:49:19 -0400
> Michael Peters <mp...@plusthree.com> wrote:
> 
>> I have a application with mod_perl Authen/Authz handlers that will
>> redirect to a login screen (via ErrorDocument) if the user is not
>> logged in. Users follow links in emails and these links occasionally
>> have anchors in them:
>>   http://mysite.com/app?foo=bar#123
>>
>> For the ErrorDocument 403 page that displays the login, it populates a
>> 'back' param into a hidden form input so that after a login we can
>> take the user to exactly where they want to go. Pretty standard
>> stuff. To create this 'back' URL I use something like
>>
>>   my $url = $r->prev->uri . '?' . $r->prev->args;
>>
>> Which works fine except that the anchor info (#123) is lost. Is there
>> anyway to get this from the original request's URL?
> 
>   I think you're looking for $r->prev->unparsed_uri 

Thanks, but I guess I should have mentioned that I'm using mod_perl 1
and this method doesn't exist. Is there some equivalent that I can do,
or is this information just lost?

-- 
Michael Peters
Developer
Plus Three, LP


Re: retrieving the anchor tags in internal redirects

Posted by Frank Wiles <fr...@wiles.org>.
On Fri, 21 Apr 2006 11:49:19 -0400
Michael Peters <mp...@plusthree.com> wrote:

> I have a application with mod_perl Authen/Authz handlers that will
> redirect to a login screen (via ErrorDocument) if the user is not
> logged in. Users follow links in emails and these links occasionally
> have anchors in them:
>   http://mysite.com/app?foo=bar#123
> 
> For the ErrorDocument 403 page that displays the login, it populates a
> 'back' param into a hidden form input so that after a login we can
> take the user to exactly where they want to go. Pretty standard
> stuff. To create this 'back' URL I use something like
> 
>   my $url = $r->prev->uri . '?' . $r->prev->args;
> 
> Which works fine except that the anchor info (#123) is lost. Is there
> anyway to get this from the original request's URL?

  I think you're looking for $r->prev->unparsed_uri 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------