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 Arturo 'Buanzo' Busleiman <bu...@buanzo.com.ar> on 2009/03/16 18:07:37 UTC

Make HTTP Request

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi! From within my module, I'd like to make an HTTP request from another HTTP server, get something
from it, and use the returned information. What's the best way to do this?

Thanks!

- --
Arturo "Buanzo" Busleiman / Arturo Busleiman @ 4:900/107
Independent Linux and Security Consultant - SANS - OISSG - OWASP
http://www.buanzo.com.ar/pro/eng.html
Mailing List Archives at http://archiver.mailfighter.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREKAAYFAkm+h1kACgkQAlpOsGhXcE0mowCeOpf2ADA9jt5/jv7KEYC+J9jL
FeoAnR3uuu2A2/IiTPrkcv0JlCvK5LKO
=99g7
-----END PGP SIGNATURE-----

Re: Make HTTP Request

Posted by Arturo 'Buanzo' Busleiman <bu...@buanzo.com.ar>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Saju Pillai wrote:
> I think OP wants to know how to make a HTTP request to *another* HTTP
> server.

Yes, that's my main concern, but I could also setup mod_proxy_http and do the subrequest locally,
which'll get forwarded by mod_proxy_http, right? - I had reviewed subrequests, and this method is
the only one I imagine as to avoid linking to libcurl.

In any case, if I end up linking to an external library (I'm already doing gpgme, see
http://wiki.buanzo.org/index.php?n=Main.Wp-enigform-authentication ), then I might as well link to
libcurl.

But I'm worried about portability. I'm not a windows programmer, so I should review libcurl and
gpgme on another platform before making any decisions.

Thanks for your comments, Saju and Sorin!

- --
Arturo "Buanzo" Busleiman / Arturo Busleiman @ 4:900/107
Independent Linux and Security Consultant - SANS - OISSG - OWASP
http://www.buanzo.com.ar/pro/eng.html
Mailing List Archives at http://archiver.mailfighter.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREKAAYFAkm+nPUACgkQAlpOsGhXcE0bcACdHNWj+1/QLic7H+4M/1upxXE8
ytwAnR9LOmbE4bVF9SO3hq7HWbHRiMUk
=4Hqy
-----END PGP SIGNATURE-----

Re: Make HTTP Request

Posted by Sorin Manolache <so...@gmail.com>.
On Mon, Mar 16, 2009 at 19:04, Saju Pillai <sa...@gmail.com> wrote:
> Sorin Manolache wrote:
>>
>> 2009/3/16 Arturo 'Buanzo' Busleiman <bu...@buanzo.com.ar>:
>>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA512
>>>
>>> Hi! From within my module, I'd like to make an HTTP request from another
>>> HTTP server, get something
>>> from it, and use the returned information. What's the best way to do
>>> this?
>>
>> You can use sub-requests. See ap_sub_req_method_uri and ap_run_sub_req.
>
> I think OP wants to know how to make a HTTP request to *another* HTTP
> server.

He can make a ap_sub_req_method_uri to an arbitrary path and then use
a rewrite rule to proxify the request:

RewriteCond %{IS_SUBREQ} true
RewriteRule  /internal_path http://another_http_server/real_path [P]

newreq = ap_sub_req_method_uri("GET", "/internal_path", r, NULL);
// here you set the filter that parses the other's server response
flt = ap_add_output_filter(my_filter, 0, newreq, newreq->connection);
// the filter will store the extracted data in the structure below
struct reponse_data response;
flt->ctx = &response;

int proxy_ret_code = ap_run_sub_req(newreq);
int server_ret_code = newreq->status;
	
// destroy the subrequest
ap_destroy_sub_req(newreq);

if (ap_is_HTTP_ERROR(proxy_ret_code) || ap_is_HTTP_ERROR(server_ret_code)) {
// error handling
}

> I have used a socket speaking a bastardized impl of HTTP - but that was a
> very specialized case.
>
> For more robust HTTP handling from within an apache module, I would use the
> libcurl api. Technically you should be able to use most HTTP client
> libraries that are callable from C.
>
> srp
> --
> http://saju.net.in
>



-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Re: Make HTTP Request

Posted by Saju Pillai <sa...@gmail.com>.
Sorin Manolache wrote:
> 2009/3/16 Arturo 'Buanzo' Busleiman <bu...@buanzo.com.ar>:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA512
>>
>> Hi! From within my module, I'd like to make an HTTP request from another HTTP server, get something
>> from it, and use the returned information. What's the best way to do this?
> 
> You can use sub-requests. See ap_sub_req_method_uri and ap_run_sub_req.

I think OP wants to know how to make a HTTP request to *another* HTTP 
server.

I have used a socket speaking a bastardized impl of HTTP - but that was 
a very specialized case.

For more robust HTTP handling from within an apache module, I would use 
the libcurl api. Technically you should be able to use most HTTP client 
libraries that are callable from C.

srp
-- 
http://saju.net.in

Re: Make HTTP Request

Posted by Sorin Manolache <so...@gmail.com>.
2009/3/16 Arturo 'Buanzo' Busleiman <bu...@buanzo.com.ar>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> Hi! From within my module, I'd like to make an HTTP request from another HTTP server, get something
> from it, and use the returned information. What's the best way to do this?

You can use sub-requests. See ap_sub_req_method_uri and ap_run_sub_req.