You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Petr Hracek <ph...@gmail.com> on 2009/09/15 08:50:04 UTC
Data are send in reverse order
Hello *,
in my apache module (written in C) are sended data to the client side over
buckets and brigades.
Function for send these date is:
apr_status_t send_data_to_client(request_rec *r, char * data_to_send, int
length_data)
{
apr_bucket_brigade * bb =
apr_brigade_create(r->pool,r->connection->bucket_alloc);
apr_bucket * b =
apr_bucket_immortal_create(data_to_send,length_data,r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb,b);
ap_pass_brigade(r->connection->output_filters,bb);
return OK;
}
It is working but in the traces of application which receive the data from
apache module the HTTP data are in reverse order.
First are received data and then is received HTTP header. Do you know how to
switch this order to the normal state, first is sended HTTP header and
afterwards are sended data?
Before when the data are send is following code:
r->content_type = "text/plain";
bodylen = strlen(response_body);
ap_set_content_length(r, bodylen);
ap_send_http_header(r);
if (r->header_only)
{
ap_log_error(APLOG_MARK,APLOG_NOERRNO | APLOG_DEBUG, 0, r->server,
"HEADER ONLY");
return OK;
}
send_data_to_client(r,response_body, bodylen);
best regards
Petr
Re: Data are send in reverse order
Posted by Graham Leggett <mi...@sharp.fm>.
Petr Hracek wrote:
> I have found mod_nntp_like where is mention in
> ap_pass_brigade(c->output_filters,bb);
> and in smtp_core is usage the same.
Neither of these modules implement http, so don't use them as examples
of how an http module should be implemented.
> Unfortunatelly when I am using ap_pass_brigade(r->output_filter,bb);
> then it is not working. Web page is not show.
Can you post some code as an example?
> Is it neccessary to configure Apache for using brigade and buckets?
Yes.
Take a look in the httpd code for modules that implement handlers, and
use them as examples of how to write to the filter stack.
Regards,
Graham
--
Re: Data are send in reverse order
Posted by Graham Leggett <mi...@sharp.fm>.
Petr Hracek wrote:
> Sorry it was my fault.
>
> I have corrected them to r->output_filters now.
> But situation is the same. Data are send but java aplication which
> receiving data
> sended over ap_pass_brigade does not receive anything. It seems that
> between apache and java aplication are "lost" is there any posibility
> how to track if that hasa been really send via ap_pass_brigade?
One thing to check, are you sending an EOS bucket (end-of-stream) at the
end to tell everybody you're done?
I suspect what might be happening is that httpd is waiting for you to
say "I'm done", but you never send the bucket to say so, so the data
buffered in the connection is being discarded when the connection is
eventually timed out by the client.
Regards,
Graham
--
Re: Data are send in reverse order
Posted by Petr Hracek <ph...@gmail.com>.
Sorry it was my fault.
I have corrected them to r->output_filters now.
But situation is the same. Data are send but java aplication which receiving
data
sended over ap_pass_brigade does not receive anything. It seems that between
apache and java aplication are "lost" is there any posibility how to track
if that hasa been really send via ap_pass_brigade?
2009/9/16 Graham Leggett <mi...@sharp.fm>
> Petr Hracek wrote:
>
> > In my module I do not modify any data sended from server to client.
> > Unfortunatelly when I am using ap_r* then firstly are sended data and
> > then HTTP relevant code.
>
> That's because you've made the same mistake in this code that you made
> in the previous code you posted:
>
> > ap_pass_brigade(r->connection->output_filters,bb);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Regards,
> Graham
> --
>
>
Re: Data are send in reverse order
Posted by Graham Leggett <mi...@sharp.fm>.
Petr Hracek wrote:
> In my module I do not modify any data sended from server to client.
> Unfortunatelly when I am using ap_r* then firstly are sended data and
> then HTTP relevant code.
That's because you've made the same mistake in this code that you made
in the previous code you posted:
> ap_pass_brigade(r->connection->output_filters,bb);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Regards,
Graham
--
Re: Data are send in reverse order
Posted by Petr Hracek <ph...@gmail.com>.
In my module I do not modify any data sended from server to client.
Unfortunatelly when I am using ap_r* then firstly are sended data and then
HTTP relevant code.
Sample code is:
/*
* Procedure for sending data from server to client side
* Instead of ap_rvputs like functions should be used following procedure
* especially for SecMCJ issue
*/
apr_status_t send_data_to_client(request_rec *r, char * data_to_send, int
length_data)
{
//apr_status_t rv;
apr_bucket_brigade * bb =
apr_brigade_create(r->pool,r->connection->bucket_alloc);
apr_bucket * b =
apr_bucket_immortal_create(data_to_send,length_data,r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb,b);
ap_pass_brigade(r->connection->output_filters,bb);
//apr_bucket_destroy(b);
//apr_brigade_destroy(bb);
return OK;
}
/*
* <Location /USSW/secmcj>
* SetHandler ussw-secmcj
* allow from all
* Satisfy any
* </Location>
*/
int udsc_secmcj_handler(request_rec *r)
{
secmcj_body = apr_pstrcat(r->pool,
"sessionID=",
apr_psprintf(r->pool, "%lu", pSession->us.udsc_sessionid),
"&requestNr=", pSession->session_id,
*request_body == '&' ? "" : "&",
request_body,
NULL);
/* now post the data to usmw /secmcj */
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r->server,
"secmcj body: %s",secmcj_body);
/* now return the response to the client (secmcj class) */
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r->server,
"secmcj body receive: %s",response_body);
r->content_type = "text/plain";
/* added because of JRE 1.4 SE SSL problem */
bodylen = strlen(response_body);
ap_set_content_length(r, bodylen);
ap_send_http_header(r);
if (r->header_only)
{
ap_log_error(APLOG_MARK,APLOG_NOERRNO | APLOG_DEBUG, 0, r->server,
"HEADER ONLY");
return OK;
}
ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, 0, r->server,
"before any sending. Length is:%d",bodylen);
send_data_to_client(r,response_body, bodylen);
return OK;
}
best regards
Petr
Nick Kew napsal(a):
> Petr Hracek wrote:
>
>> I have found mod_nntp_like where is mention in
>> ap_pass_brigade(c->output_filters,bb);
>> and in smtp_core is usage the same.
>>
>
> Those are protocol modules. So anything-HTTP is not relevant to them.
>
> Unfortunatelly when I am using ap_pass_brigade(r->output_filter,bb);
>> then it is not working. Web page is not show.
>>
>
> Do you need to use anything more complex than the ap_r* family
> (ap_rputs, etc)? If so (and if what Graham already told you isn't
> enough) you might want my book - details at http://www.apachetutor.org/
>
>
Re: Data are send in reverse order
Posted by Nick Kew <ni...@webthing.com>.
Petr Hracek wrote:
> I have found mod_nntp_like where is mention in
> ap_pass_brigade(c->output_filters,bb);
> and in smtp_core is usage the same.
Those are protocol modules. So anything-HTTP is not relevant to them.
> Unfortunatelly when I am using ap_pass_brigade(r->output_filter,bb);
> then it is not working. Web page is not show.
Do you need to use anything more complex than the ap_r* family
(ap_rputs, etc)? If so (and if what Graham already told you isn't
enough) you might want my book - details at http://www.apachetutor.org/
--
Nick Kew
Re: Data are send in reverse order
Posted by Eric Covener <co...@gmail.com>.
On Tue, Sep 15, 2009 at 9:45 AM, Petr Hracek <ph...@gmail.com> wrote:
> I have found mod_nntp_like where is mention in
> ap_pass_brigade(c->output_filters,bb);
> and in smtp_core is usage the same.
These are both modules that provide a non-HTTP protocol over the
connection. If that doesn't match your module, you're better off using
other code as a reference.
--
Eric Covener
covener@gmail.com
Re: Data are send in reverse order
Posted by Petr Hracek <ph...@gmail.com>.
I have found mod_nntp_like where is mention in
ap_pass_brigade(c->output_filters,bb);
and in smtp_core is usage the same.
Unfortunatelly when I am using ap_pass_brigade(r->output_filter,bb);
then it is not working. Web page is not show.
Is it neccessary to configure Apache for using brigade and buckets?
regards
Petr
2009/9/15 Graham Leggett <mi...@sharp.fm>
> Petr Hracek wrote:
>
> > I do not understand of this thing.
> > Could you please tell me if I have already connection between browser
> > and apache server why I should use request_rec->output_filters instead
> > of request_rec->connection->output_filters?
> >
> > I thought that if connection is established than request_rec->connection
> > should be used, right?
>
> Unfortunately not, no.
>
> The HTTP protocol allows many requests to occur over the same
> connection, and httpd models this by having a connection filter stack,
> in which is created a per-request filter stack, one for each request.
>
> The connection filter stack knows virtually nothing about HTTP, all the
> filters that do know about HTTP - most specifically the filter that
> writes headers - are part of the request filter stack.
>
> If you write to the connection filter stack, you are bypassing all the
> HTTP filters, and what you wrote appears on the socket immediately.
> Later on in your code, something else is writing to the request filter
> stack, and this causes the headers filter to output the headers, after
> the data you've just written.
>
> Regards,
> Graham
> --
>
Re: Data are send in reverse order
Posted by Graham Leggett <mi...@sharp.fm>.
Petr Hracek wrote:
> I do not understand of this thing.
> Could you please tell me if I have already connection between browser
> and apache server why I should use request_rec->output_filters instead
> of request_rec->connection->output_filters?
>
> I thought that if connection is established than request_rec->connection
> should be used, right?
Unfortunately not, no.
The HTTP protocol allows many requests to occur over the same
connection, and httpd models this by having a connection filter stack,
in which is created a per-request filter stack, one for each request.
The connection filter stack knows virtually nothing about HTTP, all the
filters that do know about HTTP - most specifically the filter that
writes headers - are part of the request filter stack.
If you write to the connection filter stack, you are bypassing all the
HTTP filters, and what you wrote appears on the socket immediately.
Later on in your code, something else is writing to the request filter
stack, and this causes the headers filter to output the headers, after
the data you've just written.
Regards,
Graham
--
Re: Data are send in reverse order
Posted by Petr Hracek <ph...@gmail.com>.
I do not understand of this thing.
Could you please tell me if I have already connection between browser and
apache server why I should use request_rec->output_filters instead of
request_rec->connection->output_filters?
I thought that if connection is established than request_rec->connection
should be used, right?
regards
Petr
2009/9/15 Graham Leggett <mi...@sharp.fm>
> Petr Hracek wrote:
>
> > in my apache module (written in C) are sended data to the client side
> > over buckets and brigades.
> > Function for send these date is:
> > apr_status_t send_data_to_client(request_rec *r, char * data_to_send,
> > int length_data)
> > {
> > apr_bucket_brigade * bb =
> > apr_brigade_create(r->pool,r->connection->bucket_alloc);
> > apr_bucket * b =
> >
> apr_bucket_immortal_create(data_to_send,length_data,r->connection->bucket_alloc);
> > APR_BRIGADE_INSERT_TAIL(bb,b);
> > ap_pass_brigade(r->connection->output_filters,bb);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > return OK;
> > }
> >
> > It is working but in the traces of application which receive the data
> > from apache module the HTTP data are in reverse order.
>
> At a quick glance, I would blame the line highlighted above - you are
> trying to write your data directly to the connection filters, rather
> than to the request filters. By doing that, your data is sent before the
> request, not after, and so you see your data before the headers, not after.
>
> Regards,
> Graham
> --
>
Re: Data are send in reverse order
Posted by Graham Leggett <mi...@sharp.fm>.
Petr Hracek wrote:
> in my apache module (written in C) are sended data to the client side
> over buckets and brigades.
> Function for send these date is:
> apr_status_t send_data_to_client(request_rec *r, char * data_to_send,
> int length_data)
> {
> apr_bucket_brigade * bb =
> apr_brigade_create(r->pool,r->connection->bucket_alloc);
> apr_bucket * b =
> apr_bucket_immortal_create(data_to_send,length_data,r->connection->bucket_alloc);
> APR_BRIGADE_INSERT_TAIL(bb,b);
> ap_pass_brigade(r->connection->output_filters,bb);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> return OK;
> }
>
> It is working but in the traces of application which receive the data
> from apache module the HTTP data are in reverse order.
At a quick glance, I would blame the line highlighted above - you are
trying to write your data directly to the connection filters, rather
than to the request filters. By doing that, your data is sent before the
request, not after, and so you see your data before the headers, not after.
Regards,
Graham
--