You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by Chuck Murcko <ch...@hyperreal.com> on 1996/12/09 23:40:19 UTC

cvs commit: apache/src/modules/proxy proxy_http.c

chuck       96/12/09 14:40:18

  Modified:    src/modules/proxy  proxy_http.c
  Log:
  1) fixes possible NULL pointer reference w/NoCache
  2) fixes NoCache behavior when using ProxyRemote (ProxyRemote host would
       cache nothing if it was in the local domain, and the local domain
       was in the NoCache list)
  3) Adds Host: header when not available
  4) Some code cleanup and clarification
  
  1) and 2) were reported by Martin Kraemer, with patches. The function,
  though not the form, of Martin's stuff is adhered to here.
  
  Revision  Changes    Path
  1.7       +40 -25    apache/src/modules/proxy/proxy_http.c
  
  Index: proxy_http.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_http.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -C3 -r1.6 -r1.7
  *** proxy_http.c	1996/11/25 11:22:05	1.6
  --- proxy_http.c	1996/12/09 22:40:17	1.7
  ***************
  *** 142,149 ****
    	     const char *proxyhost, int proxyport)
    {
        char *p;
  !     const char *err, *host;
  !     int port, i, sock, len;
        array_header *reqhdrs_arr, *resp_hdrs;
        table_entry *reqhdrs;
        struct sockaddr_in server;
  --- 142,149 ----
    	     const char *proxyhost, int proxyport)
    {
        char *p;
  !     const char *err, *desthost;
  !     int i, sock, len;
        array_header *reqhdrs_arr, *resp_hdrs;
        table_entry *reqhdrs;
        struct sockaddr_in server;
  ***************
  *** 152,157 ****
  --- 152,159 ----
        char buffer[HUGE_STRING_LEN], inprotocol[9], outprotocol[9];
        pool *pool=r->pool;
        const long int zero=0L;
  +     int destport = 0;
  +     char *destportstr = NULL;
    
        void *sconf = r->server->module_config;
        proxy_server_conf *conf =
  ***************
  *** 162,182 ****
        memset(&server, '\0', sizeof(server));
        server.sin_family = AF_INET;
    
  !     if (proxyhost != NULL)
  !     {
  ! 	server.sin_port = htons(proxyport);
  ! 	err = proxy_host2addr(proxyhost, &server.sin_addr);
  ! 	if (err != NULL) return DECLINED;  /* try another */
  ! 	host = proxyhost;
  !     } else
        {
    	url += 7;  /* skip http:// */
  ! /* We break the URL into host, port, path-search */
  ! 	port = DEFAULT_PORT;
    	p = strchr(url, '/');
    	if (p == NULL)
    	{
  ! 	    host = pstrdup(pool, url);
    	    url = "/";
    	} else
    	{
  --- 164,179 ----
        memset(&server, '\0', sizeof(server));
        server.sin_family = AF_INET;
    
  ! /* We break the URL into host, port, path-search */
  ! 
  !     if ((desthost = table_get(r->headers_in, "Host:")) == NULL)
        {
    	url += 7;  /* skip http:// */
  ! 	destport = DEFAULT_PORT;
    	p = strchr(url, '/');
    	if (p == NULL)
    	{
  ! 	    desthost = pstrdup(pool, url);
    	    url = "/";
    	} else
    	{
  ***************
  *** 184,200 ****
    	    memcpy(q, url, p-url);
    	    q[p-url] = '\0';
    	    url = p;
  ! 	    host = q;
    	}
    
  ! 	p = strchr(host, ':');
  ! 	if (p != NULL)
  ! 	{
  ! 	    *(p++) = '\0';
  ! 	    port = atoi(p);
  ! 	}
  ! 	server.sin_port = htons(port);
  ! 	err = proxy_host2addr(host, &server.sin_addr);
    	if (err != NULL) return proxyerror(r, err); /* give up */
        }
    
  --- 181,208 ----
    	    memcpy(q, url, p-url);
    	    q[p-url] = '\0';
    	    url = p;
  ! 	    desthost = q;
    	}
  +     }
    
  !     p = strchr(desthost, ':');
  !     if (p != NULL)
  !     {
  !         *(p++) = '\0';
  !         destport = atoi(p);
  !         destportstr = p;
  !     }
  ! 
  !     if (proxyhost != NULL)
  !     {
  ! 	url = r->uri;			/* restore original URL */
  ! 	server.sin_port = htons(proxyport);
  ! 	err = proxy_host2addr(proxyhost, &server.sin_addr);
  ! 	if (err != NULL) return DECLINED;  /* try another */
  !     } else
  !     {
  ! 	server.sin_port = htons(destport);
  ! 	err = proxy_host2addr(desthost, &server.sin_addr);
    	if (err != NULL) return proxyerror(r, err); /* give up */
        }
    
  ***************
  *** 213,231 ****
    	else return proxyerror(r, "Could not connect to remote machine");
        }
    
  !     clear_connection(r->headers_in);   /* Strip connection-based headers */
    
        f = bcreate(pool, B_RDWR);
        bpushfd(f, sock, sock);
    
        hard_timeout ("proxy send", r);
        bvputs(f, r->method, " ", url, " HTTP/1.0\015\012", NULL);
    
        reqhdrs_arr = table_elts (r->headers_in);
        reqhdrs = (table_entry *)reqhdrs_arr->elts;
        for (i=0; i < reqhdrs_arr->nelts; i++)
        {
  ! 	if (reqhdrs[i].key == NULL || reqhdrs[i].val == NULL) continue;
    	bvputs(f, reqhdrs[i].key, ": ", reqhdrs[i].val, "\015\012", NULL);
        }
    
  --- 221,246 ----
    	else return proxyerror(r, "Could not connect to remote machine");
        }
    
  !     clear_connection(r->headers_in);	/* Strip connection-based headers */
    
        f = bcreate(pool, B_RDWR);
        bpushfd(f, sock, sock);
    
        hard_timeout ("proxy send", r);
        bvputs(f, r->method, " ", url, " HTTP/1.0\015\012", NULL);
  +     bvputs(f, "Host: ", desthost, NULL);
  +     if (destportstr != NULL && destport != DEFAULT_PORT)
  + 	bvputs(f, ":", destportstr, "\015\012", NULL);
  +     else
  + 	bputs("\015\012", f);
    
        reqhdrs_arr = table_elts (r->headers_in);
        reqhdrs = (table_entry *)reqhdrs_arr->elts;
        for (i=0; i < reqhdrs_arr->nelts; i++)
        {
  ! 	if (reqhdrs[i].key == NULL || reqhdrs[i].val == NULL
  ! 	  || !strcmp(reqhdrs[i].key, "Host"))	/* already sent if there */
  ! 	    continue;
    	bvputs(f, reqhdrs[i].key, ": ", reqhdrs[i].val, "\015\012", NULL);
        }
    
  ***************
  *** 308,315 ****
    /* check if NoCache directive on this host */
        for (i=0; i < conf->nocaches->nelts; i++)
        {
  !         if (ent[i].name[0] == '*' || (ent[i].name != NULL &&
  !           strstr(host, ent[i].name) != NULL))
    	    nocache = 1; 
        }
    
  --- 323,330 ----
    /* check if NoCache directive on this host */
        for (i=0; i < conf->nocaches->nelts; i++)
        {
  !         if ((ent[i].name != NULL && strstr(desthost, ent[i].name) != NULL)
  ! 	  || ent[i].name[0] == '*')
    	    nocache = 1; 
        }