Branch: Tag:

2001-10-08

2001-10-08 06:08:36 by Per Hedbor <ph@opera.com>

It's not really a good idea to use different charsets for the file contents and it's headers.

Rev: server/protocols/http.pike:1.339

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2001, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.338 2001/10/02 12:20:31 per Exp $"; + constant cvs_version = "$Id: http.pike,v 1.339 2001/10/08 06:08:36 per Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
237:    }   }    - static array(string) output_encode( string what, int|void allow_entities ) + static array(string) output_encode( string what, int|void allow_entities, +  string|void force_charset )   { -  +  if( !force_charset ) +  {    string charset;    function encoder;   
256:    what = encoder( what );    return ({ charset, what });   } +  else +  return ({ +  0, +  Locale.Charset.encoder( (force_charset/"=")[-1] )->feed( what )->drain() +  }); + }      void decode_map( mapping what, function decoder )   {
1737:    heads->Connection = "close";    misc->connection = "close";    } +  if( catch( head_string += Roxen.make_http_headers( heads ) ) ) +  { +  foreach( indices( heads ), string x ) +  if( stringp( heads[x] ) ) +  head_string += x+": "+heads[x]+"\r\n"; +  else if( arrayp( heads[x] ) ) +  foreach( heads[x], string xx ) +  head_string += x+": "+xx+"\r\n"; +  else if( catch { +  head_string += x+": "+(string)heads[x]; +  } ) +  error("Illegal value in headers array! " +  "Expected string or array(string)\n"); +  head_string += "\r\n"; +  }    -  head_string += Roxen.make_http_headers( heads ); -  -  if( strlen( charset ) ) -  head_string = output_encode( head_string, 0 )[1]; +  if( strlen( charset ) || String.width( head_string ) > 8 ) +  head_string = output_encode( head_string, 0, charset )[1];    conf->hsent += strlen(head_string);    }    }