From e34e35e530c64d432ac71d8798c6b42440c7d516 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Mar 2022 07:22:41 +0000 Subject: [PATCH 1/4] h2c: fix perlcritic "Variable declared in conditional statement" perlcritic --verbose 6 h2c gives the following result: Variable declared in conditional statement at line 400, near 'my $lib="--libcurl - -x localhost:0 " if($uselibcurl);'. (Severity: 5) Fix it. --- h2c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/h2c b/h2c index c2f2731..b59b7d0 100755 --- a/h2c +++ b/h2c @@ -397,7 +397,8 @@ if($useverbose) { # This adds the -x option to prevent a curl request to actually go out to any # remote server -my $lib="--libcurl - -x localhost:0 " if($uselibcurl); +my $lib=""; +$lib="--libcurl - -x localhost:0 " if($uselibcurl); my $curlcmd = "curl ${useverbose}${usemethod}${httpver}${disabledheaders}${addedheaders}${usebody}${multipart}${requesttarget}${lib}${url}"; if($uselibcurl) { From 57bf93706b54d474bd22ba8111b8f7f838e86bce Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Mar 2022 07:33:20 +0000 Subject: [PATCH 2/4] h2c: fix perlcritic "Bareword file handle" perlcritic --verbose 6 h2c gives the following result: Bareword file handle opened at line 406, near 'open(C, "$curlcmd 2>/dev/null|");'. (Severity: 5) Fix it. --- h2c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/h2c b/h2c index b59b7d0..2a34c2b 100755 --- a/h2c +++ b/h2c @@ -403,14 +403,14 @@ my $curlcmd = "curl ${useverbose}${usemethod}${httpver}${disabledheaders}${added if($uselibcurl) { # this actually runs curl which will fail to connect so ignore errors - open(C, "$curlcmd 2>/dev/null|"); - while() { + open(my $c, "$curlcmd 2>/dev/null|"); + while(<$c>) { # skip CURLOPT_PROXY since that's only used to avoid network if($_ !~ /CURLOPT_PROXY, /) { print $_; } } - close(C); + close($c); } else { print "$curlcmd\n"; From bfac617f304f19b7ee888942155d63a7c6c42be1 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Mar 2022 07:40:16 +0000 Subject: [PATCH 3/4] h2c: fix perlcritic 'Two-argument "open" used at' perlcritic --verbose 6 h2c gives the following result: Two-argument "open" used at line 405, near 'open(C, "$curlcmd 2>/dev/null|");'. (Severity: 5) Fix it. --- h2c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h2c b/h2c index 2a34c2b..6f40cb5 100755 --- a/h2c +++ b/h2c @@ -403,7 +403,7 @@ my $curlcmd = "curl ${useverbose}${usemethod}${httpver}${disabledheaders}${added if($uselibcurl) { # this actually runs curl which will fail to connect so ignore errors - open(my $c, "$curlcmd 2>/dev/null|"); + open(my $c,q{-|},"$curlcmd 2>/dev/null"); while(<$c>) { # skip CURLOPT_PROXY since that's only used to avoid network if($_ !~ /CURLOPT_PROXY, /) { From 544ca8804be95d03130876a666ff8b85f6eb8654 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Mar 2022 09:01:06 +0000 Subject: [PATCH 4/4] h2c: fix perlcritic "Code before strictures are enabled" perlcritic --verbose 6 h2c gives the following result: Code before strictures are enabled at line 5, near 'sub usage {'. (Severity: 5) For fix it: - Add "use strict; use warnings" - Add where necessary the "my" keyword to the lexically scoped variables. - Fix also some uninitialized variables. --- h2c | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/h2c b/h2c index 6f40cb5..6111ff6 100755 --- a/h2c +++ b/h2c @@ -1,5 +1,8 @@ #!/usr/bin/perl +use strict; +use warnings; + use MIME::Base64; sub usage { @@ -30,6 +33,9 @@ my $shellcompatible = 1; # may not been windows command prompt compat my $uselongoptions = 1; # instead of short my $uselibcurl = 0; # --libcurl my $usehttp = 0; +my $usedocs; +my $usenotes; +my $useverbose = ""; while($ARGV[0]) { if(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) { @@ -75,6 +81,15 @@ while($ARGV[0]) { my $state; # 0 is request-line, 1-headers, 2-body my $line = 1; +my $error; +my $exact; +my $http; +my $method; +my $path; +my @body; +my %exactcase; +my %header; + while() { my $l = $_; # discard CRs completely @@ -125,6 +140,16 @@ if($error) { exit; } +my $opt_data = "-d"; +my $opt_request = "-X"; +my $opt_head = "-I"; +my $opt_header = "-H"; +my $opt_user_agent = "-A"; +my $opt_cookie = "-b"; +my $opt_verbose = "-v"; +my $opt_form = "-F"; +my $opt_user = "-u"; + if($uselongoptions) { $opt_data = "--data"; $opt_request = "--request"; @@ -136,21 +161,18 @@ if($uselongoptions) { $opt_form = "--form"; $opt_user = "--user"; } -else { - $opt_data = "-d"; - $opt_request = "-X"; - $opt_head = "-I"; - $opt_header = "-H"; - $opt_user_agent = "-A"; - $opt_cookie = "-b"; - $opt_verbose = "-v"; - $opt_form = "-F"; - $opt_user = "-u"; -} my $httpver=""; my $disabledheaders=""; my $addedheaders=""; +my $do_multipart; +my $ignore_contenttype; +my $multipart=""; +my $requesttarget=""; +my $unixescaped; +my $usebody; +my @docs; +my @notes; if($header{"content-type"} =~ /^multipart\/form-data;/) { # multipart formpost, this is special @@ -169,6 +191,7 @@ if($header{"content-type"} =~ /^multipart\/form-data;/) { my %fheader; my $fstate = 0; my @fbody; + while($body[$bline]) { my $l = $body[$bline]; if(0 == $fstate) { @@ -248,6 +271,9 @@ elsif(length(join("", @body))) { $usebody= sprintf("--data-binary \"%s\" ", $esc); push @docs, manpage("--data-binary", "", "send this string as a body with POST"); } + +my $usemethod = ""; + if(uc($method) eq "HEAD") { $usemethod = "$opt_head "; push @docs, manpage("-I", $opt_head, "send a HEAD request"); @@ -377,6 +403,8 @@ foreach my $h (sort keys %header) { } } +my $url; + if($path =~ /[&?]/) { $url = sprintf "\"%s://%s%s\"", $usehttp ? "http" : "https", $header{'host'}, $path; }