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

HTTP and CGI

by hotshot (Prior)
on Jul 01, 2003 at 16:28 UTC ( [id://270528]=perlquestion: print w/replies, xml ) Need Help??

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

Hi guys!

Currently the protocol between the explorer and the apache server is transparent to perl, if the explorer sends requests in HTTPS, the apache will return in HTTPS.
THe question is, can I control the protocol from the CGI, for example if the explorer sends request in HTTPS, can I somehow return my answer in HTTP?

Thanks

Hotshot

Replies are listed 'Best First'.
Re: HTTP and CGI
by Tomte (Priest) on Jul 01, 2003 at 16:38 UTC

    Since http and https are handled by different virtual-hosts on apache (due to the fact, that they listen to different ports (normaly 80 for http and 443 for https)), you have to issue a redirect to the client to accomplish this. Of course the client must be able to understand http/1.x 30x status responses and the Location header.

    A common solution is to let apache do the redirecting via mod_rewrite for certain urls.

    # the ssl host <VirtualHost aaa.bbb.ccc.ddd:443> [...]# ServerName etc. RewriteEngine on RewriteRule ^/cgi-bin/prog.pl(\?.*)$ http://my.server/cgi-bin/prog +.pl$1 </VirtualHost>

    If you want to do the redirecting from the cgi and are using CGI.pm, read up on CGI::redirect()

    Edit:fixed the redirect-target protocol.

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: HTTP and CGI
by sauoq (Abbot) on Jul 01, 2003 at 17:07 UTC
    THe question is, can I control the protocol from the CGI, for example if the explorer sends request in HTTPS, can I somehow return my answer in HTTP?

    You can't. The "protocol" is an agreement between the client and the server about how they will communicate. If the browser makes an HTTPS request, you can bet it's expecting an HTTPS response. An HTTP response won't be a valid HTTPS response.

    Tomte's suggestion to use a redirect might help you but it doesn't really answer the question. The redirect response will be HTTPS, not HTTP. The redirect itself is a suggestion to the browser to make another request to a non-secured server.

    I don't think it would be advisable to downgrade a response to a secure request anyway. What are you really trying to solve?

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-23 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found