httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject [PATCH] Accept-Encoding mk (n+1)
Date Sat, 18 Apr 1998 07:13:42 GMT
Here are some messages from Ronald Tschalaer... and a patch that I give
+1.  The first message gives context, the second has the patch. 

Dean

---------- Forwarded message ----------
Date: Tue, 17 Feb 1998 02:31:21 +0200
From: "Life is hard... and then you die." <Ronald.Tschalaer@psi.ch>
To: DGAUDET@arctic.org
Subject: Accept-Encoding - the saga continues
X-VMS-To: DGAUDET@ARCTIC.ORG


[...]
My previous patch has the problem that the Content-Encoding header is
only fixed up for negotiated documents. Asking for something like
"article.ps.gz" will return a Content-Encoding with a x-gzip or gzip
depending only on what is in the AddEncoding directive, not on what was
sent in an Accept-Encoding header. Therefore I've moved the fixup code
to the "fixup" phase in the module handling. I should've done that in
the first place... This means that all responses are fixed up, no matter
how they were generated. I think this is the correct solution.

The algorithm is still the same: if an accept-encoding header was sent
and it contains the non x- token then use that token in the
content-encoding; else if the accept-encoding header contains the x-
token then use that one; else use whatever was given in the AddEncoding
directive.

So far so good. Then comes this:

[Paul (ginsparg@qfwfq.lanl.gov) wrote:]
> things worked from our point of view, but then we had to turn it off due
> to another ridiculous bug report -- it seems that people who use MSIE
> together with gsview to look at ps.gz files had the following problem:
> MSIE downloaded the file and gunzipped it (since it was getting the C-E: gzip)
> but leaves it named .ps.gz so gsview assumes it's still gzipped and reports
> an error. so for these people it's better to send C-E: x-gzip so that MSIE
> *doesn't* gunzip and then gsview correctly reads it.

[...]

---------- Forwarded message ----------
Date: Fri, 27 Mar 1998 01:12:21 +0200
From: "Life is hard... and then you die." <Ronald.Tschalaer@psi.ch>
To: dgaudet@arctic.org
Subject: Re: Accept-Encoding - the saga continues (fwd) 
X-VMS-To: SMTP%"dgaudet@arctic.org"
X-VMS-Cc: RTSCHALAER


  Hi Dean,

> I forget where we are on this issue... do you know?  Got a patch?  :)

Hmm, I had sent a patch, but there was some debate... Specifically, the
"stip C-E header" hack was barfed at. However, the rest I think was ok,
with the possible exception of this note from you:

[snip]
> > > I think we have two choices:
> > > 
> > > - agree that x-compress and x-gzip are the way things are and always will
> > > be and we will always have to respond with those two (but we should
> > > *NEVER* respond with x-anything else, unless AddEncoding is configured
> > > that way, we should never help spread these stupidities) 

To which I replied:
> > Hmm, my patch will cause Apache to respond with "C-E: x-hello" if the
> > browser sent "A-E: x-hello". I.e. there is no explicit test for compress
> > and gzip (I just hate hardwiring things). I agree that Apache shouldn't
> > endorse this x- nonsense, but I think giving the browser what it asked
> > for goes under the heading of "Be liberal in what you accept".

I don't know how strongly you feel about this.

Anyway, here is the patch again againt my latest copy of apache:
apache_19980320020022.tar.gz . It does not contain the "strip C-E
header" hack anymore. It does have the behaviour I describe above,
however. I hope the comment in the code is clear enough.


  Cheers,

  Ronald


----------------------------------------------------------------------------
*** mod_negotiation.c.orig	Fri Mar 13 21:00:22 1998
--- mod_negotiation.c	Fri Mar 27 00:31:09 1998
***************
*** 1453,1459 ****
      int i;
      accept_rec *accept_recs = (accept_rec *) neg->accept_encodings->elts;
      char *enc = variant->content_encoding;
-     char *x_enc = NULL;
  
      if (!enc || is_identity_encoding(enc)) {
          return;
--- 1453,1458 ----
***************
*** 1469,1476 ****
      }
  
      /* Go through each of the encodings on the Accept-Encoding: header,
!      * looking for a match with our encoding
!      * Prefer non- 'x-' prefixed token (e.g. gzip over x-gzip) */
      if (enc[0] == 'x' && enc[1] == '-') {
          enc += 2;
      }
--- 1468,1475 ----
      }
  
      /* Go through each of the encodings on the Accept-Encoding: header,
!      * looking for a match with our encoding. x- prefixes are ignored.
!      */
      if (enc[0] == 'x' && enc[1] == '-') {
          enc += 2;
      }
***************
*** 1477,1499 ****
      for (i = 0; i < neg->accept_encodings->nelts; ++i) {
          char *name = accept_recs[i].type_name;
  
          if (!strcmp(name, enc)) {
              variant->encoding_quality = 1;
-             variant->content_encoding = name;
              return;
          }
- 
-         if (name[0] == 'x' && name[1] == '-' && !strcmp(name+2, enc)) {
-             x_enc = name;
-         }
      }
  
-     if (x_enc != NULL) {
-         variant->encoding_quality = 1;
-         variant->content_encoding = x_enc;
-         return;
-     }
- 
      /* Encoding not found on Accept-Encoding: header, so it is
       * _not_ acceptable */
      variant->encoding_quality = 0;
--- 1476,1491 ----
      for (i = 0; i < neg->accept_encodings->nelts; ++i) {
          char *name = accept_recs[i].type_name;
  
+         if (name[0] == 'x' && name[1] == '-') {
+             name += 2;
+         }
+ 
          if (!strcmp(name, enc)) {
              variant->encoding_quality = 1;
              return;
          }
      }
  
      /* Encoding not found on Accept-Encoding: header, so it is
       * _not_ acceptable */
      variant->encoding_quality = 0;
***************
*** 2197,2205 ****
      r->filename = sub_req->filename;
      r->handler = sub_req->handler;
      r->content_type = sub_req->content_type;
!     /* it may have been modified, so that it would match the exact encoding
!      * requested by the client (i.e. x-gzip vs. gzip) */
!     r->content_encoding = best->content_encoding;
      r->content_languages = sub_req->content_languages;
      r->content_language = sub_req->content_language;
      r->finfo = sub_req->finfo;
--- 2189,2195 ----
      r->filename = sub_req->filename;
      r->handler = sub_req->handler;
      r->content_type = sub_req->content_type;
!     r->content_encoding = sub_req->content_encoding;
      r->content_languages = sub_req->content_languages;
      r->content_language = sub_req->content_language;
      r->finfo = sub_req->finfo;
***************
*** 2222,2227 ****
--- 2212,2272 ----
      return OK;
  }
  
+ /* There is a problem with content-encoding, as some clients send and
+  * expect an x- token (e.g. x-gzip) while others expect the plain token
+  * (i.e. gzip). To try and deal with this as best as possible we do
+  * the following: if the client sent an Accept-Encoding header and it
+  * contains a plain token corresponding to the content encoding of the
+  * response, then set content encoding using the plain token. Else if
+  * the A-E header contains the x- token use the x- token in the C-E
+  * header. Else don't do anything.
+  *
+  * Note that if no A-E header was sent, or it does not contain a token
+  * compatible with the final content encoding, then the token in the
+  * C-E header will be whatever was specified in the AddEncoding
+  * directive.
+  */
+ static int fix_encoding(request_rec *r)
+ {
+     char *enc = r->content_encoding;
+     char *x_enc = NULL;
+     array_header *accept_encodings;
+     accept_rec *accept_recs;
+     int i;
+ 
+     if (!enc || !*enc) {
+         return DECLINED;
+     }
+ 
+     if (enc[0] == 'x' && enc[1] == '-') {
+         enc += 2;
+     }
+ 
+     accept_encodings = do_header_line(r->pool,
+                                 table_get(r->headers_in, "Accept-encoding"));
+     accept_recs = (accept_rec *) accept_encodings->elts;
+ 
+     for (i = 0; i < accept_encodings->nelts; ++i) {
+         char *name = accept_recs[i].type_name;
+ 
+         if (!strcmp(name, enc)) {
+             r->content_encoding = name;
+             return OK;
+         }
+ 
+         if (name[0] == 'x' && name[1] == '-' && !strcmp(name+2, enc)) {
+             x_enc = name;
+         }
+     }
+ 
+     if (x_enc) {
+         r->content_encoding = x_enc;
+         return OK;
+     }
+ 
+     return DECLINED;
+ }
+ 
  static const handler_rec negotiation_handlers[] =
  {
      {MAP_FILE_MAGIC_TYPE, handle_map_file},
***************
*** 2244,2250 ****
      NULL,                       /* check auth */
      NULL,                       /* check access */
      handle_multi,               /* type_checker */
!     NULL,                       /* fixups */
      NULL,                       /* logger */
      NULL,                       /* header parser */
      NULL,                       /* child_init */
--- 2289,2295 ----
      NULL,                       /* check auth */
      NULL,                       /* check access */
      handle_multi,               /* type_checker */
!     fix_encoding,               /* fixups */
      NULL,                       /* logger */
      NULL,                       /* header parser */
      NULL,                       /* child_init */
----------------------------------------------------------------------------


Mime
View raw message