Re: [Apache Module] Request External Redirection

2008-01-15 Thread karim Bendadda
I'm sorry but the redirection doesn't work (I'm so sad...).. It redirects
just a new http request but the Informations that I need on the incoming
request is not beeing requested... I think I need a mod_proxy_hook...

Thank you for your help

On Jan 14, 2008 7:40 PM, Joe Lewis [EMAIL PROTECTED] wrote:

 karim Bendadda wrote:
  I did that , I have a redirection to the new url but it seems that it's
 just
  a redirection , the HTTP request doesn't get in the new URl: there is my
  code:
 

 The only two options again are to proxy to the external server, or
 redirect the client to the external server.

 If you don't want a redirection at the web browser, you will have to
 proxy the request.  I do not know about setting up a hook into mod_proxy
 to have a request proxied - it's something I've never done, but there
 should be many people who have done it.  Anyone with any short examples?

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




-- 
Karim


Re: [Apache Module] Request External Redirection

2008-01-15 Thread karim Bendadda
It's the request header, In fact I receive an http request with a
certificate whish I can read by: *

certificate *= *apr_table_get(r-headers_in, sslClientCertificat);

*Now I want to redirect the SAME request to another  server by preserving
the request (and the certificate into it)

when I tried this:
*
apr_table_setn(r-headers_out, (const char*)Location,url);
ap_log_rerror(APLOG_MARK,APLOG_NOTICE,0,r,The certificate
%s,apr_table_get(r-headers_out, sslClientCertificat));
return  HTTP_MOVED_TEMPORARILY**;
*
I have the log: *The certificate= null;*
*
*How Can I redirect ALL the request??


Thks.


On Jan 15, 2008 2:02 PM, Eric Covener [EMAIL PROTECTED] wrote:

 On Jan 15, 2008 5:17 AM, karim Bendadda [EMAIL PROTECTED] wrote:
  I'm sorry but the redirection doesn't work (I'm so sad...).. It
 redirects
  just a new http request but the Informations that I need on the incoming
  request is not beeing requested... I think I need a mod_proxy_hook...

 What information isn't retained? Something in apache? A request header?



 --
 Eric Covener
 [EMAIL PROTECTED]




-- 
Karim


Re: [Apache Module] Request External Redirection

2008-01-15 Thread Eric Covener
On Jan 15, 2008 5:17 AM, karim Bendadda [EMAIL PROTECTED] wrote:
 I'm sorry but the redirection doesn't work (I'm so sad...).. It redirects
 just a new http request but the Informations that I need on the incoming
 request is not beeing requested... I think I need a mod_proxy_hook...

What information isn't retained? Something in apache? A request header?



-- 
Eric Covener
[EMAIL PROTECTED]


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Dr. Peter Poeml
On Mon, Jan 14, 2008 at 03:50:25PM +0100, karim Bendadda wrote:
 Thanks for your answer! But I don't understand the second way to implement
 it?? it can respond with a Location: header and a status of 302.??
 
 On 1/14/08, Joe Lewis [EMAIL PROTECTED] wrote:
 
  karim Bendadda wrote:
I'm writing a module (MyModule_mod.c) wich has an *HTTP
  request* as
   input . I want to add an information to the request (an integer) and
   redirect it to an *external *server ...Did you know any method for doing
   this?
  
  
 
  There are two paths.  The server can PROXY to the external server (e.g.
  grab the result from the external server and then relay that to the
  client) or it can respond with a Location: header and a status of 302.
  Figure out which you wanted to do, and if you struggle to implement it,
  let us know.

In your handler, you would do something like this to implement the latter:

/* set a Location: header and 302 redirect. */

/* assemble the url by appending the filename to a baseurl */
uri = apr_pstrcat(r-pool, baseurl, filename, NULL);

apr_table_setn(r-headers_out, Location, uri);

return HTTP_MOVED_TEMPORARILY;

Peter
-- 
WARNING: This bug is visible to non-employees. Please be respectful!
 
SUSE LINUX Products GmbH
Research  Development


pgpm6ZSxphXgE.pgp
Description: PGP signature


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Joe Lewis

Dr. Peter Poeml wrote:

On Mon, Jan 14, 2008 at 03:50:25PM +0100, karim Bendadda wrote:
  

Thanks for your answer! But I don't understand the second way to implement
it?? it can respond with a Location: header and a status of 302.??

On 1/14/08, Joe Lewis [EMAIL PROTECTED] wrote:


karim Bendadda wrote:
  

 I'm writing a module (MyModule_mod.c) wich has an *HTTP


request* as
  

input . I want to add an information to the request (an integer) and
redirect it to an *external *server ...Did you know any method for doing
this?




There are two paths.  The server can PROXY to the external server (e.g.
grab the result from the external server and then relay that to the
client) or it can respond with a Location: header and a status of 302.
Figure out which you wanted to do, and if you struggle to implement it,
let us know.
  


In your handler, you would do something like this to implement the latter:

/* set a Location: header and 302 redirect. */

/* assemble the url by appending the filename to a baseurl */
uri = apr_pstrcat(r-pool, baseurl, filename, NULL);

apr_table_setn(r-headers_out, Location, uri);

return HTTP_MOVED_TEMPORARILY;

Peter
  



Exactly!  What it does is forces the web client to go to the external 
server and request the resource/URI rather than the web server getting 
it for the web client.  It's a standard in the HTTP protocols that 302 
response codes work in a specific fashion.


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


Re: [Apache Module] Request External Redirection

2008-01-14 Thread karim Bendadda
Thank you for your help!

How can I call the Redirect directive into the module??, In fact in the
module I have a function that make an LDAP connection I want to do something
like that:

request_rec* my_request; //The request with new information

if(my_function(user_is_defined_in_ldap)==true)

Redirect my_request new_Url

else

Do_nothing

On 1/14/08, Dr. Peter Poeml [EMAIL PROTECTED] wrote:

 On Mon, Jan 14, 2008 at 03:50:25PM +0100, karim Bendadda wrote:
  Thanks for your answer! But I don't understand the second way to
 implement
  it?? it can respond with a Location: header and a status of 302.??
 
  On 1/14/08, Joe Lewis [EMAIL PROTECTED] wrote:
  
   karim Bendadda wrote:
 I'm writing a module (MyModule_mod.c) wich has an *HTTP
   request* as
input . I want to add an information to the request (an integer) and
redirect it to an *external *server ...Did you know any method for
 doing
this?
   
   
  
   There are two paths.  The server can PROXY to the external server (e.g
 .
   grab the result from the external server and then relay that to the
   client) or it can respond with a Location: header and a status of 302.
   Figure out which you wanted to do, and if you struggle to implement
 it,
   let us know.

 In your handler, you would do something like this to implement the latter:

 /* set a Location: header and 302 redirect. */

 /* assemble the url by appending the filename to a baseurl */
 uri = apr_pstrcat(r-pool, baseurl, filename, NULL);

 apr_table_setn(r-headers_out, Location, uri);

 return HTTP_MOVED_TEMPORARILY;

 Peter
 --
 WARNING: This bug is visible to non-employees. Please be respectful!

 SUSE LINUX Products GmbH
 Research  Development




-- 
Karim


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Joe Lewis

karim Bendadda wrote:

Thank you for your help!

How can I call the Redirect directive into the module??, In fact in the
module I have a function that make an LDAP connection I want to do something
like that:

request_rec* my_request; //The request with new information

if(my_function(user_is_defined_in_ldap)==true)

Redirect my_request new_Url

else

Do_nothing
  



Do_nothing should be return DECLINED in the handler.  Redirect 
my_request new_URL should be almost verbatim the code that the Doc 
(Peter Poeml) included.  Let me just snip down through to his example to 
make it a little more obvious.




In your handler, you would do something like this to implement the latter:

/* set a Location: header and 302 redirect. */

/* assemble the url by appending the filename to a baseurl */
uri = apr_pstrcat(r-pool, baseurl, filename, NULL);

apr_table_setn(r-headers_out, Location, uri);

return HTTP_MOVED_TEMPORARILY;



And there is the how to.  Recall, though, that this kind of thing 
shouldn't be in an input filter, but a handler.  (It may, in theory, be 
workable in a filter, but a filter is supposed to alter input not handle 
requests, and a handler is supposed to give the response of the 302 or 
data or decline to handle it.)


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


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Joe Lewis

karim Bendadda wrote:

I did that , I have a redirection to the new url but it seems that it's just
a redirection , the HTTP request doesn't get in the new URl: there is my
code:
  


The only two options again are to proxy to the external server, or 
redirect the client to the external server.


If you don't want a redirection at the web browser, you will have to 
proxy the request.  I do not know about setting up a hook into mod_proxy 
to have a request proxied - it's something I've never done, but there 
should be many people who have done it.  Anyone with any short examples?


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


Re: [Apache Module] Request External Redirection

2008-01-14 Thread karim Bendadda
How can I see if my module really redirect the request?? (by the
ap_log_error for example)
Thank you very much for your precisous help!

On 1/14/08, Joe Lewis [EMAIL PROTECTED] wrote:

 karim Bendadda wrote:
  I did that , I have a redirection to the new url but it seems that it's
 just
  a redirection , the HTTP request doesn't get in the new URl: there is my
  code:
 

 The only two options again are to proxy to the external server, or
 redirect the client to the external server.

 If you don't want a redirection at the web browser, you will have to
 proxy the request.  I do not know about setting up a hook into mod_proxy
 to have a request proxied - it's something I've never done, but there
 should be many people who have done it.  Anyone with any short examples?

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




-- 
Karim


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Joe Lewis

karim Bendadda wrote:

How can I see if my module really redirect the request?? (by the
ap_log_error for example)
Thank you very much for your precisous help!
  


You should see the URL change in the browser to the new location.

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


Re: [Apache Module] Request External Redirection

2008-01-14 Thread karim Bendadda
Sorry but I'm a beginer on developping Apache modules...Thank you for your
patience...

I dont't understand this:

 /* set a Location: header and 302 redirect. */

Does'it mean to make this??:

Location /my_module
Redirect /my_module http://10.112.3.20/test
/Location


Then I tried this:

static int my_module_handler (request_rec *r){

   /* assemble the url by appending the filename to a baseurl */

   uri = apr_pstrcat(r-pool, http://10.112.3.20/test;, my_module,
NULL);/**/

apr_table_setn(r-headers_out, my_module, uri);

 return HTTP_MOVED_TEMPORARILY;
}


Am I wrrong?? Is that means my request is redirected to
http://10.112.3.20/test??



On 1/14/08, Joe Lewis [EMAIL PROTECTED] wrote:

 karim Bendadda wrote:
  Thank you for your help!
 
  How can I call the Redirect directive into the module??, In fact in the
  module I have a function that make an LDAP connection I want to do
 something
  like that:
 
  request_rec* my_request; //The request with new information
 
  if(my_function(user_is_defined_in_ldap)==true)
 
  Redirect my_request new_Url
 
  else
 
  Do_nothing
 


 Do_nothing should be return DECLINED in the handler.  Redirect
 my_request new_URL should be almost verbatim the code that the Doc
 (Peter Poeml) included.  Let me just snip down through to his example to
 make it a little more obvious.


  In your handler, you would do something like this to implement the
 latter:
 
  /* set a Location: header and 302 redirect. */
 
  /* assemble the url by appending the filename to a baseurl */
  uri = apr_pstrcat(r-pool, baseurl, filename, NULL);
 
  apr_table_setn(r-headers_out, Location, uri);
 
  return HTTP_MOVED_TEMPORARILY;


 And there is the how to.  Recall, though, that this kind of thing
 shouldn't be in an input filter, but a handler.  (It may, in theory, be
 workable in a filter, but a filter is supposed to alter input not handle
 requests, and a handler is supposed to give the response of the 302 or
 data or decline to handle it.)

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




-- 
Karim


Re: [Apache Module] Request External Redirection

2008-01-14 Thread Joe Lewis

karim Bendadda wrote:

Sorry but I'm a beginer on developping Apache modules...Thank you for your
patience...

I dont't understand this:

  

/* set a Location: header and 302 redirect. */



Does'it mean to make this??:
  


No, that is just a C comment.


Location /my_module
Redirect /my_module http://10.112.3.20/test
/Location
  


This is a pre-build hard coded redirection module that does something 
very similar to :



static int my_module_handler (request_rec *r){

   /* assemble the url by appending the filename to a baseurl */

   uri = apr_pstrcat(r-pool, http://10.112.3.20/test;, my_module,
NULL);/**/

apr_table_setn(r-headers_out, my_module, uri);

 return HTTP_MOVED_TEMPORARILY;
}


  


However, you have two things that are wrong in your code.  The resulting 
uri would be http://10.112.3.20/testmy_module; because the 
apr_pstrcat() function tacks the two strings together.  If you already 
know the full URL, you can skip the uri= line and set the headers_out.


Which brings up the other issue.  The apr_table_setn must be setting a 
Location header in order to meet the redirection standard.  Yours is 
setting my_module.  Replace my_module with Location, and then 
whatever is in the uri parameter is going to the web browser as the 
location header, and it should contact the new server/resource.


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