I've been experimenting trying to get the time down for some HTTP code which was using LWP. HTTP::Lite was faster then HTTP::GHTTP was faster again and WWW::Curl seemed to be the fastest. However when posting I seem to get a mysterious persistent header string even though I've cleared it. Here is example code:

use strict; use warnings; use WWW::Curl::Easy; use WWW::Curl::Form; use Encode; my $hdr; my $curl = WWW::Curl::Easy->new(); $curl->setopt(CURLOPT_NOPROGRESS, 1); # shut off the built-in progress + meter $curl->setopt(CURLOPT_HEADER, 0); # don't include hdr in body $curl->setopt(CURLOPT_ENCODING, 'gzip'); $curl->setopt(CURLOPT_PROXY, ''); # no proxy open my $fh, ">", \$hdr; $curl->setopt(CURLOPT_WRITEHEADER, $fh); $curl->setopt(CURLOPT_URL, 'http://xxx.yyy.zzz:82/vx'); post(); print "FIRST HEADER $hdr\n\n"; $hdr = ''; sleep 2; post(); print "SECOND HEADER $hdr\n"; sub post { my $form = WWW::Curl::Form->new; $curl->setopt(CURLOPT_HTTPHEADER, ['Expect:','']); $form->formadd('method', 'login'); $form->formadd('username', 'xxx'); $form->formadd('password', 'xxx'); $curl->setopt(CURLOPT_HTTPPOST, $form); my $response_body; $curl->setopt(CURLOPT_WRITEDATA,\$response_body); my $retcode = $curl->perform; if ($retcode != 0) { die "post_request failed (", $retcode, " - ", $curl->errbuf, ")"; } my $decoded_content = decode ('utf-8', $response_body); }

which outputs

FIRST HEADER HTTP/1.1 200 OK Server: nginx/1.0.4 Date: Tue, 28 Jun 2011 17:57:39 GMT Content-Type: application/json; charset=UTF-8 Connection: keep-alive Set-Cookie: XXX=A6C8DD1FCAEFF6A4E040007F010036E6%3Abcffbfc621258ed7c1f +4b8fba d5e515230912a769433656c984bad7a0ceb73ec; path=/; expires=Wed, 29-Jun-2 +011 17:57: 39 GMT Content-Length: 68 SECOND HEADER HTTP/1.1 200 OK Server: nginx/1.0.4 Date: Tue, 28 Jun 2011 17:57:39 GMT Content-Type: application/json; charset=UTF-8 Connection: keep-alive Set-Cookie: XXX=A6C8DD1FCAEFF6A4E040007F010036E6%3Abcffbfc621258ed7c1f +4b8fba d5e515230912a769433656c984bad7a0ceb73ec; path=/; expires=Wed, 29-Jun-2 +011 17:57: 39 GMT Content-Length: 68 HTTP/1.1 200 OK Server: nginx/1.0.4 Date: Tue, 28 Jun 2011 17:57:41 GMT Content-Type: application/json; charset=UTF-8 Connection: keep-alive Set-Cookie: XXX=A6C8AF9C5885B010E040007F010033A2%3A88dd9574a4b678c1e55 +e0fd63 ec1c2fbebc77c7cfd456473df25dc22db26ab90; path=/; expires=Wed, 29-Jun-2 +011 17:57: 41 GMT Content-Length: 68

even though $hdr is cleared between post calls. Notice the data in $hdr in the second case contains the identical data from the first post - see the times. The more times you post the longer $hdr gets like it has stored every header result ever made. I'm quite prepared to find I've done something wrong but I find this strange. Any ideas?

Sorry I cannot provide a URL for the exact service but it is not visible on the net. It is basically a starman service which allows you to login to an API.


In reply to WWW::Curl mysterious header values persisting by mje

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.