You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ha...@hyperreal.com> on 1995/11/24 21:38:35 UTC

Re: ICP client/server in Perl (fwd)

No ack sent

Forwarded message:
> From martin@mrrl.lut.ac.uk  Thu Nov 23 10:29:03 1995
> Message-Id: <19...@gizmo.lut.ac.uk>
> To: Peter Danzig <da...@catarina.usc.edu>
> cc: cybercache@mrrl.lut.ac.uk, apache-bugs@mail.apache.org
> Subject: Re: ICP client/server in Perl 
> X-Mailer: exmh version 1.6.4 10/10/95
> X-URI: <URL:http://www.roads.lut.ac.uk/~martin>
> In-reply-to: Your message of "Wed, 22 Nov 1995 18:14:42 PST."
>              <19...@warthog.usc.edu> 
> Mime-Version: 1.0
> Content-Type: text/plain
> Date: Thu, 23 Nov 1995 18:26:48 +0000
> From: Martin Hamilton <ma...@mrrl.lut.ac.uk>
> 
> 
> Peter Danzig writes:
> 
> | Currently, the cache would return your MD5 checksum as part
> | of the object's MIME header.  While I agree that it would be 
> | great for consistency if the cache re-computed the object's MD5,
> | do you think we proxy builders can rely on the browsers to detect
> | corrupted objects and to automatically issue a refresh?
> 
> I like the model of browsers using MD5 to tell their users whether
> the object got through OK.  Guess we'll need most of the popular
> servers to support it before the browser authors catch on.  I
> might have a go at hacking it into the odd one...
> 
> Content-MD5 would probably be good for caches even if they avoided
> having to calculate the checksum themselves ?  e.g. cache the MD5
> checksum provided by the server when the cached object was
> originally fetched, and it becomes a reliable indicator of the
> object having changed...  There's probably also some mileage in
> using MD5s where we currently use URLs ? - cf. Keith Moore's
> "Location Independent Filenames"
> 
> Cheerio,
> 
> Martin
> 
> PS Here's a quick hack which adds support for the "Content-MD5:"
> Header (cf. RFC 1864) to Apache httpd 0.8.14. 
> 
> e.g. (> indicates client, < indicates server)
> 
>   >GET /~martin/check.txt HTTP/1.0
>   >Accept: */*
>   >
>   <HTTP/1.0 200 OK
>   <Date: Thu, 23 Nov 1995 17:59:06 GMT
>   <Server: Apache/0.8.14
>   <Content-type: text/plain
>   <Content-MD5: g5A4uaZgbiUx5+vMX0eHMQ==
>   <Content-length: 19
>   <Last-modified: Wed, 22 Nov 1995 18:54:59 GMT
>   <
>   <Squeamish OSIfrage
> 
> To build a Content-MD5 enabled server, 
> 
>   o add -DCONTENT_MD5 to the CFLAGS in src/Configuration, 
>   o copy md5.h, globals.h, and md5c.c from RSA's MD5 package
>      (or from the NCSA httpd 1.5 source directory!)
>   o copy the new file md5.c (see below) into the src
>      directory
>   o add md5.o and md5c.o to the list of objects to compile
>      in src/Makefile.tmpl
>   o now run ./Configure and make as usual
> 
> MD5 checksums are only supplied for static files
> 
> A drawback with this approach is that the amount of work
> required to calculate the MD5 checksum of a large object can be
> significant.  The obvious next step would be to cache MD5
> checksums and file modification times (perhaps in a DBM style
> database?)- and only recalculate the checksum if the object has
> been modfied since the last visit
> 
> 
> *** src/http_core.c.FCS Thu Nov 23 18:06:47 1995
> --- src/http_core.c     Thu Nov 23 17:32:08 1995
> ***************
> *** 677,682 ****
> --- 677,686 ----
>           return FORBIDDEN;
>       }
>         
> + #ifdef CONTENT_MD5
> +     r->content_md5 = (char *)md5digest(f);
> + #endif
> + 
>       soft_timeout ("send", r);
>       
>       send_http_header (r);
> 
> *** src/http_protocol.c.FCS	Thu Nov 23 17:24:33 1995
> --- src/http_protocol.c	Thu Nov 23 17:32:34 1995
> ***************
> *** 515,520 ****
> --- 515,525 ----
>       
>       if (r->content_language)
>           fprintf (fd, "Content-language: %s\015\012", r->content_language);
> + 
> + #ifdef CONTENT_MD5
> +     if (r->content_md5)
> +         fprintf (fd, "Content-MD5: %s\015\012", r->content_md5);
> + #endif 
>       
>       for (i = 0; i < hdrs_arr->nelts; ++i) {
>           if (!hdrs[i].key) continue;
> 
> *** src/httpd.h.FCS	Thu Nov 23 17:20:36 1995
> --- src/httpd.h	Thu Nov 23 17:32:59 1995
> ***************
> *** 306,311 ****
> --- 306,314 ----
>     char *content_type;		/* Break these out --- we dispatch on 'em */
>     char *content_encoding;
>     char *content_language;
> + #ifdef CONTENT_MD5
> +   char *content_md5;
> + #endif
>     
>     int no_cache;
>     
> 
> 
> New file:  src/md5.c  ...
> 
> 
> #ifdef CONTENT_MD5
> 
> #include <stdio.h>
> #include <string.h>
> #include "global.h"
> #include "md5.h"
> 
> /* these portions extracted from mpack, John G. Myers - jgm+@cmu.edu */
> 
> /* (C) Copyright 1993,1994 by Carnegie Mellon University
>  * All Rights Reserved.
>  *
>  * Permission to use, copy, modify, distribute, and sell this software
>  * and its documentation for any purpose is hereby granted without
>  * fee, provided that the above copyright notice appear in all copies
>  * and that both that copyright notice and this permission notice
>  * appear in supporting documentation, and that the name of Carnegie
>  * Mellon University not be used in advertising or publicity
>  * pertaining to distribution of the software without specific,
>  * written prior permission.  Carnegie Mellon University makes no
>  * representations about the suitability of this software for any
>  * purpose.  It is provided "as is" without express or implied
>  * warranty.
>  *
>  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
>  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
>  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
>  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
>  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
>  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
>  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
>  * SOFTWARE.
>  */
> /*
> Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
> 
> Permission to use, copy, modify, and distribute this material
> for any purpose and without fee is hereby granted, provided
> that the above copyright notice and this permission notice
> appear in all copies, and that the name of Bellcore not be
> used in advertising or publicity pertaining to this
> material without the specific, prior written permission
> of an authorized representative of Bellcore.  BELLCORE
> MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
> OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
> WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.  */
> 
> static char basis_64[] =
>    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
> 
> char *md5contextTo64(context)
> MD5_CTX *context;
> {
>     unsigned char digest[18];
>     char *encodedDigest;
>     int i;
>     char *p;
> 
>     encodedDigest = (char *)malloc(25 * sizeof(char));
> 
>     MD5Final(digest, context);
>     digest[sizeof(digest)-1] = digest[sizeof(digest)-2] = 0;
> 
>     p = encodedDigest;
>     for (i=0; i < sizeof(digest); i+=3) {
>         *p++ = basis_64[digest[i]>>2];
>         *p++ = basis_64[((digest[i] & 0x3)<<4) | ((digest[i+1] & 0xF0)>>4)];
>         *p++ = basis_64[((digest[i+1] & 0xF)<<2) | ((digest[i+2] & 0xC0)>>6)];
>         *p++ = basis_64[digest[i+2] & 0x3F];
>     }
>     *p-- = '\0';
>     *p-- = '=';
>     *p-- = '=';
>     return encodedDigest;
> }
> 
> 
> char *md5digest(infile)
> FILE *infile;
> {
>     MD5_CTX context;
>     char buf[1000];
>     long length = 0;
>     int nbytes;
> 
>     MD5Init(&context);
>     while (nbytes = fread(buf, 1, sizeof(buf), infile)) {
>         length += nbytes;
>         MD5Update(&context, buf, nbytes);
>     }
>     rewind(infile);
>     return md5contextTo64(&context);
> }
> #endif /* CONTENT_MD5 */
> 
> 
>