Re: [Module Dev] Sending http request

2008-01-22 Thread Joe Lewis

karim Bendadda wrote:

First I'd like to thank you very much Joe for help...

I have a begineer question:

*3) allow apache to handle the rest of the request*. Is that mean return
1 because when I tried this I had an error...and when I tried return OK
I had nothing...
  


(I don't remember if I responded, so I am responding [again if I already 
did]).


Check your http proxy settings.  You need to have it configured.  Check 
your apache error_log for errors.


Joe


that's my code:

*static int my_module_handler (request_rec *r) {
 char *url = apr_pstrdup(r-pool,http:\\10.12.23.5\irj\test);
r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
return 1;
}

static void **my_module**_hooks(apr_pool_t *pool){
ap_hook_handler(**my_module**_handler, NULL, NULL, APR_HOOK_FIRST);
   }

module AP_MODULE_DECLARE_DATA **my_module**_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
auth_chorus_config,
NULL,
**my_module**_cmds,
**my_module**_hooks
};*

Thanks


On Jan 17, 2008 4:01 PM, Joe Lewis  [EMAIL PROTECTED] wrote:

  

karim Bendadda wrote:


Hi All;

I tried this

*request_rec *subr = ap_sub_req_lookup_uri(url, r, NULL);
apr_table_set( subr-headers_out, Location, url );
ap_log_rerror( APLOG_MARK, APLOG_ERR, 0,r, sub request status:
%i,subr-status );
ap_run_sub_req(subr);*

I have the following error:

*[Thu Jan 17 07:11:25 2008] [error] [client 10.75.197.168 ] File does
  

not


exist: /usr/local/apache2/htdocs/my_module*

I think because the external server is not on the same site..I read the
paragraph 6.3 Diverting a Request: The internal redirect ...I think
  

there is


no external redirect for http requests...
Any suggestion please??

  

That error and assumption are correct.  As Ray stated, the
ap_sub_req_lookup_uri only works if the URI is on the local server's
apache.  (It is a URI vs. URL concept - the URI does not include the
http://servername piece of the URL.)

Instead, try a simple :

r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
return 1;

(this example was stolen from mod_rewrite, which was the only core
module that I was aware of that included a send to proxy command).
Just set the URL to what the client would have been grabbing if it was
redirected to the right page.  For example, if the client is trying to
get the page http://corvette.sharktooth.org/status.html , the resulting
line would be :

url = apr_pstrdup(r-pool,http://corvette.sharktooth.org/status.html;);
r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
return 1;

(this could also be shortened - what the three lines do are 1) get/set
the URL, which should be set in your case already, 2) preface the URL
with proxy:, which is an indicator to proxy the request elsewhere, and
3) allow apache to handle the rest of the request).

Try it and let us know if that works for you.

Joe
--
Joseph Lewis http://sharktooth.org/ 
Divide the fire, and you will sooner put it out. - Publius Syrus






  



--
Joseph Lewis http://sharktooth.org/
Divide the fire, and you will sooner put it out. - Publius Syrus


Re: [Module Dev] Sending http request

2008-01-17 Thread karim Bendadda
First I'd like to thank you very much Joe for help...

I have a begineer question:

*3) allow apache to handle the rest of the request*. Is that mean return
1 because when I tried this I had an error...and when I tried return OK
I had nothing...

that's my code:

*static int my_module_handler (request_rec *r) {
 char *url = apr_pstrdup(r-pool,http:\\10.12.23.5\irj\test);
r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
return 1;
}

static void **my_module**_hooks(apr_pool_t *pool){
ap_hook_handler(**my_module**_handler, NULL, NULL, APR_HOOK_FIRST);
   }

module AP_MODULE_DECLARE_DATA **my_module**_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
auth_chorus_config,
NULL,
**my_module**_cmds,
**my_module**_hooks
};*

Thanks


On Jan 17, 2008 4:01 PM, Joe Lewis  [EMAIL PROTECTED] wrote:

 karim Bendadda wrote:
  Hi All;
 
  I tried this
 
  *request_rec *subr = ap_sub_req_lookup_uri(url, r, NULL);
  apr_table_set( subr-headers_out, Location, url );
  ap_log_rerror( APLOG_MARK, APLOG_ERR, 0,r, sub request status:
  %i,subr-status );
  ap_run_sub_req(subr);*
 
  I have the following error:
 
  *[Thu Jan 17 07:11:25 2008] [error] [client 10.75.197.168 ] File does
 not
  exist: /usr/local/apache2/htdocs/my_module*
 
  I think because the external server is not on the same site..I read the
  paragraph 6.3 Diverting a Request: The internal redirect ...I think
 there is
  no external redirect for http requests...
  Any suggestion please??
 

 That error and assumption are correct.  As Ray stated, the
 ap_sub_req_lookup_uri only works if the URI is on the local server's
 apache.  (It is a URI vs. URL concept - the URI does not include the
 http://servername piece of the URL.)

 Instead, try a simple :

 r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
 return 1;

 (this example was stolen from mod_rewrite, which was the only core
 module that I was aware of that included a send to proxy command).
 Just set the URL to what the client would have been grabbing if it was
 redirected to the right page.  For example, if the client is trying to
 get the page http://corvette.sharktooth.org/status.html , the resulting
 line would be :

 url = apr_pstrdup(r-pool,http://corvette.sharktooth.org/status.html;);
 r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
 return 1;

 (this could also be shortened - what the three lines do are 1) get/set
 the URL, which should be set in your case already, 2) preface the URL
 with proxy:, which is an indicator to proxy the request elsewhere, and
 3) allow apache to handle the rest of the request).

 Try it and let us know if that works for you.

 Joe
 --
 Joseph Lewis http://sharktooth.org/ 
 Divide the fire, and you will sooner put it out. - Publius Syrus




-- 
Karim


Re: [Module Dev] Sending http request

2008-01-17 Thread karim Bendadda
On Jan 17, 2008 7:30 PM, karim Bendadda [EMAIL PROTECTED] wrote:

 First I'd like to thank you very much Joe for help...

 I have a begineer question:

 *3) allow apache to handle the rest of the request*. Is that mean return
 1 because when I tried this I had an error...and when I tried return OK
 I had nothing...

 that's my code:

 *static int my_module_handler (request_rec *r) {
  char *url = apr_pstrdup(r-pool,http:\\10.12.23.5\irj\test);
 r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
 return 1;
 }

 static void **my_module**_hooks(apr_pool_t *pool){
 ap_hook_handler(**my_module**_handler, NULL, NULL, APR_HOOK_FIRST);
}

 module AP_MODULE_DECLARE_DATA **my_module**_module = {
 STANDARD20_MODULE_STUFF,
 NULL,
 NULL,
**my_module**_config,
 NULL,
 **my_module**_cmds,
 **my_module**_hooks
 };*

 Thanks



 On Jan 17, 2008 4:01 PM, Joe Lewis  [EMAIL PROTECTED] wrote:

  karim Bendadda wrote:
   Hi All;
  
   I tried this
  
   *request_rec *subr = ap_sub_req_lookup_uri(url, r, NULL);
   apr_table_set( subr-headers_out, Location, url );
   ap_log_rerror( APLOG_MARK, APLOG_ERR, 0,r, sub request status:
   %i,subr-status );
   ap_run_sub_req(subr);*
  
   I have the following error:
  
   *[Thu Jan 17 07:11:25 2008] [error] [client 10.75.197.168 ] File does
  not
   exist: /usr/local/apache2/htdocs/my_module*
  
   I think because the external server is not on the same site..I read
  the
   paragraph 6.3 Diverting a Request: The internal redirect ...I think
  there is
   no external redirect for http requests...
   Any suggestion please??
  
 
  That error and assumption are correct.  As Ray stated, the
  ap_sub_req_lookup_uri only works if the URI is on the local server's
  apache.  (It is a URI vs. URL concept - the URI does not include the
  http://servername piece of the URL.)
 
  Instead, try a simple :
 
  r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
  return 1;
 
  (this example was stolen from mod_rewrite, which was the only core
  module that I was aware of that included a send to proxy command).
  Just set the URL to what the client would have been grabbing if it was
  redirected to the right page.  For example, if the client is trying to
  get the page http://corvette.sharktooth.org/status.html , the resulting
  line would be :
 
  url = apr_pstrdup(r-pool,http://corvette.sharktooth.org/status.html;);
  r-filename = apr_pstrcat(r-pool, proxy:, url, NULL);
  return 1;
 
  (this could also be shortened - what the three lines do are 1) get/set
  the URL, which should be set in your case already, 2) preface the URL
  with proxy:, which is an indicator to proxy the request elsewhere, and
 
  3) allow apache to handle the rest of the request).
 
  Try it and let us know if that works for you.
 
  Joe
  --
  Joseph Lewis http://sharktooth.org/ 
  Divide the fire, and you will sooner put it out. - Publius Syrus
 



 --
 Karim




-- 
Karim


Re: [Module Dev] Sending http request

2008-01-16 Thread karim Bendadda
Thank you for replying. I will see your link and reply to the mailing
list..perhaps this will help .

On Jan 16, 2008 3:42 PM, Eric Covener [EMAIL PROTECTED] wrote:

 On Jan 16, 2008 9:36 AM, karim Bendadda [EMAIL PROTECTED] wrote:
  Hi Everybody,
 
   Have you any idea of an apr function wish *sends an HTTP request to
 an
  url*?  I have a request request_rec and I need to send it to an http url
 :
  http:\\url.com. I'd like something like :
 *send_request(request_rec,url); *
 
  P.S: On my last mail (Request External Redirection) I asked you to help
 me
  for a redirection but I think that I need to send a new request! Sorry
 for
  the inconvenience
 

 nothing that simple probably, but mod_serf in trunk might be of interest:


 http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_serf.c?view=co



 --
 Eric Covener
 [EMAIL PROTECTED]




-- 
Karim


Re: [Module Dev] Sending http request

2008-01-16 Thread Ray Morris
  If the URL is on the same site, you can
use a subrequest.  Below is an example of
doing a subrequest. ap_run_sub_req only needs
to be run if you need the body of the response.
The headers can be accessed after calling
ap_sub_req_lookup_uri.  Authentication is
skipped for subrequests by default, so if you
need to run autentication call ap_get_basic_auth_pw
as below.  The copying of the authentication
and host headers probably isn't needed, but 
was something I put in before discovering the
need to call ap_get_basic_auth_pw.  I'm no 
expert - I only know what I read in Nick's
fabulous Apache modules book. :) 

subr = ap_sub_req_lookup_uri(r-uri, r, NULL);
apr_table_set( subr-headers_in, Authorization,
apr_table_get(r-headers_in, Authorization) );
apr_table_set( subr-headers_in, Host, apr_table_get(r-headers_in,
Host) );
ap_get_basic_auth_pw(subr, sent_pw);
ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, sub request status: %i,
subr-status );
ap_run_sub_req(subr);

--
Ray B. Morris
[EMAIL PROTECTED]

Strongbox - The next generation in site security:
http://www.bettercgi.com/strongbox/

Throttlebox - Intelligent Bandwidth Control
http://www.bettercgi.com/throttlebox/

Strongbox / Throttlebox affiliate program:
http://www.bettercgi.com/affiliates/user/register.php




On 01/16/2008 04:09:52 PM, karim Bendadda wrote:
 Thank you for replying. I will see your link and reply to the mailing
 list..perhaps this will help .
 
 On Jan 16, 2008 3:42 PM, Eric Covener [EMAIL PROTECTED] wrote:
 
  On Jan 16, 2008 9:36 AM, karim Bendadda [EMAIL PROTECTED] wrote:
   Hi Everybody,
  
Have you any idea of an apr function wish *sends an HTTP
 request to
  an
   url*?  I have a request request_rec and I need to send it to an
 http url
  :
   http:\\url.com. I'd like something like :
  *send_request(request_rec,url); *
  
   P.S: On my last mail (Request External Redirection) I asked you 
 to
 help
  me
   for a redirection but I think that I need to send a new request!
 Sorry
  for
   the inconvenience
  
 
  nothing that simple probably, but mod_serf in trunk might be of
 interest:
 
 
  
 http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_serf.c?view=co
 
 
 
  --
  Eric Covener
  [EMAIL PROTECTED]
 
 
 
 
 --
 Karim