Skip to content

Instantly share code, notes, and snippets.

@hiboma
Created June 17, 2012 13:17
Show Gist options
  • Save hiboma/2944528 to your computer and use it in GitHub Desktop.
Save hiboma/2944528 to your computer and use it in GitHub Desktop.
how to use mod_proxy's "proxy-server" handler in your custom Apache module
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "http_request.h"
static int reverse_proxy_handler(request_rec *r)
{
r->filename = apr_pstrcat(r->pool, "proxy:http://example.com/", r->unparsed_uri, NULL);
r->proxyreq = PROXYREQ_REVERSE;
r->handler = "proxy-server";
return OK;
}
static void reverse_proxy_register_hooks(apr_pool_t *p)
{
ap_hook_fixups(reverse_proxy_handler, NULL, NULL, APR_HOOK_FIRST);
}
/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA reverse_proxy_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
NULL, /* table of config file commands */
reverse_proxy_register_hooks /* register hooks */
};
@hiboma
Copy link
Author

hiboma commented Jun 17, 2012

a bit buggy ,,,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment