You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "B. Burke" <bc...@mindspring.com> on 2000/09/25 14:19:04 UTC

question: using Apache for non-HTML messages

I'm using Apache/1.3.11 with mod_perl/1.22 on an AIX platform to serve
as an
application server, with persistent ties into a MySQL database.

My company is using an in-house socket API for data transfers.  The
request
messages in our API are somewhat similiar to an HTML GET request, in
that
we use tagged, delimited fields (pipe delimited instead of & delimited).

I have written a socket server gateway to act as a protocol converter,
to convert
our API's requests into HTML GET's (and also convert the HTML output
into our
API's response format).

My question is this.  Is it possible using mod_perl for me to
incorporate the protocol
conversion into Apache itself?  In other words, can I strip out the need
for HTML
headers, and rewrite the format of GET requests to comply with our
proprietary API?
I don't know if this is something that I can do through mod_perl, or if
I will have to
dig deeper into C and recompile a new server.

Any help or ideas will be mucho appreciated!

Thanks,
Brian Burke
bcburke@mindspring.com


Re: question: using Apache for non-HTML messages

Posted by David Alan Pisoni <da...@cnation.com>.
Really all you need to do is send your response back like you would any response, just without the HTML formatting.  If you wanted to be a bit more "correct", you could change the content-type of the respose so that it is not 'text/html'.  (In your case, you might just make one up like 'application/x-brians-spiffy-protocol' or whatever you think is appropriate preceded with 'x-'.)  Or, if you wanted to debug it using a web browser, you could simply use 'text/plain', and your browser will display the raw result.

It is important to note that Apache is an HTTP server, not an "HTML server".  It is capable of serving any sort of serial content.

So anyway, since it looks like you're using a registry script, you would merely start your output with :
print "Content-type: " . $my_content_type . "\n\n"; # note the 2 newlines!

and then proceed directly to your proprietary output.

Make sense?

David

At 9.21 -0400 9/25/2000, B. Burke wrote:
>Here is an example of what I'm looking to do.
>
>GET /perl/app.pl?MODE=search&CITY=Dallas&STATE=TX&ID=195302 HTTP/1.0
>Accept: text/html
>User-Agent:  MyTestClient1.0
>From:  nowhere.com
>
>I want to replace the HTML request above with something like this:
>
>|MODE=search|CITY=Dallas|STATE=TX|ID=195302|
>
>I can hard code the handler to do GET's against only one script.  The request
>format
>is VERY similiar to the arguments in a GET (all I really have to do is
>translate the pipe).
>I think for the response, all I need to do is remove the headers entirely,
>and I can format
>the script output to conform to our API (I don't need protocol headers for
>requests nor
>for responses).
>
>I've been able to basically remove the response headers by removing the
>functionality
>of ap_sen_header_field() before compiling Apache, but it would be nice to
>have a
>more eloquent solution through mod_perl.
>
>Thanks,
>Brian
>
>
>Matt Sergeant wrote:
>
>> On Mon, 25 Sep 2000, B. Burke wrote:
>>
>> >
>> > I'm using Apache/1.3.11 with mod_perl/1.22 on an AIX platform to serve
>> > as an application server, with persistent ties into a MySQL database.
>> >
>> > My company is using an in-house socket API for data transfers.  The
>> > request messages in our API are somewhat similiar to an HTML GET
>> > request, in that we use tagged, delimited fields (pipe delimited
>> > instead of & delimited).
>> >
>> > I have written a socket server gateway to act as a protocol converter,
>> > to convert our API's requests into HTML GET's (and also convert the
>> > HTML output into our API's response format).
>> >
>> > My question is this.  Is it possible using mod_perl for me to
>> > incorporate the protocol conversion into Apache itself?  In other
>> > words, can I strip out the need for HTML headers, and rewrite the
>> > format of GET requests to comply with our proprietary API? I don't
>> > know if this is something that I can do through mod_perl, or if I will
>> > have to dig deeper into C and recompile a new server.
>> >
>> > Any help or ideas will be mucho appreciated!
>>
>> I don't think you'll actually have to re-write anything. Although an
>> example of a transaction would be most helpful. All you have to do is
>> setup mod_perl to handle the connection, Apache _should_ be able to handle
>> the request if it looks enough like a GET request, and you should be able
>> to respond to it with little enough information, provided your responses
>> are also similar to HTTP responses (HTTP response code followed optionally
>> by headers then the body).
>>
>> --
>> <Matt/>
>>
>> Fastnet Software Ltd. High Performance Web Specialists
>> Providing mod_perl, XML, Sybase and Oracle solutions
>> Email for training and consultancy availability.
>> http://sergeant.org | AxKit: http://axkit.org


Re: Update: Re: PerlSendHeader Off & socket persistence (was Re:question: usingApache for non-HTML messages)

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 2 Oct 2000, B. Burke wrote:

> Why would the lack of a $r->send_http_header call cause socket persistence
> to go away?  I was under the impression that $r->send_http_header only affected
> what was sent to the client, but appearantly it affects Apache's socket handling
> as well.

because send_http_header calls set_keepalive underneath, set_keepalive
sets the flags so apache will keep the connection open.  try the patch
below and add $r->set_keepalive to your code.

> 2) how can I make apache stop printing the outbound message size on each response

what headers exactly is your client sending?  you must be somehow
triggering chunked encoding.

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.114
diff -u -r1.114 Apache.xs
--- src/modules/perl/Apache.xs	2000/09/28 19:28:33	1.114
+++ src/modules/perl/Apache.xs	2000/10/02 21:23:28
@@ -937,6 +937,10 @@
     send_http_header(r);
     mod_perl_sent_header(r, 1);
 
+void
+set_keepalive(r)
+    Apache	r
+
 #ifndef PERL_OBJECT
 
 int


Re: Update: Re: PerlSendHeader Off & socket persistence (was Re:question: usingApache for non-HTML messages)

Posted by "B. Burke" <bc...@mindspring.com>.
Why would the lack of a $r->send_http_header call cause socket persistence
to go away?  I was under the impression that $r->send_http_header only affected
what was sent to the client, but appearantly it affects Apache's socket handling
as well.

When I don't use $r->send_http_header, my sockets are dying after Apache's
response to the 1st query...dying from the apache side, not the client side.  I have
my test client hard-coded to keep the socket open and send keepalives on every
request.

Since I don't want the server to send headers, but I want socket persistence, I'm in
a bind.  I've tried tracing through the apache source and commenting out stuff I
don't need (manually removing headers, the ugly way).  However I cannot find the
code segiment that prints the outbound hexidecimal message size (which I also
want to remove), so I'm stuck for the moment.

It seems I need to know 1 of 2 things:
1) How do you keep sockets open when $r->send_http_header isn't used
2) how can I make apache stop printing the outbound message size on each response

Any help will be appreciated!

Brian

Doug MacEachern wrote:

> On Thu, 28 Sep 2000, B. Burke wrote:
>
> > Once I changed how I was printing the header from the script, the socket
> > persistence
> > worked with PerlSendHeader Off.  So I guess I solved my problem although I don't
> > really
> > know why.
>
> because CGI.pm will trigger a call to $r->send_http_header, regardless of
> PerlSendHeader settings.  whereas: "print Content-type: text/html\n\n";
> will not, unless PerlSendHeader is On.


Re: Update: Re: PerlSendHeader Off & socket persistence (was Re: question: usingApache for non-HTML messages)

Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 28 Sep 2000, B. Burke wrote:
 
> Once I changed how I was printing the header from the script, the socket
> persistence
> worked with PerlSendHeader Off.  So I guess I solved my problem although I don't
> really
> know why.

because CGI.pm will trigger a call to $r->send_http_header, regardless of
PerlSendHeader settings.  whereas: "print Content-type: text/html\n\n";
will not, unless PerlSendHeader is On.


Update: Re: PerlSendHeader Off & socket persistence (was Re: question: usingApache for non-HTML messages)

Posted by "B. Burke" <bc...@mindspring.com>.
> what is your test client?
I wrote a command line client that just sends/receives basic messages for testing.

I have been opening a socket and sending this:
GET /perl/myscript HTTP/1.1
Connection: Keep-Alive
Host: myhost.mydomain.com\n\n

It worked as expected - I was able to keep the socket open and send & receive
multiple
messages.  When I set PerlSendHeader to Off, the socket closed after the 1st query.

I finally had success with socket persistence when I tried using CGI to print the
header
by replacing this:
print "Content-type: text/html\n\n";
with this:
print header();

Once I changed how I was printing the header from the script, the socket
persistence
worked with PerlSendHeader Off.  So I guess I solved my problem although I don't
really
know why.

Brian


Doug MacEachern wrote:

> On Wed, 27 Sep 2000, B. Burke wrote:
>
> > When I set PerlSendHeader to Off in my perl.conf it doesn't send headers,
> > which
> > is good.  The bad part is that it seems to break socket persistence for some
> > reason.
> > When I have PerlSendHeader set to On, I can open a socket with my test client,
> >
> > and make multiple queries on the same socket.
>
> what is your test client?  apache will close the connection after the
> first request, unless keep-alive is maintained between client/server.


Re: PerlSendHeader Off & socket persistence (was Re: question: using Apache for non-HTML messages)

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 27 Sep 2000, B. Burke wrote:

> When I set PerlSendHeader to Off in my perl.conf it doesn't send headers,
> which
> is good.  The bad part is that it seems to break socket persistence for some
> reason.
> When I have PerlSendHeader set to On, I can open a socket with my test client,
> 
> and make multiple queries on the same socket.

what is your test client?  apache will close the connection after the
first request, unless keep-alive is maintained between client/server.


PerlSendHeader Off & socket persistence (was Re: question: using Apache for non-HTML messages)

Posted by "B. Burke" <bc...@mindspring.com>.
When I set PerlSendHeader to Off in my perl.conf it doesn't send headers,
which
is good.  The bad part is that it seems to break socket persistence for some
reason.
When I have PerlSendHeader set to On, I can open a socket with my test client,

and make multiple queries on the same socket.

Any ideas to help me keep the socket open?

Thanks,
Brian

Doug MacEachern wrote:

> On Mon, 25 Sep 2000, B. Burke wrote:
>
> > I've been able to basically remove the response headers by removing the
> > functionality
> > of ap_sen_header_field() before compiling Apache, but it would be nice to
>
> you don't have to remove anything, just don't call $r->send_http_header
> and make sure PerlSendHeader is configured to Off, then Apache will not
> send any headers.


Re: question: using Apache for non-HTML messages

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 25 Sep 2000, B. Burke wrote:
 
> I've been able to basically remove the response headers by removing the
> functionality
> of ap_sen_header_field() before compiling Apache, but it would be nice to

you don't have to remove anything, just don't call $r->send_http_header
and make sure PerlSendHeader is configured to Off, then Apache will not
send any headers.


Re: question: using Apache for non-HTML messages

Posted by "B. Burke" <bc...@mindspring.com>.
Here is an example of what I'm looking to do.

GET /perl/app.pl?MODE=search&CITY=Dallas&STATE=TX&ID=195302 HTTP/1.0
Accept: text/html
User-Agent:  MyTestClient1.0
From:  nowhere.com

I want to replace the HTML request above with something like this:

|MODE=search|CITY=Dallas|STATE=TX|ID=195302|

I can hard code the handler to do GET's against only one script.  The request
format
is VERY similiar to the arguments in a GET (all I really have to do is
translate the pipe).
I think for the response, all I need to do is remove the headers entirely,
and I can format
the script output to conform to our API (I don't need protocol headers for
requests nor
for responses).

I've been able to basically remove the response headers by removing the
functionality
of ap_sen_header_field() before compiling Apache, but it would be nice to
have a
more eloquent solution through mod_perl.

Thanks,
Brian


Matt Sergeant wrote:

> On Mon, 25 Sep 2000, B. Burke wrote:
>
> >
> > I'm using Apache/1.3.11 with mod_perl/1.22 on an AIX platform to serve
> > as an application server, with persistent ties into a MySQL database.
> >
> > My company is using an in-house socket API for data transfers.  The
> > request messages in our API are somewhat similiar to an HTML GET
> > request, in that we use tagged, delimited fields (pipe delimited
> > instead of & delimited).
> >
> > I have written a socket server gateway to act as a protocol converter,
> > to convert our API's requests into HTML GET's (and also convert the
> > HTML output into our API's response format).
> >
> > My question is this.  Is it possible using mod_perl for me to
> > incorporate the protocol conversion into Apache itself?  In other
> > words, can I strip out the need for HTML headers, and rewrite the
> > format of GET requests to comply with our proprietary API? I don't
> > know if this is something that I can do through mod_perl, or if I will
> > have to dig deeper into C and recompile a new server.
> >
> > Any help or ideas will be mucho appreciated!
>
> I don't think you'll actually have to re-write anything. Although an
> example of a transaction would be most helpful. All you have to do is
> setup mod_perl to handle the connection, Apache _should_ be able to handle
> the request if it looks enough like a GET request, and you should be able
> to respond to it with little enough information, provided your responses
> are also similar to HTTP responses (HTTP response code followed optionally
> by headers then the body).
>
> --
> <Matt/>
>
> Fastnet Software Ltd. High Performance Web Specialists
> Providing mod_perl, XML, Sybase and Oracle solutions
> Email for training and consultancy availability.
> http://sergeant.org | AxKit: http://axkit.org


Re: question: using Apache for non-HTML messages

Posted by Matt Sergeant <ma...@sergeant.org>.
On Mon, 25 Sep 2000, B. Burke wrote:

> 
> I'm using Apache/1.3.11 with mod_perl/1.22 on an AIX platform to serve
> as an application server, with persistent ties into a MySQL database.
> 
> My company is using an in-house socket API for data transfers.  The
> request messages in our API are somewhat similiar to an HTML GET
> request, in that we use tagged, delimited fields (pipe delimited
> instead of & delimited).
> 
> I have written a socket server gateway to act as a protocol converter,
> to convert our API's requests into HTML GET's (and also convert the
> HTML output into our API's response format).
> 
> My question is this.  Is it possible using mod_perl for me to
> incorporate the protocol conversion into Apache itself?  In other
> words, can I strip out the need for HTML headers, and rewrite the
> format of GET requests to comply with our proprietary API? I don't
> know if this is something that I can do through mod_perl, or if I will
> have to dig deeper into C and recompile a new server.
> 
> Any help or ideas will be mucho appreciated!

I don't think you'll actually have to re-write anything. Although an
example of a transaction would be most helpful. All you have to do is
setup mod_perl to handle the connection, Apache _should_ be able to handle
the request if it looks enough like a GET request, and you should be able
to respond to it with little enough information, provided your responses
are also similar to HTTP responses (HTTP response code followed optionally
by headers then the body).

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org