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

Unified Diff: runtime/bin/http_impl.dart

Issue 9616004: Add handling of the HTTP header "Host" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_impl.dart
diff --git a/runtime/bin/http_impl.dart b/runtime/bin/http_impl.dart
index 4bc975f9a5828037b58bd27b32ae77cd927ff6dc..0872f6c3ec8b941b93cf1cc269a09734eefe5c31 100644
--- a/runtime/bin/http_impl.dart
+++ b/runtime/bin/http_impl.dart
@@ -58,6 +58,7 @@ class _HttpRequestResponseBase {
int get contentLength() => _contentLength;
bool get keepAlive() => _keepAlive;
+ Map get headers() => _headers;
void _setHeader(String name, String value) {
_headers[name] = value;
@@ -173,7 +174,6 @@ class _HttpRequest extends _HttpRequestResponseBase implements HttpRequest {
String get method() => _method;
String get uri() => _uri;
String get path() => _path;
- Map get headers() => _headers;
String get queryString() => _queryString;
Map get queryParameters() => _queryParameters;
@@ -259,24 +259,24 @@ class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse {
_state = START;
void set contentLength(int contentLength) {
- if (_outputStream != null) return new HttpException("Header already sent");
+ if (_outputStream != null) throw new HttpException("Header already sent");
_contentLength = contentLength;
}
void set keepAlive(bool keepAlive) {
- if (_outputStream != null) return new HttpException("Header already sent");
+ if (_outputStream != null) throw new HttpException("Header already sent");
_keepAlive = keepAlive;
}
int get statusCode() => _statusCode;
void set statusCode(int statusCode) {
- if (_outputStream != null) return new HttpException("Header already sent");
+ if (_outputStream != null) throw new HttpException("Header already sent");
_statusCode = statusCode;
}
String get reasonPhrase() => _findReasonPhrase(_statusCode);
void set reasonPhrase(String reasonPhrase) {
- if (_outputStream != null) return new HttpException("Header already sent");
+ if (_outputStream != null) throw new HttpException("Header already sent");
_reasonPhrase = reasonPhrase;
}
@@ -714,7 +714,36 @@ class _HttpClientRequest
void set contentLength(int contentLength) => _contentLength = contentLength;
void set keepAlive(bool keepAlive) => _keepAlive = keepAlive;
+ Date get host() => _host;
Anders Johnsen 2012/03/06 10:29:57 String
Søren Gjesse 2012/03/06 10:59:05 Oops, forgot to run tests with type check turned o
+ void set host(String host) {
+ _host = host;
+ _updateHostHeader();
+ }
+
+ int get port() => _port;
+ void set port(int port) {
+ _port = port;
+ _updateHostHeader();
+ }
+
void setHeader(String name, String value) {
+ if (_state != START) throw new HttpException("Header already sent");
+ if (name.toLowerCase() == "host") {
+ int pos = value.indexOf(":");
+ if (pos == -1) {
+ _host = value;
+ _port = HttpClient.DEFAULT_HTTP_PORT;
+ } else {
+ _host = value.substring(0, pos);
+ if (pos + 1 == value.length) {
+ _port = HttpClient.DEFAULT_HTTP_PORT;
+ } else {
+ _port = Math.parseInt(value.substring(pos + 1));
+ }
+ }
+ _updateHostHeader();
+ return;
+ }
_setHeader(name, value);
}
@@ -735,6 +764,11 @@ class _HttpClientRequest
return _outputStream;
}
+ _updateHostHeader() {
+ String portPart = _port == HttpClient.DEFAULT_HTTP_PORT ? "" : ":$_port";
+ _setHeader("host", "$host$portPart");
+ }
+
// Delegate functions for the HttpOutputStream implementation.
bool _streamWrite(List<int> buffer, bool copyBuffer) {
return _write(buffer, copyBuffer);
@@ -803,6 +837,8 @@ class _HttpClientRequest
String _method;
String _uri;
+ String _host;
+ int _port;
_HttpClientConnection _connection;
_HttpOutputStream _outputStream;
int _state;
@@ -818,7 +854,6 @@ class _HttpClientResponse
int get statusCode() => _statusCode;
String get reasonPhrase() => _reasonPhrase;
- Map get headers() => _headers;
InputStream get inputStream() {
if (_inputStream == null) {
@@ -1033,6 +1068,8 @@ class _HttpClient implements HttpClient {
_HttpClientConnection connection) {
connection._connectionEstablished(socketConn);
HttpClientRequest request = connection.open(method, path);
+ request.host = host;
+ request.port = port;
if (connection._onRequest != null) {
connection._onRequest(request);
} else {
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698