Reputation: 756
When specifying custom header containing underscores using HTTP::Request
from LWP::UserAgent
, the underscores are changed to hyphens:
use LWP::UserAgent;
my $rq = HTTP::Request->new("GET", "http://cpan.org");
$rq->header("X-FOO_BAR", "xyzzy");
print $rq->as_string;
outputs:
GET http://cpan.org
X-FOO-BAR: xyzzy
Is there a way to turn this behavior off?
Upvotes: 8
Views: 2625
Reputation: 1
I had the same problem too while trying to write out a location in a pages header via CGI::Session
. I fixed it by replacing the underscore with %5f
and it worked for me. In your case this might work:
$rq->header('X-FOO%5fBAR', "xyzzy");
Upvotes: 0
Reputation: 5290
Try naming the header with a leading :
, as per the documentation in HTTP::Headers under "NON-CANONICALIZED FIELD NAMES":
The header field name spelling is normally canonicalized including the '_' to '-' translation. There are some application where this is not appropriate. Prefixing field names with ':' allow you to force a specific spelling.
Upvotes: 16