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

Side by Side Diff: tests/standalone/src/io/HttpTest.dart

Issue 9602011: Add handling of HTTP header "Expires" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed accidental edit Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 #import("dart:isolate"); 10 #import("dart:isolate");
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 response.outputStream.close(); 117 response.outputStream.close();
118 } 118 }
119 119
120 // Return a 301 with a custom reason phrase. 120 // Return a 301 with a custom reason phrase.
121 void _reasonForMovingHandler(HttpRequest request, HttpResponse response) { 121 void _reasonForMovingHandler(HttpRequest request, HttpResponse response) {
122 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 122 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
123 response.reasonPhrase = "Don't come looking here any more"; 123 response.reasonPhrase = "Don't come looking here any more";
124 response.outputStream.close(); 124 response.outputStream.close();
125 } 125 }
126 126
127 // Set the "Expires" header using the expires property.
128 void _expires1Handler(HttpRequest request, HttpResponse response) {
129 Date date =
130 new Date.withTimeZone(
131 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc());
132 response.expires = date;
133 Expect.equals(date, response.expires);
134 response.outputStream.close();
135 }
136
137 // Set the "Expires" header.
138 void _expires2Handler(HttpRequest request, HttpResponse response) {
139 response.setHeader("Expires", "Fri, 11 Jun 1999 18:46:53 GMT");
140 Date date =
141 new Date.withTimeZone(
142 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc());
143 Expect.equals(date, response.expires);
144 response.outputStream.close();
145 }
146
127 void main() { 147 void main() {
128 // Setup request handlers. 148 // Setup request handlers.
129 _requestHandlers = new Map(); 149 _requestHandlers = new Map();
130 _requestHandlers["/echo"] = (HttpRequest request, HttpResponse response) { 150 _requestHandlers["/echo"] = (HttpRequest request, HttpResponse response) {
131 _echoHandler(request, response); 151 _echoHandler(request, response);
132 }; 152 };
133 _requestHandlers["/0123456789"] = 153 _requestHandlers["/0123456789"] =
134 (HttpRequest request, HttpResponse response) { 154 (HttpRequest request, HttpResponse response) {
135 _zeroToTenHandler(request, response); 155 _zeroToTenHandler(request, response);
136 }; 156 };
137 _requestHandlers["/reasonformoving"] = 157 _requestHandlers["/reasonformoving"] =
138 (HttpRequest request, HttpResponse response) { 158 (HttpRequest request, HttpResponse response) {
139 _reasonForMovingHandler(request, response); 159 _reasonForMovingHandler(request, response);
140 }; 160 };
161 _requestHandlers["/expires1"] =
162 (HttpRequest request, HttpResponse response) {
163 _expires1Handler(request, response);
164 };
165 _requestHandlers["/expires2"] =
166 (HttpRequest request, HttpResponse response) {
167 _expires2Handler(request, response);
168 };
141 169
142 this.port.receive((var message, SendPort replyTo) { 170 this.port.receive((var message, SendPort replyTo) {
143 if (message.isStart) { 171 if (message.isStart) {
144 _server = new HttpServer(); 172 _server = new HttpServer();
145 try { 173 try {
146 _server.listen("127.0.0.1", 0); 174 _server.listen("127.0.0.1", 0);
147 _server.onRequest = (HttpRequest req, HttpResponse rsp) { 175 _server.onRequest = (HttpRequest req, HttpResponse rsp) {
148 _requestReceivedHandler(req, rsp); 176 _requestReceivedHandler(req, rsp);
149 }; 177 };
150 replyTo.send(new TestServerStatus.started(_server.port), null); 178 replyTo.send(new TestServerStatus.started(_server.port), null);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode); 421 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
394 Expect.equals("Don't come looking here any more", response.reasonPhrase); 422 Expect.equals("Don't come looking here any more", response.reasonPhrase);
395 httpClient.shutdown(); 423 httpClient.shutdown();
396 testServerMain.shutdown(); 424 testServerMain.shutdown();
397 }; 425 };
398 }); 426 });
399 testServerMain.start(); 427 testServerMain.start();
400 } 428 }
401 429
402 430
431 void testExpires() {
432 TestServerMain testServerMain = new TestServerMain();
433 testServerMain.setServerStartedHandler((int port) {
434 int responses = 0;
435 HttpClient httpClient = new HttpClient();
436
437 void processResponse(HttpClientResponse response) {
438 Expect.equals(HttpStatus.OK, response.statusCode);
439 Expect.equals("Fri, 11 Jun 1999 18:46:53 GMT",
440 response.headers["expires"]);
441 Expect.equals(
442 new Date.withTimeZone(
443 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc()),
444 response.expires);
445 responses++;
446 if (responses == 2) {
447 httpClient.shutdown();
448 testServerMain.shutdown();
449 }
450 }
451
452 HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/expires1");
453 conn1.onResponse = (HttpClientResponse response) {
454 processResponse(response);
455 };
456 HttpClientConnection conn2 = httpClient.get("127.0.0.1", port, "/expires2");
457 conn2.onResponse = (HttpClientResponse response) {
458 processResponse(response);
459 };
460 });
461
462 testServerMain.start();
463 }
464
465
403 void main() { 466 void main() {
404 testStartStop(); 467 testStartStop();
405 testGET(); 468 testGET();
406 testPOST(true); 469 testPOST(true);
407 testPOST(false); 470 testPOST(false);
408 testReadInto(true); 471 testReadInto(true);
409 testReadInto(false); 472 testReadInto(false);
410 testReadShort(true); 473 testReadShort(true);
411 testReadShort(false); 474 testReadShort(false);
412 test404(); 475 test404();
413 testReasonPhrase(); 476 testReasonPhrase();
477 testExpires();
414 } 478 }
OLDNEW
« runtime/bin/http_utils.dart ('K') | « tests/standalone/src/io/HttpDateTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698