Hi, I have written a simple HTTP Proxy which I want to use to add an entry to the header of every request passing through it. My problem is that all underscores "_" get changed to hyphens "-" in the entries' keys and the key is converted to lowercase. The code looks as follows:

The ini file:

[proxy_setup] #port on which proxy listens, use in browser proxy settings port=84 #header to add header_key=SM_USER header_value=waldo
The proxy:
use HTTP::Proxy; use HTTP::Proxy::HeaderFilter::simple; use HTTP::Proxy::Engine::NoFork; use Config::IniFiles; #initialize ini file loading my $ini = 'SM_Proxy.ini'; my $cfg = new Config::IniFiles(-file => $ini); die "invalid ini file $ini" unless defined($cfg); #reads specified config file entry sub read_cfg { my ($section, $key) = @_; my $val = $cfg->val($section, $key); die "undefined key $key in section $section" unless defined($val); $val; } #read values from ini file my $port = read_cfg('proxy_setup', 'port'); my $header_key = read_cfg('proxy_setup', 'header_key'); my $header_value = read_cfg('proxy_setup', 'header_value'); #define proxy and header filter(adding entry read from ini file to eac +h request header) my $proxy = HTTP::Proxy->new( host => "127.0.0.1", port => $port ); my $filter = HTTP::Proxy::HeaderFilter::simple->new( sub { $_[1]->header( $header_key => $header_value); } ); $proxy->push_filter( request => $filter ); $proxy->start;
I.e. in the current example, the name of the header entry comes out as "sm-user" instead of "SM_USER". What am I doing wrong?

Update: Thank you guys, using the flag $HTTP::Headers::TRANSLATE_UNDERSCORE solved the issue!


In reply to Underscores changed to hyphens by HTTP::Proxy header filter by jds17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.