Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: sdk/lib/io/http_impl.dart

Issue 2618523005: Make HTTP headers use a growing buffer, not a fixed-size 8K one. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_headers.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index a965afa43fe2f18dc4ce986a393e02a64429dd15..40d909d0283213ab071218b464f464e1553833d7 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -574,29 +574,20 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
}
void _writeHeader() {
- Uint8List buffer = new Uint8List(_OUTGOING_BUFFER_SIZE);
- int offset = 0;
-
- void write(List<int> bytes) {
- int len = bytes.length;
- for (int i = 0; i < len; i++) {
- buffer[offset + i] = bytes[i];
- }
- offset += len;
- }
+ BytesBuilder buffer = new _CopyingBytesBuilder(_OUTGOING_BUFFER_SIZE);
// Write status line.
if (headers.protocolVersion == "1.1") {
- write(_Const.HTTP11);
+ buffer.add(_Const.HTTP11);
} else {
- write(_Const.HTTP10);
+ buffer.add(_Const.HTTP10);
}
- buffer[offset++] = _CharCode.SP;
- write(statusCode.toString().codeUnits);
- buffer[offset++] = _CharCode.SP;
- write(reasonPhrase.codeUnits);
- buffer[offset++] = _CharCode.CR;
- buffer[offset++] = _CharCode.LF;
+ buffer.addByte(_CharCode.SP);
+ buffer.add(statusCode.toString().codeUnits);
+ buffer.addByte(_CharCode.SP);
+ buffer.add(reasonPhrase.codeUnits);
+ buffer.addByte(_CharCode.CR);
+ buffer.addByte(_CharCode.LF);
var session = _httpRequest._session;
if (session != null && !session._destroyed) {
@@ -630,10 +621,11 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
headers._finalize();
// Write headers.
- offset = headers._write(buffer, offset);
Søren Gjesse 2017/01/05 14:22:12 Is headers._write still used?
Lasse Reichstein Nielsen 2017/01/13 06:22:59 There is another implementation of _writeHeaders,
- buffer[offset++] = _CharCode.CR;
- buffer[offset++] = _CharCode.LF;
- _outgoing.setHeader(buffer, offset);
+ headers._build(buffer);
+ buffer.addByte(_CharCode.CR);
+ buffer.addByte(_CharCode.LF);
+ Uint8List headerBytes = buffer.takeBytes();
+ _outgoing.setHeader(headerBytes, headerBytes.length);
}
String _findReasonPhrase(int statusCode) {
@@ -1160,7 +1152,6 @@ class _HttpOutgoing implements StreamConsumer<List<int>> {
void setHeader(List<int> data, int length) {
assert(_length == 0);
- assert(data.length == _OUTGOING_BUFFER_SIZE);
_buffer = data;
_length = length;
}
« no previous file with comments | « sdk/lib/io/http_headers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698