[HTTPCORE-6] When transmitting HTTP messages, re-use Header buffers whenever possible.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@418729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b0357c0348
commit
0af06cd4dd
|
@ -35,8 +35,8 @@ import org.apache.http.cookie.Cookie;
|
|||
import org.apache.http.cookie.CookieOrigin;
|
||||
import org.apache.http.cookie.MalformedCookieException;
|
||||
import org.apache.http.io.CharArrayBuffer;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHeaderElement;
|
||||
import org.apache.http.message.BufferedHeader;
|
||||
import org.apache.http.util.DateParseException;
|
||||
import org.apache.http.util.DateUtils;
|
||||
|
||||
|
@ -133,6 +133,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
|
|||
throw new IllegalArgumentException("Cookie array may not be empty");
|
||||
}
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
|
||||
buffer.append("Cookie: ");
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
Cookie cookie = cookies[i];
|
||||
if (i > 0) {
|
||||
|
@ -145,7 +146,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
|
|||
buffer.append(s);
|
||||
}
|
||||
}
|
||||
return new Header[] { new BasicHeader("Cookie", buffer.toString()) };
|
||||
return new Header[] { new BufferedHeader(buffer) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.apache.http.cookie.Cookie;
|
|||
import org.apache.http.cookie.CookieOrigin;
|
||||
import org.apache.http.cookie.MalformedCookieException;
|
||||
import org.apache.http.io.CharArrayBuffer;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHeaderElement;
|
||||
import org.apache.http.message.BufferedHeader;
|
||||
|
||||
/**
|
||||
* Netscape cookie draft compliant cookie policy
|
||||
|
@ -115,6 +115,7 @@ public class NetscapeDraftSpec extends CookieSpecBase {
|
|||
throw new IllegalArgumentException("Cookie array may not be empty");
|
||||
}
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
|
||||
buffer.append("Cookie: ");
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
Cookie cookie = cookies[i];
|
||||
if (i > 0) {
|
||||
|
@ -127,7 +128,7 @@ public class NetscapeDraftSpec extends CookieSpecBase {
|
|||
buffer.append(s);
|
||||
}
|
||||
}
|
||||
return new Header[] { new BasicHeader("Cookie", buffer.toString()) };
|
||||
return new Header[] { new BufferedHeader(buffer) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.http.cookie.CookieOrigin;
|
|||
import org.apache.http.cookie.CookiePathComparator;
|
||||
import org.apache.http.cookie.MalformedCookieException;
|
||||
import org.apache.http.io.CharArrayBuffer;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BufferedHeader;
|
||||
import org.apache.http.util.DateUtils;
|
||||
|
||||
/**
|
||||
|
@ -146,13 +146,14 @@ public class RFC2109Spec extends CookieSpecBase {
|
|||
}
|
||||
}
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.length);
|
||||
buffer.append("Cookie: ");
|
||||
formatParamAsVer(buffer, "$Version", Integer.toString(version), version);
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
buffer.append("; ");
|
||||
Cookie cookie = cookies[i];
|
||||
formatCookieAsVer(buffer, cookie, version);
|
||||
}
|
||||
return new Header[] {new BasicHeader("Cookie", buffer.toString())};
|
||||
return new Header[] { new BufferedHeader(buffer) };
|
||||
}
|
||||
|
||||
private Header[] doFormatManyHeaders(final Cookie[] cookies) {
|
||||
|
@ -161,10 +162,11 @@ public class RFC2109Spec extends CookieSpecBase {
|
|||
Cookie cookie = cookies[i];
|
||||
int version = cookie.getVersion();
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(40);
|
||||
buffer.append("Cookie: ");
|
||||
formatParamAsVer(buffer, "$Version", Integer.toString(version), version);
|
||||
buffer.append("; ");
|
||||
formatCookieAsVer(buffer, cookies[i], version);
|
||||
headers[i] = new BasicHeader("Cookie", buffer.toString());
|
||||
headers[i] = new BufferedHeader(buffer);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue