)
AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_scheme_handler, (request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport),(r,url,proxyhost,proxyport),DECLINED)
-AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_canon_handler, (request_rec *r, char *url, const char *scheme, apr_port_t def_port),(r,url,scheme,def_port),DECLINED)
+AP_IMPLEMENT_HOOK_RUN_FIRST(int, proxy_canon_handler, (request_rec *r, char *url),(r,url),DECLINED)
/*
static int proxy_fixup(request_rec *r)
{
char *url, *p;
+ int access_status;
if (!r->proxyreq || strncmp(r->filename, "proxy:", 6) != 0)
return DECLINED;
url = &r->filename[6];
-/* canonicalise each specific scheme */
- if (strncasecmp(url, "http:", 5) == 0)
- return ap_proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT);
- else if (strncasecmp(url, "ftp:", 4) == 0)
- return ap_proxy_ftp_canon(r, url + 4, NULL, 0);
+ /* canonicalise each specific scheme */
+ if ((access_status = ap_run_proxy_canon_handler(r, url))) {
+ return access_status;
+ }
p = strchr(url, ':');
if (p == NULL || p == url)
int i, rc;
int direct_connect = 0;
const char *str;
- const char *pragma, *auth, *imstr;
long maxfwd;
/* is this for us? */
if (p == NULL)
return HTTP_BAD_REQUEST;
- pragma = apr_table_get(r->headers_in, "Pragma");
- auth = apr_table_get(r->headers_in, "Authorization");
- imstr = apr_table_get(r->headers_in, "If-Modified-Since");
-
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,
- "Request for %s, pragma=%s, auth=%s, imstr=%s", url,
- pragma, auth, imstr);
-
/* If the host doesn't have a domain name, add one and redirect. */
if (conf->domain != NULL) {
rc = proxy_needsdomain(r, url, conf->domain);
/* proxy_connect.c */
+int ap_proxy_connect_canon(request_rec *r, char *url);
int ap_proxy_connect_handler(request_rec *r, char *url,
const char *proxyhost, apr_port_t proxyport);
/* proxy_ftp.c */
-int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port);
+int ap_proxy_ftp_canon(request_rec *r, char *url);
int ap_proxy_ftp_handler(request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport);
apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f,
apr_bucket_brigade *bb);
/* proxy_http.c */
-int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
- apr_port_t def_port);
+int ap_proxy_http_canon(request_rec *r, char *url);
int ap_proxy_http_handler(request_rec *r, char *url,
const char *proxyhost, apr_port_t proxyport);
char *ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
int isenc);
char *ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
- char **passwordp, char **hostp, int *port);
+ char **passwordp, char **hostp, apr_port_t *port);
const char *ap_proxy_date_canon(apr_pool_t *p, const char *x);
apr_table_t *ap_proxy_read_headers(request_rec *r, request_rec *rp, char *buffer, int size, conn_rec *c);
int ap_proxy_liststr(const char *list, const char *val);
AP_DECLARE_HOOK(int, proxy_scheme_handler, (request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport))
-AP_DECLARE_HOOK(int, proxy_canon_handler, (request_rec *r, char *url, const char *scheme, apr_port_t def_port))
+AP_DECLARE_HOOK(int, proxy_canon_handler, (request_rec *r, char *url))
#endif /*MOD_PROXY_H*/
return 0;
}
+/* canonicalise CONNECT URLs. */
+int ap_proxy_connect_canon(request_rec *r, char *url)
+{
+
+ if (r->method_number != M_CONNECT) {
+ return DECLINED;
+ }
+
+ return OK;
+}
+
+/* CONNECT handler */
int ap_proxy_connect_handler(request_rec *r, char *url,
const char *proxyname, apr_port_t proxyport)
{
proxy_server_conf *conf =
(proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+ /* is this for us? */
+ if (r->method_number != M_CONNECT) {
+ return DECLINED;
+ }
/*
* Step One: Determine Who To Connect To
static void ap_proxy_connect_register_hook(apr_pool_t *p)
{
ap_hook_proxy_scheme_handler(ap_proxy_connect_handler, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_proxy_canon_handler(ap_proxy_connect_canon, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA proxy_connect_module = {
/*
* Canonicalise ftp URLs.
*/
-int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port)
+int ap_proxy_ftp_canon(request_rec *r, char *url)
{
char *user, *password, *host, *path, *parms, *strp, sport[7];
apr_pool_t *p = r->pool;
const char *err;
- int port;
+ apr_port_t port, def_port;
- port = DEFAULT_FTP_PORT;
+ /* */
+ if (strncasecmp(url, "ftp:", 4) == 0) {
+ url += 4;
+ }
+ else {
+ return DECLINED;
+ }
+ def_port = ap_default_port_for_scheme("ftp");
+
+ port = def_port;
err = ap_proxy_canon_netloc(p, &url, &user, &password, &host, &port);
if (err)
return HTTP_BAD_REQUEST;
if (password != NULL && !ftp_check_string(password))
return HTTP_BAD_REQUEST;
-/* now parse path/parameters args, according to rfc1738 */
-/* N.B. if this isn't a true proxy request, then the URL path
- * (but not query args) has already been decoded.
- * This gives rise to the problem of a ; being decoded into the
- * path.
- */
+ /* now parse path/parameters args, according to rfc1738 */
+ /* N.B. if this isn't a true proxy request, then the URL path
+ * (but not query args) has already been decoded.
+ * This gives rise to the problem of a ; being decoded into the
+ * path.
+ */
strp = strchr(url, ';');
if (strp != NULL) {
*(strp++) = '\0';
/* now, rebuild URL */
- if (port != DEFAULT_FTP_PORT)
+ if (port != def_port)
apr_snprintf(sport, sizeof(sport), ":%d", port);
else
sport[0] = '\0';
* url is the URL starting with the first '/'
* def_port is the default port for this scheme.
*/
-int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port)
+int ap_proxy_http_canon(request_rec *r, char *url)
{
char *host, *path, *search, sport[7];
const char *err;
- int port;
+ const char *scheme;
+ apr_port_t port, def_port;
-/* do syntatic check.
- * We break the URL into host, port, path, search
- */
+ /* ap_default_port_for_scheme() */
+ if (strncasecmp(url, "http:", 5) == 0) {
+ url += 5;
+ scheme = "http";
+ }
+ else if (strncasecmp(url, "https:", 6) == 0) {
+ url += 6;
+ scheme = "https:";
+ }
+ else {
+ return DECLINED;
+ }
+ def_port = ap_default_port_for_scheme(scheme);
+
+ /* do syntatic check.
+ * We break the URL into host, port, path, search
+ */
port = def_port;
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
if (err)
return HTTP_BAD_REQUEST;
-/* now parse path/search args, according to rfc1738 */
-/* N.B. if this isn't a true proxy request, then the URL _path_
- * has already been decoded. True proxy requests have r->uri
- * == r->unparsed_uri, and no others have that property.
- */
+ /* now parse path/search args, according to rfc1738 */
+ /* N.B. if this isn't a true proxy request, then the URL _path_
+ * has already been decoded. True proxy requests have r->uri
+ * == r->unparsed_uri, and no others have that property.
+ */
if (r->uri == r->unparsed_uri) {
search = strchr(url, '?');
if (search != NULL)
else
search = r->args;
-/* process path */
+ /* process path */
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, r->proxyreq);
if (path == NULL)
return HTTP_BAD_REQUEST;
*/
char *
ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
- char **passwordp, char **hostp, int *port)
+ char **passwordp, char **hostp, apr_port_t *port)
{
- int i;
+ apr_port_t i;
char *strp, *host, *url = *urlp;
char *user = NULL, *password = NULL;
proxy_get_host_of_request(request_rec *r)
{
char *url, *user = NULL, *password = NULL, *err, *host;
- int port = -1;
+ apr_port_t port = -1;
if (r->hostname != NULL)
return r->hostname;