… | |
… | |
649 | $hdr{"user-agent"} = $USERAGENT unless exists $hdr{"user-agent"}; |
649 | $hdr{"user-agent"} = $USERAGENT unless exists $hdr{"user-agent"}; |
650 | |
650 | |
651 | $hdr{"content-length"} = length $arg{body} |
651 | $hdr{"content-length"} = length $arg{body} |
652 | if length $arg{body} || $method ne "GET"; |
652 | if length $arg{body} || $method ne "GET"; |
653 | |
653 | |
|
|
654 | my $idempotent = $method =~ /^(?:GET|HEAD|PUT|DELETE|OPTIONS|TRACE)$/; |
|
|
655 | |
|
|
656 | # default value for keepalive is true iff the request is for an idempotent method |
|
|
657 | my $keepalive = exists $arg{keepalive} |
|
|
658 | ? $arg{keepalive}*1 |
|
|
659 | : $idempotent ? $PERSISTENT_TIMEOUT : 0; |
|
|
660 | |
654 | $hdr{connection} = "close Te"; #1.1 |
661 | $hdr{connection} = ($keepalive ? "" : "close ") . "Te"; #1.1 |
655 | $hdr{te} = "trailers" unless exists $hdr{te}; #1.1 |
662 | $hdr{te} = "trailers" unless exists $hdr{te}; #1.1 |
656 | |
663 | |
657 | my %state = (connect_guard => 1); |
664 | my %state = (connect_guard => 1); |
658 | |
665 | |
659 | my $ae_error = 595; # connecting |
666 | my $ae_error = 595; # connecting |
… | |
… | |
673 | ); |
680 | ); |
674 | |
681 | |
675 | # return if error occured during push_write() |
682 | # return if error occured during push_write() |
676 | return unless %state; |
683 | return unless %state; |
677 | |
684 | |
678 | %hdr = (); # reduce memory usage, save a kitten, also make it possible to re-use |
685 | # reduce memory usage, save a kitten, also re-use it for the response headers. |
|
|
686 | %hdr = (); |
679 | |
687 | |
680 | # status line and headers |
688 | # status line and headers |
681 | $state{read_response} = sub { |
689 | $state{read_response} = sub { |
682 | for ("$_[1]") { |
690 | for ("$_[1]") { |
683 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |
691 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |