httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@nueva.pvt.k12.ca.us>
Subject Re: Problems with Content Negociation (fwd)
Date Sat, 18 May 1996 23:41:43 GMT
On Fri, 17 May 1996, Robert S. Thau wrote:

>   Well, it seemed the simplest. Least likely to break something else.
> 
> The problem with trying to implement tie-breaking rules by jiggling
> the numbers like this is that if you try to handle anything *else*
> the same way, the interactions start to get messy.

Good point. It's just that that reeeeeeeealy long if statement towards
the end of best_match() scares me and I didn't want to mess with it.

But I tried. Here's a patch that seems to work:

Index: mod_negotiation.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_negotiation.c,v
retrieving revision 1.6
diff -c -r1.6 mod_negotiation.c
*** mod_negotiation.c	1996/04/17 14:02:17	1.6
--- mod_negotiation.c	1996/05/18 23:39:08
***************
*** 175,185 ****
      int is_pseudo_html;		/* text/html, *or* the INCLUDES_MAGIC_TYPEs */
  
      /* Above are all written-once properties of the variant.  The
!      * two fields below are changed during negotiation:
       */
      
      float quality;	
      float level_matched;
  } var_rec;
  
  /* Something to carry around the state of negotiation (and to keep
--- 175,186 ----
      int is_pseudo_html;		/* text/html, *or* the INCLUDES_MAGIC_TYPEs */
  
      /* Above are all written-once properties of the variant.  The
!      * three fields below are changed during negotiation:
       */
      
      float quality;	
      float level_matched;
+     int mime_stars;
  } var_rec;
  
  /* Something to carry around the state of negotiation (and to keep
***************
*** 216,221 ****
--- 217,223 ----
      mime_info->quality = 0.0;
      mime_info->bytes = 0;
      mime_info->lang_index = -1;
+     mime_info->mime_stars = 0;
  }
  
  /* Initializing the relevant fields of a variant record from the
***************
*** 720,725 ****
--- 722,730 ----
   *
   * Note also that if we get an exact match on the media type, we update
   * level_matched for use in level_cmp below...
+  * 
+  * We also give a value for mime_stars, which is used later. It should
+  * be 1 for star/star, 2 for type/star and 3 for type/subtype.
   */
  
  int mime_match (accept_rec *accept, var_rec *avail)
***************
*** 728,743 ****
      char *avail_type = avail->type_name;
      int len = strlen(accept_type);
    
!     if (accept_type[0] == '*')	/* Anything matches star/star */
  	return 1; 
!     else if (accept_type[len - 1] == '*')
! 	return !strncmp (accept_type, avail_type, len - 2);
      else if (!strcmp (accept_type, avail_type)
  	     || (!strcmp (accept_type, "text/html")
  		 && (!strcmp(avail_type, INCLUDES_MAGIC_TYPE)
  		     || !strcmp(avail_type, INCLUDES_MAGIC_TYPE3)))) {
  	if (accept->level >= avail->level) {
  	    avail->level_matched = avail->level;
  	    return 1;
  	}
      }
--- 733,756 ----
      char *avail_type = avail->type_name;
      int len = strlen(accept_type);
    
!     if (accept_type[0] == '*')	{ /* Anything matches star/star */
!         if (avail->mime_stars < 1)
! 	  avail->mime_stars = 1;
  	return 1; 
!     }
!     else if ((accept_type[len - 1] == '*') &&
! 	     !strncmp (accept_type, avail_type, len - 2)) {
!         if (avail->mime_stars < 2)
! 	  avail->mime_stars = 2;
! 	return 1;
!     }
      else if (!strcmp (accept_type, avail_type)
  	     || (!strcmp (accept_type, "text/html")
  		 && (!strcmp(avail_type, INCLUDES_MAGIC_TYPE)
  		     || !strcmp(avail_type, INCLUDES_MAGIC_TYPE3)))) {
  	if (accept->level >= avail->level) {
  	    avail->level_matched = avail->level;
+ 	    avail->mime_stars = 3;
  	    return 1;
  	}
      }
***************
*** 916,922 ****
  	return;
  
      /* Lose any variant with an unacceptable content encoding */
! 
      for (i = 0; i < neg->avail_vars->nelts; ++i)
  	if (var_recs[i].quality > 0
  	    && !find_encoding (neg->accept_encodings,
--- 929,935 ----
  	return;
  
      /* Lose any variant with an unacceptable content encoding */
!     
      for (i = 0; i < neg->avail_vars->nelts; ++i)
  	if (var_recs[i].quality > 0
  	    && !find_encoding (neg->accept_encodings,
***************
*** 1006,1011 ****
--- 1019,1028 ----
  	     * tied variants by whatever means it likes.  This server
  	     * breaks ties as follows, in order:
  	     *
+ 	     * By perferring non-wildcard entries to those with
+ 	     * wildcards. The spec specifically says we should
+ 	     * do this, and it makes a lot of sense.
+ 	     *
  	     * By order of languages in Accept-language, to give the
  	     * client a way to specify a language preference.  I'd prefer
  	     * to give this precedence over media type, but the standard
***************
*** 1025,1039 ****
  		
  	    if (q > best_quality
  		|| (q == best_quality
! 		    && (variant->lang_index < best->lang_index
! 			|| (variant->lang_index == best->lang_index
! 			    && ((levcmp = level_cmp (variant, best)) == 1
! 				|| (levcmp == 0
! 				    && !strcmp (variant->type_name,
! 						best->type_name)
! 				    && (find_content_length(neg, variant)
! 					<
! 					find_content_length(neg, best))))))))
  	    {
  		best = variant;
  		best_quality = q;
--- 1042,1057 ----
  		
  	    if (q > best_quality
  		|| (q == best_quality
! 		    && ((variant->mime_stars > best->mime_stars)
! 			|| (variant->lang_index < best->lang_index
! 			    || (variant->lang_index == best->lang_index
! 				&& ((levcmp = level_cmp (variant, best)) == 1
! 				    || (levcmp == 0
! 					&& !strcmp (variant->type_name,
! 						    best->type_name)
! 					&& (find_content_length(neg, variant)
! 					    <
! 				find_content_length(neg, best)))))))))
  	    {
  		best = variant;
  		best_quality = q;


-- 
________________________________________________________________________
Alexei Kosut <akosut@nueva.pvt.k12.ca.us>      The Apache HTTP Server
URL: http://www.nueva.pvt.k12.ca.us/~akosut/   http://www.apache.org/
 
      "War does not determine who is right, only who is left."



Mime
View raw message