fixes bug 181046 "trim unnecessary bytes from standard request headers."

r=bbaetz sr=bzbarsky
This commit is contained in:
darin%netscape.com 2002-11-20 20:51:12 +00:00
Родитель 8334428257
Коммит 75b79eb6e0
3 изменённых файлов: 15 добавлений и 13 удалений

Просмотреть файл

@ -550,7 +550,7 @@ pref("network.http.sendSecureXSiteReferrer", true);
pref("network.http.redirection-limit", 20);
// Enable http compression: comment this out in case of problems with 1.1
pref("network.http.accept-encoding" ,"gzip, deflate, compress;q=0.9");
pref("network.http.accept-encoding" ,"gzip,deflate,compress;q=0.9");
pref("network.http.pipelining" , false);
pref("network.http.proxy.pipelining", false);

Просмотреть файл

@ -143,4 +143,7 @@ PRTimeToSeconds(PRTime t_usec)
// nsCRT::strdup likes to convert nsnull to ""
#define strdup_if(s) (s ? nsCRT::strdup(s) : nsnull)
// round q-value to one decimal place; return most significant digit as uint.
#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.05) * 10.0))
#endif // nsHttp_h__

Просмотреть файл

@ -1570,10 +1570,10 @@ nsHttpHandler::GetPrefBranch(nsIPrefBranch **result)
* 1.0 amongst the number of languages present.
*
* Ex: passing: "en, ja"
* returns: "en, ja;q=0.50"
* returns: "en,ja;q=0.5"
*
* passing: "en, ja, fr_CA"
* returns: "en, ja;q=0.66, fr_CA;q=0.33"
* returns: "en,ja;q=0.7,fr_CA;q=0.3"
*/
static nsresult
PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLanguages)
@ -1587,7 +1587,6 @@ PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLangua
const char *comma;
PRInt32 available;
o_Accept = nsCRT::strdup(i_AcceptLanguages);
if (nsnull == o_Accept)
return NS_ERROR_OUT_OF_MEMORY;
@ -1616,9 +1615,9 @@ PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLangua
*trim = '\0';
if (*token != '\0') {
comma = n++ != 0 ? ", " : ""; // delimiter if not first item
comma = n++ != 0 ? "," : ""; // delimiter if not first item
if (q < 0.9995)
wrote = PR_snprintf(p2, available, "%s%s;q=0.%02u", comma, token, (unsigned) (q * 100.0));
wrote = PR_snprintf(p2, available, "%s%s;q=0.%01u", comma, token, QVAL_TO_UINT(q));
else
wrote = PR_snprintf(p2, available, "%s%s", comma, token);
q -= dec;
@ -1654,7 +1653,7 @@ nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
* comma delimited and with q values set for each charset in decending order.
*
* Ex: passing: "euc-jp"
* returns: "euc-jp, utf-8;q=0.667, *;q=0.667"
* returns: "euc-jp,utf-8;q=0.6,*;q=0.6"
*
* passing: "UTF-8"
* returns: "UTF-8, *"
@ -1713,9 +1712,9 @@ PrepareAcceptCharsets(const char *i_AcceptCharset, nsACString &o_AcceptCharset)
*trim = '\0';
if (*token != '\0') {
comma = n++ != 0 ? ", " : ""; // delimiter if not first item
comma = n++ != 0 ? "," : ""; // delimiter if not first item
if (q < 0.9995)
wrote = PR_snprintf(p2, available, "%s%s;q=0.%02u", comma, token, (unsigned) (q * 100.0));
wrote = PR_snprintf(p2, available, "%s%s;q=0.%01u", comma, token, QVAL_TO_UINT(q));
else
wrote = PR_snprintf(p2, available, "%s%s", comma, token);
q -= dec;
@ -1725,9 +1724,9 @@ PrepareAcceptCharsets(const char *i_AcceptCharset, nsACString &o_AcceptCharset)
}
}
if (add_utf) {
comma = n++ != 0 ? ", " : ""; // delimiter if not first item
comma = n++ != 0 ? "," : ""; // delimiter if not first item
if (q < 0.9995)
wrote = PR_snprintf(p2, available, "%sutf-8;q=0.%02u", comma, (unsigned) (q * 100.0));
wrote = PR_snprintf(p2, available, "%sutf-8;q=0.%01u", comma, QVAL_TO_UINT(q));
else
wrote = PR_snprintf(p2, available, "%sutf-8", comma);
q -= dec;
@ -1736,7 +1735,7 @@ PrepareAcceptCharsets(const char *i_AcceptCharset, nsACString &o_AcceptCharset)
NS_ASSERTION(available > 0, "allocated string not long enough");
}
if (add_asterisk) {
comma = n++ != 0 ? ", " : ""; // delimiter if not first item
comma = n++ != 0 ? "," : ""; // delimiter if not first item
// keep q of "*" equal to the lowest q value
// in the event of a tie between the q of "*" and a non-wildcard
@ -1744,7 +1743,7 @@ PrepareAcceptCharsets(const char *i_AcceptCharset, nsACString &o_AcceptCharset)
q += dec;
if (q < 0.9995) {
wrote = PR_snprintf(p2, available, "%s*;q=0.%02u", comma, (unsigned) (q * 100.0));
wrote = PR_snprintf(p2, available, "%s*;q=0.%01u", comma, QVAL_TO_UINT(q));
}
else
wrote = PR_snprintf(p2, available, "%s*", comma);