use HTTP::Request;
Change that line to:
BEGIN {
use HTTP::Request;
$HTTP::Headers::TRANSLATE_UNDERSCORE = 0;
}
That's the fix.
Read on for details ...
My test:
#!/usr/bin/env perl -l
use strict;
use warnings;
BEGIN {
use HTTP::Request;
$HTTP::Headers::TRANSLATE_UNDERSCORE = 0;
}
use Data::Dump;
my $r = HTTP::Request->new;
my $header = $r->header('__X_Y__', 1);
dd $r;
With just "use HTTP::Request;", instead of that BEGIN block, I get:
bless({
_content => "",
_headers => bless({ "--x-y--" => 1, "::std_case" => { "--x-y--" => "
+--X-Y--" } }, "HTTP::Headers"),
_method => undef,
_uri => undef,
}, "HTTP::Request")
With the BEGIN block, as shown, I get:
bless({
_content => "",
_headers => bless({ "::std_case" => { __x_y__ => "__X_Y__" }, "__x_y
+__" => 1 }, "HTTP::Headers"),
_method => undef,
_uri => undef,
}, "HTTP::Request")
"Why is that ..."
A little investigation, using the published documentation, provided the answer.
In HTTP::Request,
under "$r->header( $field => $value )", you'll see:
"This is used to get/set header values and it is inherited from HTTP::Headers ..."
In HTTP::Headers,
under "$h->header( $field => $value )", you'll see:
"To make the life easier for perl users who wants to avoid quoting before the => operator, you can use '_' as a replacement for '-' in header names."
You'll also see similar comments for other methods.
Following the Source link
(at the top of the page), shows:
...
# The $TRANSLATE_UNDERSCORE variable controls whether '_' can be used
# as a replacement for '-' in header field names.
our $TRANSLATE_UNDERSCORE = 1 unless defined $TRANSLATE_UNDERSCORE;
...
$field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
...
I searched the documentation of both HTTP::Request and HTTP::Headers
for "TRANSLATE_UNDERSCORE": no matches were found.
Perhaps you'd care to raise a bug report for a documentation enhancement.
|