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

Unified Diff: runtime/bin/vmservice/server.dart

Issue 308673012: Redo LocationManager to use HTML5 History API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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
Index: runtime/bin/vmservice/server.dart
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
index 051ea43ff64eed6d97a83ea3b0b961a65516dae4..4ed6c64e8477cdbcd08893015fea99ddec2ea567 100644
--- a/runtime/bin/vmservice/server.dart
+++ b/runtime/bin/vmservice/server.dart
@@ -80,7 +80,7 @@ class HttpRequestClient extends Client {
class Server {
static const WEBSOCKET_PATH = '/ws';
- String defaultPath = '/index.html';
+ String observatoryPath = '/index.html';
final String ip;
int port;
@@ -89,23 +89,35 @@ class Server {
Server(this.service, this.ip, this.port);
+ bool _shouldServeObservatory(HttpRequest request) {
+ if (request.headers['observatory'] != null) {
+ // Request is already coming from Observatory.
+ return false;
+ }
+ // TODO(johnmccutchan): Test with obscure browsers.
+ if (request.headers.value(HttpHeaders.USER_AGENT).contains('Mozilla')) {
+ // Request is coming from a browser but not Observatory application.
+ // Serve Observatory and let the Observatory make the real request.
+ return true;
+ }
+ // All other user agents are assumed to be textual.
+ return false;
+ }
+
void _requestHandler(HttpRequest request) {
- // Allow cross origin requests.
+ // Allow cross origin requests with 'observatory' header.
request.response.headers.add('Access-Control-Allow-Origin', '*');
+ request.response.headers.add('Access-Control-Allow-Headers', 'observatory');
- final String path =
- request.uri.path == '/' ? defaultPath : request.uri.path;
-
- var resource = Resource.resources[path];
- if (resource != null) {
- // Serving up a static resource (e.g. .css, .html, .png).
- request.response.headers.contentType =
- ContentType.parse(resource.mimeType);
- request.response.add(resource.data);
+ if (request.method != 'GET') {
+ // Not a GET request. Do nothing.
request.response.close();
return;
}
+ final String path =
+ request.uri.path == '/' ? observatoryPath : request.uri.path;
+
if (path == WEBSOCKET_PATH) {
WebSocketTransformer.upgrade(request).then((WebSocket webSocket) {
new WebSocketClient(webSocket, service);
@@ -113,6 +125,19 @@ class Server {
return;
}
+ var resource = Resource.resources[path];
+ if (resource == null && _shouldServeObservatory(request)) {
+ resource = Resource.resources[observatoryPath];
+ assert(resource != null);
+ }
+ if (resource != null) {
+ // Serving up a static resource (e.g. .css, .html, .png).
+ request.response.headers.contentType =
+ ContentType.parse(resource.mimeType);
+ request.response.add(resource.data);
+ request.response.close();
+ return;
+ }
var message = new Message.fromUri(request.uri);
var client = new HttpRequestClient(request, service);
client.onMessage(null, message);

Powered by Google App Engine
This is Rietveld 408576698