Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Perl CGI HTTP2

by marcelv (Initiate)
on Nov 26, 2020 at 20:32 UTC ( [id://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 CGI.pm 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?

Marcel

Replies are listed 'Best First'.
Re: Perl CGI HTTP2
by choroba (Cardinal) on Nov 26, 2020 at 21: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 07: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 CGI.pm 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found