You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by David Wortham <dj...@gmail.com> on 2007/03/07 20:28:48 UTC
'POST SubRequest via mod_proxy' Question
Hello again developers,
I don't fully expect anyone to be able to answer this question. At this
point, I am just looking for ideas to try.
I am still trying to get my module to make a POST request to an external
server (I am using a subrequest that bounces off of mod_proxy to the
external server). I have successfully created a subrequest using a "POST"
method, but:
(1) I can't seem to get the content of the POST (the post variables) written
to the subrequest body; I have tried a 'ap_rprintf(...)', but it appears
that the contents of this write becomes the beginning of the response
content
(2) Is the content of a subrequest expected to output directly to the
(super/parent)request?
int status code
if(is_request_a_honeypot_token(r) && string_matches(r->method, "GET"))
{
int status_code = OK;
request_rec* subr = NULL;
char newurl[2048];
// apr_snprintf(newurl, sizeof(newurl), "proxy:%s://%s:%d/%s",
"http", "192.168.3.104", 11000, "cgi/serve.php");
apr_snprintf(newurl, sizeof(newurl), "proxy:%s://%s:%d/%s", "http",
"192.168.3.104", 18000, "raw.html");
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Handling Honeypot
Request");
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: New POST Request
URI: %s", newurl);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: POST Request
Parameters: %s", newparams);
#endif
if (ap_find_linked_module("mod_proxy.c") == NULL)
{
status = HTTP_INTERNAL_SERVER_ERROR;
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Access denied with
code 500%s "
"(Internal Error: proxy action to %s requested but
mod_proxy not found).",
newurl);
return status;
}
else
{
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: mod_proxy module
found successfully");
#endif
// Make a subrequest to mod_proxy, POSTing to the Honeypot
server and passing the resulting content as the content of the SuperRequest
subr = (request_rec*)ap_sub_req_method_uri("POST", "*", r,
NULL); // this MUST succeed!
subr->assbackwards = 0;
// build POST headers
char postparams[8192];
apr_snprintf(postparams, sizeof(postparams),
"k1=v1&k2=v2&k3=v3");
ap_set_content_type(subr, "application/x-www-form-urlencoded");
apr_table_set(subr->headers_in, "Content-Length",
strlen(postparams));
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "query constructed: %s
(%s)", newurl, postparams);
ap_rprintf(subr, "%s", postparams);
subr->filename = apr_pstrdup(r->pool, newurl);
subr->proxyreq = PROXYREQ_REVERSE;
subr->handler = "proxy-server";
status_code = ap_run_sub_req(subr);
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
status code(%d)", status_code);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
hostname - \"%s\"", subr->hostname);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
method - \"%s\"", subr->method);
#endif
if (status_code == 200)
{
// write from the subrequest results to the SuperRequest
ap_set_content_type(r, "text/html");
int bytes_sent = ap_rprintf(r, "<html>\n\t<head>\n<title>MY
FIRST HONEYPOT</title>\n\t</head>\n\t<body>\n\t\t<h1>My First
Honeypot</h1>\n\t</body>\n</html>");
}
ap_destroy_sub_req(subr);
// done processing content
status = OK;
}
}
Re: 'POST SubRequest via mod_proxy' Question
Posted by Stuart Children <st...@terminus.co.uk>.
Hi
David Wortham wrote:
> (2) I am using the above subrequest to bounce a POST request off mod_proxy
> (to get the POST to an external server). I have the headers built
> correctly. Is there any way to add POST variables to the subrequest before
> it gets to mod_proxy? Perhaps by use of an input or output filter?
You can create an input filter yes (and set Content-Length appropriately).
However, you're going to have issues with POST sub-requests with more
recent Apache versions:
http://issues.apache.org/bugzilla/show_bug.cgi?id=37402
PatchAvailable there. I don't think it's clear whether Apache should
work with them (sub-requests essentially being its own "thing"), but
they used to, and it does the job for me.
HTH
--
Stuart Children
http://terminus.co.uk/
------------------------------------------------------------------
Visit Guardian Unlimited - the UK's most popular newspaper website
http://guardian.co.uk http://observer.co.uk
------------------------------------------------------------------
The Newspaper Marketing Agency
Opening Up Newspapers
http://www.nmauk.co.uk
------------------------------------------------------------------
This e-mail and all attachments are confidential and may also
be privileged. If you are not the named recipient, please notify
the sender and delete the e-mail and all attachments immediately.
Do not disclose the contents to another person. You may not use
the information for any purpose, or store, or copy, it in any way.
Guardian News & Media Limited is not liable for any computer
viruses or other material transmitted with or as part of this
e-mail. You should employ virus checking software.
Guardian News & Media Limited
A member of Guardian Media Group PLC
Registered Office
Number 1 Scott Place, Manchester M3 3GG
Registered in England Number 908396
Re: 'POST SubRequest via mod_proxy' Question
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
David Wortham wrote:
> Sorry for the last mailing list post - my email client sent the message
> prematurely.
>
> I have two questions:
> (1) Has been able to get 'ap_run_sub_req(...)' to execute a sub_request
> without dumping the results straight to the (super|parent)request's output?
> I am using the following code to create the subrequest:
If you need a truly twisted approach to what can be accomplished by
manipulating subreq's, filters and connections, please take a close
look at http://svn.apache.org/repos/asf/httpd/mod_ftp/trunk/
Re: 'POST SubRequest via mod_proxy' Question
Posted by David Wortham <dj...@gmail.com>.
Sorry for the last mailing list post - my email client sent the message
prematurely.
I have two questions:
(1) Has been able to get 'ap_run_sub_req(...)' to execute a sub_request
without dumping the results straight to the (super|parent)request's output?
I am using the following code to create the subrequest:
/* begin code excerpt */
subr = (request_rec*)ap_sub_req_method_uri("POST", "*", r, NULL);
/* end code excerpt */
I have read that passing an 'ap_filter_t*' as the last parameter would
probably do what I want, but I don't understand how I would get a reference
to a filter pointer from inside a request handler function (I could
understand it from within a filter function).
(2) I am using the above subrequest to bounce a POST request off mod_proxy
(to get the POST to an external server). I have the headers built
correctly. Is there any way to add POST variables to the subrequest before
it gets to mod_proxy? Perhaps by use of an input or output filter?
I have already searched Google Codesearch extensively for use of subrequests
like this (on modules built for 2.0.x and 2.2.x) to no avail. I know at
least one other person was trying to do the same thing two weeks ago but no
one ever responded to him.
Does anyone have any suggestions or places to look?
Thanks in advance,
David Wortham