| OLD | NEW |
| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Expect.equals(1, request.headers["Host"].length); | 110 Expect.equals(1, request.headers["Host"].length); |
| 111 Expect.equals("www.dartlang.org:1234", request.headers["Host"][0]); | 111 Expect.equals("www.dartlang.org:1234", request.headers["Host"][0]); |
| 112 Expect.equals("www.dartlang.org", request.headers.host); | 112 Expect.equals("www.dartlang.org", request.headers.host); |
| 113 Expect.equals(1234, request.headers.port); | 113 Expect.equals(1234, request.headers.port); |
| 114 response.statusCode = HttpStatus.OK; | 114 response.statusCode = HttpStatus.OK; |
| 115 response.outputStream.close(); | 115 response.outputStream.close(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Set the "Expires" header using the expires property. | 118 // Set the "Expires" header using the expires property. |
| 119 void _expires1Handler(HttpRequest request, HttpResponse response) { | 119 void _expires1Handler(HttpRequest request, HttpResponse response) { |
| 120 Date date = new Date(1999, Date.JUN, 11, 18, 46, 53, 0, isUtc: true); | 120 Date date = new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0); |
| 121 response.headers.expires = date; | 121 response.headers.expires = date; |
| 122 Expect.equals(date, response.headers.expires); | 122 Expect.equals(date, response.headers.expires); |
| 123 response.outputStream.close(); | 123 response.outputStream.close(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Set the "Expires" header. | 126 // Set the "Expires" header. |
| 127 void _expires2Handler(HttpRequest request, HttpResponse response) { | 127 void _expires2Handler(HttpRequest request, HttpResponse response) { |
| 128 response.headers.set("Expires", "Fri, 11 Jun 1999 18:46:53 GMT"); | 128 response.headers.set("Expires", "Fri, 11 Jun 1999 18:46:53 GMT"); |
| 129 Date date = new Date(1999, Date.JUN, 11, 18, 46, 53, 0, isUtc: true); | 129 Date date = new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0); |
| 130 Expect.equals(date, response.headers.expires); | 130 Expect.equals(date, response.headers.expires); |
| 131 response.outputStream.close(); | 131 response.outputStream.close(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void _contentType1Handler(HttpRequest request, HttpResponse response) { | 134 void _contentType1Handler(HttpRequest request, HttpResponse response) { |
| 135 Expect.equals("text/html", request.headers.contentType.value); | 135 Expect.equals("text/html", request.headers.contentType.value); |
| 136 Expect.equals("text", request.headers.contentType.primaryType); | 136 Expect.equals("text", request.headers.contentType.primaryType); |
| 137 Expect.equals("html", request.headers.contentType.subType); | 137 Expect.equals("html", request.headers.contentType.subType); |
| 138 Expect.equals("utf-8", request.headers.contentType.parameters["charset"]); | 138 Expect.equals("utf-8", request.headers.contentType.parameters["charset"]); |
| 139 | 139 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 152 response.headers.set(HttpHeaders.CONTENT_TYPE, | 152 response.headers.set(HttpHeaders.CONTENT_TYPE, |
| 153 "text/html; charset = utf-8"); | 153 "text/html; charset = utf-8"); |
| 154 response.outputStream.close(); | 154 response.outputStream.close(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void _cookie1Handler(HttpRequest request, HttpResponse response) { | 157 void _cookie1Handler(HttpRequest request, HttpResponse response) { |
| 158 // No cookies passed with this request. | 158 // No cookies passed with this request. |
| 159 Expect.equals(0, request.cookies.length); | 159 Expect.equals(0, request.cookies.length); |
| 160 | 160 |
| 161 Cookie cookie1 = new Cookie("name1", "value1"); | 161 Cookie cookie1 = new Cookie("name1", "value1"); |
| 162 Date date = new Date(2014, Date.JAN, 5, 23, 59, 59, 0, isUtc: true); | 162 Date date = new Date.utc(2014, Date.JAN, 5, 23, 59, 59, 0); |
| 163 cookie1.expires = date; | 163 cookie1.expires = date; |
| 164 cookie1.domain = "www.example.com"; | 164 cookie1.domain = "www.example.com"; |
| 165 cookie1.httpOnly = true; | 165 cookie1.httpOnly = true; |
| 166 response.cookies.add(cookie1); | 166 response.cookies.add(cookie1); |
| 167 Cookie cookie2 = new Cookie("name2", "value2"); | 167 Cookie cookie2 = new Cookie("name2", "value2"); |
| 168 cookie2.maxAge = 100; | 168 cookie2.maxAge = 100; |
| 169 cookie2.domain = ".example.com"; | 169 cookie2.domain = ".example.com"; |
| 170 cookie2.path = "/shop"; | 170 cookie2.path = "/shop"; |
| 171 response.cookies.add(cookie2); | 171 response.cookies.add(cookie2); |
| 172 response.outputStream.close(); | 172 response.outputStream.close(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 void testExpires() { | 287 void testExpires() { |
| 288 TestServerMain testServerMain = new TestServerMain(); | 288 TestServerMain testServerMain = new TestServerMain(); |
| 289 testServerMain.setServerStartedHandler((int port) { | 289 testServerMain.setServerStartedHandler((int port) { |
| 290 int responses = 0; | 290 int responses = 0; |
| 291 HttpClient httpClient = new HttpClient(); | 291 HttpClient httpClient = new HttpClient(); |
| 292 | 292 |
| 293 void processResponse(HttpClientResponse response) { | 293 void processResponse(HttpClientResponse response) { |
| 294 Expect.equals(HttpStatus.OK, response.statusCode); | 294 Expect.equals(HttpStatus.OK, response.statusCode); |
| 295 Expect.equals("Fri, 11 Jun 1999 18:46:53 GMT", | 295 Expect.equals("Fri, 11 Jun 1999 18:46:53 GMT", |
| 296 response.headers["expires"][0]); | 296 response.headers["expires"][0]); |
| 297 Expect.equals(new Date(1999, Date.JUN, 11, 18, 46, 53, 0, isUtc: true), | 297 Expect.equals(new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0), |
| 298 response.headers.expires); | 298 response.headers.expires); |
| 299 responses++; | 299 responses++; |
| 300 if (responses == 2) { | 300 if (responses == 2) { |
| 301 httpClient.shutdown(); | 301 httpClient.shutdown(); |
| 302 testServerMain.shutdown(); | 302 testServerMain.shutdown(); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/expires1"); | 306 HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/expires1"); |
| 307 conn1.onResponse = (HttpClientResponse response) { | 307 conn1.onResponse = (HttpClientResponse response) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 int responses = 0; | 369 int responses = 0; |
| 370 HttpClient httpClient = new HttpClient(); | 370 HttpClient httpClient = new HttpClient(); |
| 371 | 371 |
| 372 HttpClientConnection conn1 = | 372 HttpClientConnection conn1 = |
| 373 httpClient.get("127.0.0.1", port, "/cookie1"); | 373 httpClient.get("127.0.0.1", port, "/cookie1"); |
| 374 conn1.onResponse = (HttpClientResponse response) { | 374 conn1.onResponse = (HttpClientResponse response) { |
| 375 Expect.equals(2, response.cookies.length); | 375 Expect.equals(2, response.cookies.length); |
| 376 response.cookies.forEach((cookie) { | 376 response.cookies.forEach((cookie) { |
| 377 if (cookie.name == "name1") { | 377 if (cookie.name == "name1") { |
| 378 Expect.equals("value1", cookie.value); | 378 Expect.equals("value1", cookie.value); |
| 379 Date date = new Date(2014, Date.JAN, 5, 23, 59, 59, 0, isUtc: true); | 379 Date date = new Date.utc(2014, Date.JAN, 5, 23, 59, 59, 0); |
| 380 Expect.equals(date, cookie.expires); | 380 Expect.equals(date, cookie.expires); |
| 381 Expect.equals("www.example.com", cookie.domain); | 381 Expect.equals("www.example.com", cookie.domain); |
| 382 Expect.isTrue(cookie.httpOnly); | 382 Expect.isTrue(cookie.httpOnly); |
| 383 } else if (cookie.name == "name2") { | 383 } else if (cookie.name == "name2") { |
| 384 Expect.equals("value2", cookie.value); | 384 Expect.equals("value2", cookie.value); |
| 385 Expect.equals(100, cookie.maxAge); | 385 Expect.equals(100, cookie.maxAge); |
| 386 Expect.equals(".example.com", cookie.domain); | 386 Expect.equals(".example.com", cookie.domain); |
| 387 Expect.equals("/shop", cookie.path); | 387 Expect.equals("/shop", cookie.path); |
| 388 } else { | 388 } else { |
| 389 Expect.fail("Unexpected cookie"); | 389 Expect.fail("Unexpected cookie"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 404 }); | 404 }); |
| 405 testServerMain.start(); | 405 testServerMain.start(); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void main() { | 408 void main() { |
| 409 testHost(); | 409 testHost(); |
| 410 testExpires(); | 410 testExpires(); |
| 411 testContentType(); | 411 testContentType(); |
| 412 testCookies(); | 412 testCookies(); |
| 413 } | 413 } |
| OLD | NEW |