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?
Please note that using underscores in headers is perfectly valid per the HTTP spec, but Nginx, by default, will ignore them.
The name of the HTTP request header you want to set or remove can only contain: Alphanumeric characters: a - z and A - Z. The following special characters: - and _
In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With