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

Side by Side Diff: runtime/bin/vmservice/server.dart

Issue 1261483003: Stop sniffing user agent in vm service http server (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of vmservice_io; 5 part of vmservice_io;
6 6
7 class WebSocketClient extends Client { 7 class WebSocketClient extends Client {
8 static const int PARSE_ERROR_CODE = 4000; 8 static const int PARSE_ERROR_CODE = 4000;
9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001;
10 static const int NOT_MAP_ERROR_CODE = 4002; 10 static const int NOT_MAP_ERROR_CODE = 4002;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 final int _port; 88 final int _port;
89 89
90 HttpServer _server; 90 HttpServer _server;
91 bool get running => _server != null; 91 bool get running => _server != null;
92 bool _displayMessages = false; 92 bool _displayMessages = false;
93 93
94 Server(this._service, this._ip, this._port) { 94 Server(this._service, this._ip, this._port) {
95 _displayMessages = (_ip != '127.0.0.1' || _port != 8181); 95 _displayMessages = (_ip != '127.0.0.1' || _port != 8181);
96 } 96 }
97 97
98 bool _shouldServeObservatory(HttpRequest request) {
99 if (request.headers['Observatory-Version'] != null) {
100 // Request is already coming from Observatory.
101 return false;
102 }
103 // TODO(johnmccutchan): Test with obscure browsers.
104 if (request.headers.value(HttpHeaders.USER_AGENT).contains('Mozilla')) {
105 // Request is coming from a browser but not Observatory application.
106 // Serve Observatory and let the Observatory make the real request.
107 return true;
108 }
109 // All other user agents are assumed to be textual.
110 return false;
111 }
112
113 void _requestHandler(HttpRequest request) { 98 void _requestHandler(HttpRequest request) {
114 // Allow cross origin requests with 'observatory' header. 99 // Allow cross origin requests with 'observatory' header.
115 request.response.headers.add('Access-Control-Allow-Origin', '*'); 100 request.response.headers.add('Access-Control-Allow-Origin', '*');
116 request.response.headers.add('Access-Control-Allow-Headers', 101 request.response.headers.add('Access-Control-Allow-Headers',
117 'Observatory-Version'); 102 'Observatory-Version');
118 103
119 if (request.method != 'GET') { 104 if (request.method != 'GET') {
120 // Not a GET request. Do nothing. 105 // Not a GET request. Do nothing.
121 request.response.close(); 106 request.response.close();
122 return; 107 return;
123 } 108 }
124 109
125 final String path = 110 final String path =
126 request.uri.path == '/' ? ROOT_REDIRECT_PATH : request.uri.path; 111 request.uri.path == '/' ? ROOT_REDIRECT_PATH : request.uri.path;
127 112
128 if (path == WEBSOCKET_PATH) { 113 if (path == WEBSOCKET_PATH) {
129 WebSocketTransformer.upgrade(request).then((WebSocket webSocket) { 114 WebSocketTransformer.upgrade(request).then((WebSocket webSocket) {
130 new WebSocketClient(webSocket, _service); 115 new WebSocketClient(webSocket, _service);
131 }); 116 });
132 return; 117 return;
133 } 118 }
134 119
135 var resource = Resource.resources[path]; 120 var resource = Resource.resources[path];
136 if (resource == null && _shouldServeObservatory(request)) {
137 resource = Resource.resources[ROOT_REDIRECT_PATH];
138 assert(resource != null);
139 }
140 if (resource != null) { 121 if (resource != null) {
141 // Serving up a static resource (e.g. .css, .html, .png). 122 // Serving up a static resource (e.g. .css, .html, .png).
142 request.response.headers.contentType = 123 request.response.headers.contentType =
143 ContentType.parse(resource.mimeType); 124 ContentType.parse(resource.mimeType);
144 request.response.add(resource.data); 125 request.response.add(resource.data);
145 request.response.close(); 126 request.response.close();
146 return; 127 return;
147 } 128 }
148 var client = new HttpRequestClient(request, _service); 129 var client = new HttpRequestClient(request, _service);
149 var message = new Message.fromUri(client, request.uri); 130 var message = new Message.fromUri(client, request.uri);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); 187 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n');
207 _notifyServerState("", 0); 188 _notifyServerState("", 0);
208 return this; 189 return this;
209 }); 190 });
210 } 191 }
211 192
212 } 193 }
213 194
214 void _notifyServerState(String ip, int port) 195 void _notifyServerState(String ip, int port)
215 native "VMServiceIO_NotifyServerState"; 196 native "VMServiceIO_NotifyServerState";
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698