Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number


by marcelv (Initiate)
on Nov 26, 2020 at 15:32 UTC ( #11124271=perlquestion: print w/replies, xml ) Need Help??

marcelv has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I currently have quite some scripts running on Perl 5.24 on a Microsoft Windows Server running IIS 10.0. On this server I use a certificate to for HTTPS connections. The scripts are all using the module to do CGI. As I do use Non-Parsed Headers (NPH), all my scripts start with the prefix "nph-" and have the following line to import the CGI module:
use CGI qw/:standard -nph/;

Now when a browser requests one of my scripts, these scripts are executed twice. I have made a Wireshark trace and I see the following happening:

  1. The browser does the TLS handshake
  2. The browser does a HTTP2 request to the script
  3. The server responds with HTTP_1_1_REQUIRED
  4. The browser does another request, but now uses HTTP/1.1
  5. The server sends a HTTP/1.1 response with the script output

This is most evident when Firefox is used, as it does not remember it should use HTTP/1.1 for the request, where Chrome, Edge and Safari do remember.

Now when I remove the "nph-" prefix from the script name (and do not change the contents), the following happens:

  1. The browser does the TLS handshake
  2. The browser does a HTTP2 request to the script
  3. The server sends the HTTP2 response with the script output

Now I could change all my script names by removing the "nph-" prefix, but it seems that the scripts do not really do NPH anymore as the server is sending back a HTTP2 response, whereas with the "nph-" prefix the exact headers as generated by my script are received by the browser.

Now my question: is it possible to HTTP2 via CGI using the CGI module or any other module?


Replies are listed 'Best First'.
Re: Perl CGI HTTP2
by choroba (Archbishop) on Nov 26, 2020 at 16:25 UTC
    Quick googling revealed Do I have to call it nph-* which has lots of relevant information in neighbouring chapters, too.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Perl CGI HTTP2
by Anonymous Monk on Nov 27, 2020 at 02:38 UTC
    CGI is a text-based protocol that closely mimics HTTP/1.1 on the wire. HTTP/2 is a binary protocol designed to multiplex multiple transfers at the same time. I'm afraid that teaching to speak HTTP/2 is out of question. Actually, the CGI RFC defines the NPH output as an HTTP/1.0 or HTTP/1.1 response message, so unless there are servers that set SERVER_PROTOCOL=HTTP/2.0, no CGI script will speak HTTP/2, Perl or otherwise.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11124271]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-01-25 01:51 GMT
Find Nodes?
    Voting Booth?