You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jose Kahan <jo...@w3.org> on 2009/03/12 16:40:54 UTC
Misleading example in Apache 2 doc
!
I'm not sure if I should mail this here or open a
new bugzilla report. Please advice.
The Content Negotiation doc is using a misleading
example in this section:
http://httpd.apache.org/docs/2.2/content-negotiation.html#better
[[
Example
SetEnvIf Cookie "language=(.+)" prefer-language=$1
Header append Vary cookie
]]
That regular expression won't work if the cookie has other attributes
in addition to the language one. One of our users got caught
by it. A quick search on the web shows that many people have had
this problem too.
Here's a correct regular expression that will return the language
attribute value, regardless of the contents of the cookie:
[[
SetEnvIf Cookie "language=([a-z|A-Z][a-z|A-Z|-]+)" prefer-language=$1
]]
The expression looks bigger because it takes into account not
only strings like "en", but also "zh-hans". I added upper and lower
case as cookies are case insensitive and I'm not sure if Apache converts
cookies to lower-case at some point. If it's always lower case,
we can simplify the regular expression to:
[[
SetEnvIf Cookie "language=([a-z][a-z|-]+)" prefer-language=$1
]]
Could you update the example in the doc accordingly?
Thanks!
-jose
Re: Misleading example in Apache 2 doc (fix)
Posted by Jose Kahan <jo...@w3.org>.
Hi André,
> language\s*=\s*([^;,\s]+)
Your expression works well and is simpler than mine.
+1 to update the doc with it instead of my proposal.
Thanks :)
-jose
Re: Misleading example in Apache 2 doc (fix)
Posted by André Malo <nd...@perlig.de>.
* Jose Kahan wrote:
[adding docs@]
> I didn't do my homework completely. According to
> RFC 2910, Cookie tokens may be separated by
> white space. The correct regular expression is:
>
> [[
> SetEnvIf Cookie "language\s*=\s*([a-z|A-Z][a-z|A-Z|-]+)"
> prefer-language=$1 ]]
Also, why are you allowing pipe characters within the language spec? ;-)
How about simply:
language\s*=\s*([a-zA-Z-]+)
?
Maybe
language\s*=\s*([^;,\s]+)
is even better (more flexible). dunno.
nd
--
my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~});
my $japh = q[sub japh { }]; print join #########################
[ $japh =~ /{(.)}/] -> [0] => map $_ -> () # André Malo #
=> @japh; # http://pub.perlig.de/ #
Re: Misleading example in Apache 2 doc (fix)
Posted by André Malo <nd...@perlig.de>.
* Jose Kahan wrote:
[adding docs@]
> I didn't do my homework completely. According to
> RFC 2910, Cookie tokens may be separated by
> white space. The correct regular expression is:
>
> [[
> SetEnvIf Cookie "language\s*=\s*([a-z|A-Z][a-z|A-Z|-]+)"
> prefer-language=$1 ]]
Also, why are you allowing pipe characters within the language spec? ;-)
How about simply:
language\s*=\s*([a-zA-Z-]+)
?
Maybe
language\s*=\s*([^;,\s]+)
is even better (more flexible). dunno.
nd
--
my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~});
my $japh = q[sub japh { }]; print join #########################
[ $japh =~ /{(.)}/] -> [0] => map $_ -> () # André Malo #
=> @japh; # http://pub.perlig.de/ #
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
Misleading example in Apache 2 doc (fix)
Posted by Jose Kahan <jo...@w3.org>.
I didn't do my homework completely. According to
RFC 2910, Cookie tokens may be separated by
white space. The correct regular expression is:
[[
SetEnvIf Cookie "language\s*=\s*([a-z|A-Z][a-z|A-Z|-]+)" prefer-language=$1
]]
Thanks!
-jose