Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: HTTP Responses |
|
Author |
|
shug94
Joined: 27 Aug 2009 Posts: 9
|
Posted: Thu 27 Aug '09 12:11 Post subject: HTTP Responses |
|
|
Hello everyone, I am having a little trouble with something.
I have a perl script running on an Apache 2.2 HTTP Server. This script is launched by an http request which is generated by an external tool.
My script then generates an HTML response and returns it to the calling tool.
The problem I am having is that I don't seem to be able to set all the fields of the HTTP Response. Whatever I print out to standard output basically becomes the http response. However I was getting the error: "malformed header from script. Bad header=HTTP/1.1 202 Accepted" when I tried to start creating my http response at the status line. Everything works when I start creating my http response at the entity headers.
This is OK, because I still get the content body and a lot of the header information that I need.
However it is not great, because I need to set values in the Status Line, General Headers and Response Headers.
Does Apache 2.2 (or maybe Perl) handle this for me? And how can I turn it off so that I can specify this myself?
I assume it is some kind of configuration tweak that I just don't know about.
Cheers and thanks in advance,
Cameron |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
|
Back to top |
|
shug94
Joined: 27 Aug 2009 Posts: 9
|
Posted: Fri 28 Aug '09 3:29 Post subject: |
|
|
From what I have read of this mod_asis, it appears to let me send a static file as a response to an http request for that file.
I am developing a simple test server app which will receive an http request, which could contain various pieces of proprietary information. This http request is generated by the code that we are trying to test. Depending on the proprietary information, I must return an http response, which will contain information generated from that proprietary information.
In order to have my test server implement the interface that is expected by the code to be tested, it needs to return different status lines than just "200: OK". It also needs to set certain values in the General-Header.
Is it possible to dynamically generate these parts of an http response as part of a perl cgi script?
If mod_asis is the answer, then maybe I just haven't read enough about it yet, and I would love to be educated. Otherwise, what ideas do you guys have? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 28 Aug '09 4:18 Post subject: |
|
|
I missed the .asis bit on that module.
shug94 wrote: | Is it possible to dynamically generate these parts of an http response as part of a perl cgi script? |
print "Content-type: text/html\n"; # <-- note only one \n at the end
print "Status: 999 OK\n";
print "Server: MyServer 123\n";
print "Set-Cookie: cookie_name=cookie_value\n";
print "\n"; # <- extra \n after your last header is printed
print "Hello World\n";
Using Live Headers in Firefox we see
HTTP/1.x 999 OK
Date: Fri, 28 Aug 2009 03:13:26 GMT
Set-Cookie: cookie_name=cookie_value;
Server: Apache
Apache seems to force it's Server: header on us |
|
Back to top |
|
shug94
Joined: 27 Aug 2009 Posts: 9
|
Posted: Fri 28 Aug '09 8:03 Post subject: |
|
|
Excellent! Thankyou tons.
I just assumed that I needed to print it out in the order that they occur in the HTTP Response.
Little did I realise that Apache would take my header info and re-order it as much as it likes. Apparently it really cares about that content-type being first.
Cheers. |
|
Back to top |
|
|
|
|
|
|