Forced cache refresh and no_proxy in Mosaic

luotonen@ptsun00.cern.ch (Ari Luotonen)
Errors-To: listmaster@www0.cern.ch
Date: Thu, 12 May 1994 15:09:58 +0200
Errors-To: listmaster@www0.cern.ch
Message-id: <9405121307.AA06474@ptsun03.cern.ch>
Errors-To: listmaster@www0.cern.ch
Reply-To: luotonen@ptsun00.cern.ch
Originator: www-talk@info.cern.ch
Sender: www-talk@www0.cern.ch
Precedence: bulk
From: luotonen@ptsun00.cern.ch (Ari Luotonen)
To: Multiple recipients of list <www-talk@www0.cern.ch>
Subject: Forced cache refresh and no_proxy in Mosaic
X-Listprocessor-Version: 6.0c -- ListProcessor by Anastasios Kotsikonas

Dear WWW proxy (cern_httpd) users,

As release notes of CERN httpd 3.0preX let understand, httpd as a
proxy understands the

	Pragma: no-cache

header, causing a forced cache refresh. This header line has been
added to the HTTP spec.  Clients should start supporting this, but
since nobody has time to do that, enclosed you will find 3 patch
files for Mosaic 2.4 which cause it to send this pragma when you
press Reload.

Another addition is the support of no_proxy environment variable.
For example, now I can set for my patched Mosaic:

	setenv no_proxy cern.ch

and no request to domain cern.ch goes thru the proxy but rather
directly to the server inside CERN.

Local requests going through the proxy have been an annoying side
effect of WWW proxy usage, but this no longer has to be so.

Precompiled stripped gzipped Mosaic 2.4 for SunOS 4.1.3 with and
without -lresolv is also available from directory:

	ftp://info.cern.ch/pub/www/proxy-support/Mosaic-2.4

Patched versions of HTAccess.c, HTTP.c and gui-documents.c, and
patches themselves are also in that directory.

I guarantee no further support whatsoever for this, you should rather
pressure NCSA to put the patches in, these are *important* changes and
should be supported by the official version!

Cheers,
--
Ari Luotonen		 |
World-Wide Web Project	 |
CERN			 | phone: +41 22 767 8583
CH - 1211 Geneve 23	 | email: luotonen@dxcern.cern.ch


--clip---clip---clip---clip---clip---clip---clip---clip---clip---clip--


*** HTAccess.c.ORIG	Thu May 12 14:18:55 1994
--- HTAccess.c	Thu May 12 14:25:36 1994
***************
*** 108,113 ****
--- 108,192 ----
  }
  
  
+ /*							override_proxy()
+ **
+ **	Check the no_proxy environment variable to get the list
+ **	of hosts for which proxy server is not consulted.
+ **
+ **	no_proxy is a comma- or space-separated list of machine
+ **	or domain names, with optional :port part.  If no :port
+ **	part is present, it applies to all ports on that domain.
+ **
+ **	Example:
+ **		no_proxy="cern.ch,some.domain:8001"
+ **
+ */
+ PRIVATE BOOL override_proxy ARGS1(CONST char *, addr)
+ {
+     CONST char * no_proxy = getenv("no_proxy");
+     char * p = NULL;
+     char * host = NULL;
+     int port = 0;
+     int h_len = 0;
+ 
+     if (!no_proxy || !addr || !(host = HTParse(addr, "", PARSE_HOST)))
+ 	return NO;
+     if (!*host) { free(host); return NO; }
+ 
+     if (p = strchr(host, ':')) {	/* Port specified */
+ 	*p++ = 0;			/* Chop off port */
+ 	port = atoi(p);
+     }
+     else {				/* Use default port */
+ 	char * access = HTParse(addr, "", PARSE_ACCESS);
+ 	if (access) {
+ 	    if	    (!strcmp(access,"http"))	port = 80;
+ 	    else if (!strcmp(access,"gopher"))	port = 70;
+ 	    else if (!strcmp(access,"ftp"))	port = 21;
+ 	    free(access);
+ 	}
+     }
+     if (!port) port = 80;		/* Default */
+     h_len = strlen(host);
+ 
+     while (*no_proxy) {
+ 	CONST char * end;
+ 	CONST char * colon = NULL;
+ 	int templ_port = 0;
+ 	int t_len;
+ 
+ 	while (*no_proxy && (WHITE(*no_proxy) || *no_proxy==','))
+ 	    no_proxy++;			/* Skip whitespace and separators */
+ 
+ 	end = no_proxy;
+ 	while (*end && !WHITE(*end) && *end != ',') {	/* Find separator */
+ 	    if (*end==':') colon = end;			/* Port number given */
+ 	    end++;
+ 	}
+ 
+ 	if (colon) {
+ 	    templ_port = atoi(colon+1);
+ 	    t_len = colon - no_proxy;
+ 	}
+ 	else {
+ 	    t_len = end - no_proxy;
+ 	}
+ 
+ 	if ((!templ_port || templ_port == port)  &&
+ 	    (t_len > 0  &&  t_len <= h_len  &&
+ 	     !strncmp(host + h_len - t_len, no_proxy, t_len))) {
+ 	    free(host);
+ 	    return YES;
+ 	}
+ 	if (*end) no_proxy = end+1;
+ 	else break;
+     }
+ 
+     free(host);
+     return NO;
+ }
+ 
+ 
  /*		Find physical name and access protocol
  **		--------------------------------------
  **
***************
*** 137,143 ****
  */
  #define USE_GATEWAYS
  #ifdef USE_GATEWAYS
!     {
  	char *gateway_parameter, *gateway, *proxy;
  
  	/* search for gateways */
--- 216,226 ----
  */
  #define USE_GATEWAYS
  #ifdef USE_GATEWAYS
! 
!     /* make sure the using_proxy variable is false */
!     using_proxy = NO;
! 
!     if (!override_proxy(addr)) {
  	char *gateway_parameter, *gateway, *proxy;
  
  	/* search for gateways */
***************
*** 168,176 ****
  	    gateway = DEFAULT_WAIS_GATEWAY;
  	}
  #endif
- 
- 	/* make sure the using_proxy variable is false */
- 	using_proxy = NO;
  
  	/* proxy servers have precedence over gateway servers */
  	if (proxy) {
--- 251,256 ----


--clip---clip---clip---clip---clip---clip---clip---clip---clip---clip--

*** HTTP.c.ORIG	Thu May 12 13:25:33 1994
--- HTTP.c	Thu May 12 13:34:09 1994
***************
*** 40,46 ****
  char *post_data = NULL;
  extern BOOL using_gateway;    /* are we using an HTTP gateway? */
  extern BOOL using_proxy;      /* are we using an HTTP proxy gateway? */
! 
  
  /*		Load Document from HTTP Server			HTLoadHTTP()
  **		==============================
--- 40,46 ----
  char *post_data = NULL;
  extern BOOL using_gateway;    /* are we using an HTTP gateway? */
  extern BOOL using_proxy;      /* are we using an HTTP proxy gateway? */
! PUBLIC BOOL reloading = NO;   /* reloading => send no-cache pragma to proxy */
  
  /*		Load Document from HTTP Server			HTLoadHTTP()
  **		==============================
***************
*** 195,201 ****
                StrAllocCat(command, line);
              }
          }
!       
        sprintf(line, "User-Agent:  %s/%s  libwww/%s%c%c",
                HTAppName ? HTAppName : "unknown",
                HTAppVersion ? HTAppVersion : "0.0",
--- 195,210 ----
                StrAllocCat(command, line);
              }
          }
! 
!       /*
!        * When reloading give no-cache pragma to proxy server to make
!        * it refresh its cache. -- Ari L. <luotonen@dxcern.cern.ch>
!        */
!       if (reloading) {
! 	  sprintf(line, "Pragma: no-cache%c%c", CR, LF);
! 	  StrAllocCat(command, line);
!       }
! 
        sprintf(line, "User-Agent:  %s/%s  libwww/%s%c%c",
                HTAppName ? HTAppName : "unknown",
                HTAppVersion ? HTAppVersion : "0.0",


--clip---clip---clip---clip---clip---clip---clip---clip---clip---clip--

*** gui-documents.c.ORIG	Mon Apr 11 20:58:02 1994
--- gui-documents.c	Thu May 12 14:13:11 1994
***************
*** 487,494 ****
  	post_gave_encrypt = 0;
  #endif /* PEM_AUTH */
  
!   win->current_node->text = mo_pull_er_over (win->current_node->url, 
!                                              &win->current_node->texthead);
    {
      /* Check use_this_url_instead from HTAccess.c. */
      /* IS THIS GOOD ENOUGH FOR THIS CASE??? */
--- 487,503 ----
  	post_gave_encrypt = 0;
  #endif /* PEM_AUTH */
  
!   {
!       /*
!        * Reload should force a cache refresh on a proxy
!        *	-- Ari L. <luotonen@dxcern.cern.ch>
!        */
!       extern char reloading;	/* is really a BOOL */
!       reloading = 1;
!       win->current_node->text = mo_pull_er_over (win->current_node->url, 
! 						 &win->current_node->texthead);
!       reloading = 0;
!   }
    {
      /* Check use_this_url_instead from HTAccess.c. */
      /* IS THIS GOOD ENOUGH FOR THIS CASE??? */


--clip---clip---clip---clip---clip---clip---clip---clip---clip---clip--