Solved

Set keep-alive connection

Posted on 2006-07-22
11
877 Views
Last Modified: 2012-06-27
How can Set keep-alive connection in perl script.
Currently this script reply with following headers:

HTTP/1.1 200 OK
Date: Sat, 22 Jul 2006 20:32:26 GMT
Server: Apache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

If I try to return header like
print "Content-Type: text/html\nConnection: Keep-Alive\nKeep-Alive: timeout=300, max=5\n\n";


it change headers to
HTTP/1.1 200 OK
Date: Sat, 22 Jul 2006 20:32:26 GMT
Server: Apache
Connection: Keep-Alive, close
Keep-Alive: timeout=300, max=5
Transfer-Encoding: chunked
Content-Type: text/html
0
Comment
Question by:serg111
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17163742
print "keep-alive:42\n";
0
 
LVL 2

Author Comment

by:serg111
ID: 17164371
It does not help - still "Connection: close"
it change reply headers to

HTTP/1.1 200 OK
Date: Sun, 23 Jul 2006 22:03:08 GMT
Server: Apache
keep-alive: 42
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17164410
print "Connection:keep-alive\r\nkeep-alive:42\r\n";

> Connection: Keep-Alive, close
if you realy print the headers as you posted in your question, then the server added your headers to its own ones, in that case you need to configure your server for NPH - none-parsing  headers (means that the headers of the CGI are used)
0
 
LVL 2

Author Comment

by:serg111
ID: 17164602
Yes, it looks like server added own headers.
I dont have access to server configuration.
Can enable NPH inside script?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17164950
use CGI;
my $q = new CGI;

print $query->header(-type=>'text/htmlf',
                       -nph=>1,
                       -status=>'402 Payment required',
                       -Keep-Alive=>'42');
                  
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 2

Author Comment

by:serg111
ID: 17165136
It generates 500 Internal Server Error
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165161
I had a slight typo.  Change to

use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $q = new CGI;

print $query->header(-type=>'text/html',
                    -nph=>1,
                    -status=>'402 Payment required',
                    -Keep-Alive=>'42');
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165165
Sorry, still a typo above, $query should be $q, ie:

I had a slight typo.  Change to

use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $q = new CGI;

print $q->header(-type=>'text/html',
               -nph=>1,
               -status=>'402 Payment required',
               -Keep-Alive=>'42');
0
 
LVL 17

Accepted Solution

by:
mjcoyne earned 125 total points
ID: 17165180
There are two other ways to put CGI.pm into NPH mode.

1. With the use statement:
      use CGI qw(:standard -nph)
     

2. By calling the nph() method with a non-zero parameter at any point after using CGI.pm in your program:
      CGI->nph(1)

Also, according to Lincoln Stein (CGI.pm's autour; see http://stein.cshl.org/WWW/CGI/#nph) "IIS and many Unix servers look at the beginning of the script's name for the prefix "nph-"."  Try changing your script name from 'myscript.pl' to 'nph-myscript.pl'?

What server are you using?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17165246
Also note that modern versions of CGI.pm try to automatically detect when to use NPH mode, but obviously it's not foolproof.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17165638
keep in mind, that NPH is a configuration of the web server, hence the suggested methods must not work if the web server is configured to add its own headers and (mainly) discard thos from its applications
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now