| OLD | NEW |
| 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 dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * HTTP status codes. | 8 * HTTP status codes. |
| 9 */ | 9 */ |
| 10 abstract class HttpStatus { | 10 abstract class HttpStatus { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Access to the HTTP headers for requests and responses. In some | 164 * Access to the HTTP headers for requests and responses. In some |
| 165 * situations the headers will be immutable and the mutating methods | 165 * situations the headers will be immutable and the mutating methods |
| 166 * will then throw exceptions. | 166 * will then throw exceptions. |
| 167 * | 167 * |
| 168 * For all operations on HTTP headers the header name is | 168 * For all operations on HTTP headers the header name is |
| 169 * case-insensitive. | 169 * case-insensitive. |
| 170 */ | 170 */ |
| 171 abstract class HttpHeaders { | 171 abstract class HttpHeaders { |
| 172 static const ACCEPT = "Accept"; | 172 static const ACCEPT = "accept"; |
| 173 static const ACCEPT_CHARSET = "Accept-Charset"; | 173 static const ACCEPT_CHARSET = "accept-charset"; |
| 174 static const ACCEPT_ENCODING = "Accept-Encoding"; | 174 static const ACCEPT_ENCODING = "accept-encoding"; |
| 175 static const ACCEPT_LANGUAGE = "Accept-Language"; | 175 static const ACCEPT_LANGUAGE = "accept-language"; |
| 176 static const ACCEPT_RANGES = "Accept-Ranges"; | 176 static const ACCEPT_RANGES = "accept-ranges"; |
| 177 static const AGE = "Age"; | 177 static const AGE = "age"; |
| 178 static const ALLOW = "Allow"; | 178 static const ALLOW = "allow"; |
| 179 static const AUTHORIZATION = "Authorization"; | 179 static const AUTHORIZATION = "authorization"; |
| 180 static const CACHE_CONTROL = "Cache-Control"; | 180 static const CACHE_CONTROL = "cache-control"; |
| 181 static const CONNECTION = "Connection"; | 181 static const CONNECTION = "connection"; |
| 182 static const CONTENT_ENCODING = "Content-Encoding"; | 182 static const CONTENT_ENCODING = "content-encoding"; |
| 183 static const CONTENT_LANGUAGE = "Content-Language"; | 183 static const CONTENT_LANGUAGE = "content-language"; |
| 184 static const CONTENT_LENGTH = "Content-Length"; | 184 static const CONTENT_LENGTH = "content-length"; |
| 185 static const CONTENT_LOCATION = "Content-Location"; | 185 static const CONTENT_LOCATION = "content-location"; |
| 186 static const CONTENT_MD5 = "Content-MD5"; | 186 static const CONTENT_MD5 = "content-md5"; |
| 187 static const CONTENT_RANGE = "Content-Range"; | 187 static const CONTENT_RANGE = "content-range"; |
| 188 static const CONTENT_TYPE = "Content-Type"; | 188 static const CONTENT_TYPE = "content-type"; |
| 189 static const DATE = "Date"; | 189 static const DATE = "date"; |
| 190 static const ETAG = "ETag"; | 190 static const ETAG = "etag"; |
| 191 static const EXPECT = "Expect"; | 191 static const EXPECT = "expect"; |
| 192 static const EXPIRES = "Expires"; | 192 static const EXPIRES = "expires"; |
| 193 static const FROM = "From"; | 193 static const FROM = "from"; |
| 194 static const HOST = "Host"; | 194 static const HOST = "host"; |
| 195 static const IF_MATCH = "If-Match"; | 195 static const IF_MATCH = "if-match"; |
| 196 static const IF_MODIFIED_SINCE = "If-Modified-Since"; | 196 static const IF_MODIFIED_SINCE = "if-modified-since"; |
| 197 static const IF_NONE_MATCH = "If-None-Match"; | 197 static const IF_NONE_MATCH = "if-none-match"; |
| 198 static const IF_RANGE = "If-Range"; | 198 static const IF_RANGE = "if-range"; |
| 199 static const IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; | 199 static const IF_UNMODIFIED_SINCE = "if-unmodified-since"; |
| 200 static const LAST_MODIFIED = "Last-Modified"; | 200 static const LAST_MODIFIED = "last-modified"; |
| 201 static const LOCATION = "Location"; | 201 static const LOCATION = "location"; |
| 202 static const MAX_FORWARDS = "Max-Forwards"; | 202 static const MAX_FORWARDS = "max-forwards"; |
| 203 static const PRAGMA = "Pragma"; | 203 static const PRAGMA = "pragma"; |
| 204 static const PROXY_AUTHENTICATE = "Proxy-Authenticate"; | 204 static const PROXY_AUTHENTICATE = "proxy-authenticate"; |
| 205 static const PROXY_AUTHORIZATION = "Proxy-Authorization"; | 205 static const PROXY_AUTHORIZATION = "proxy-authorization"; |
| 206 static const RANGE = "Range"; | 206 static const RANGE = "range"; |
| 207 static const REFERER = "Referer"; | 207 static const REFERER = "referer"; |
| 208 static const RETRY_AFTER = "Retry-After"; | 208 static const RETRY_AFTER = "retry-after"; |
| 209 static const SERVER = "Server"; | 209 static const SERVER = "server"; |
| 210 static const TE = "TE"; | 210 static const TE = "te"; |
| 211 static const TRAILER = "Trailer"; | 211 static const TRAILER = "trailer"; |
| 212 static const TRANSFER_ENCODING = "Transfer-Encoding"; | 212 static const TRANSFER_ENCODING = "transfer-encoding"; |
| 213 static const UPGRADE = "Upgrade"; | 213 static const UPGRADE = "upgrade"; |
| 214 static const USER_AGENT = "User-Agent"; | 214 static const USER_AGENT = "user-agent"; |
| 215 static const VARY = "Vary"; | 215 static const VARY = "vary"; |
| 216 static const VIA = "Via"; | 216 static const VIA = "via"; |
| 217 static const WARNING = "Warning"; | 217 static const WARNING = "warning"; |
| 218 static const WWW_AUTHENTICATE = "WWW-Authenticate"; | 218 static const WWW_AUTHENTICATE = "www-authenticate"; |
| 219 |
| 220 // Cookie headers from RFC 6265. |
| 221 static const COOKIE = "cookie"; |
| 222 static const SET_COOKIE = "set-cookie"; |
| 219 | 223 |
| 220 static const GENERAL_HEADERS = const [CACHE_CONTROL, | 224 static const GENERAL_HEADERS = const [CACHE_CONTROL, |
| 221 CONNECTION, | 225 CONNECTION, |
| 222 DATE, | 226 DATE, |
| 223 PRAGMA, | 227 PRAGMA, |
| 224 TRAILER, | 228 TRAILER, |
| 225 TRANSFER_ENCODING, | 229 TRANSFER_ENCODING, |
| 226 UPGRADE, | 230 UPGRADE, |
| 227 VIA, | 231 VIA, |
| 228 WARNING]; | 232 WARNING]; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 * Enumerates the headers, applying the function [f] to each | 323 * Enumerates the headers, applying the function [f] to each |
| 320 * header. The header name passed in [:name:] will be all lower | 324 * header. The header name passed in [:name:] will be all lower |
| 321 * case. | 325 * case. |
| 322 */ | 326 */ |
| 323 void forEach(void f(String name, List<String> values)); | 327 void forEach(void f(String name, List<String> values)); |
| 324 | 328 |
| 325 /** | 329 /** |
| 326 * Disables folding for the header named [name] when sending the HTTP | 330 * Disables folding for the header named [name] when sending the HTTP |
| 327 * header. By default, multiple header values are folded into a | 331 * header. By default, multiple header values are folded into a |
| 328 * single header line by separating the values with commas. The | 332 * single header line by separating the values with commas. The |
| 329 * Set-Cookie header has folding disabled by default. | 333 * 'set-cookie' header has folding disabled by default. |
| 330 */ | 334 */ |
| 331 void noFolding(String name); | 335 void noFolding(String name); |
| 332 | 336 |
| 333 /** | 337 /** |
| 334 * Gets and sets the date. The value of this property will | 338 * Gets and sets the date. The value of this property will |
| 335 * reflect the "DateTime" header. | 339 * reflect the 'date' header. |
| 336 */ | 340 */ |
| 337 DateTime date; | 341 DateTime date; |
| 338 | 342 |
| 339 /** | 343 /** |
| 340 * Gets and sets the expiry date. The value of this property will | 344 * Gets and sets the expiry date. The value of this property will |
| 341 * reflect the "Expires" header. | 345 * reflect the 'expires' header. |
| 342 */ | 346 */ |
| 343 DateTime expires; | 347 DateTime expires; |
| 344 | 348 |
| 345 /** | 349 /** |
| 346 * Gets and sets the "if-modified-since" date. The value of this property will | 350 * Gets and sets the "if-modified-since" date. The value of this property will |
| 347 * reflect the "if-modified-since" header. | 351 * reflect the "if-modified-since" header. |
| 348 */ | 352 */ |
| 349 DateTime ifModifiedSince; | 353 DateTime ifModifiedSince; |
| 350 | 354 |
| 351 /** | 355 /** |
| 352 * Gets and sets the host part of the "Host" header for the | 356 * Gets and sets the host part of the 'host' header for the |
| 353 * connection. | 357 * connection. |
| 354 */ | 358 */ |
| 355 String host; | 359 String host; |
| 356 | 360 |
| 357 /** | 361 /** |
| 358 * Gets and sets the port part of the "Host" header for the | 362 * Gets and sets the port part of the 'host' header for the |
| 359 * connection. | 363 * connection. |
| 360 */ | 364 */ |
| 361 int port; | 365 int port; |
| 362 | 366 |
| 363 /** | 367 /** |
| 364 * Gets and sets the content type. Note that the content type in the | 368 * Gets and sets the content type. Note that the content type in the |
| 365 * header will only be updated if this field is set | 369 * header will only be updated if this field is set |
| 366 * directly. Mutating the returned current value will have no | 370 * directly. Mutating the returned current value will have no |
| 367 * effect. | 371 * effect. |
| 368 */ | 372 */ |
| 369 ContentType contentType; | 373 ContentType contentType; |
| 370 } | 374 } |
| 371 | 375 |
| 372 | 376 |
| 373 /** | 377 /** |
| 374 * Representation of a header value in the form: | 378 * Representation of a header value in the form: |
| 375 * | 379 * |
| 376 * [:value; parameter1=value1; parameter2=value2:] | 380 * [:value; parameter1=value1; parameter2=value2:] |
| 377 * | 381 * |
| 378 * [HeaderValue] can be used to conveniently build and parse header | 382 * [HeaderValue] can be used to conveniently build and parse header |
| 379 * values on this form. | 383 * values on this form. |
| 380 * | 384 * |
| 381 * To build an [:Accepts:] header with the value | 385 * To build an [:accepts:] header with the value |
| 382 * | 386 * |
| 383 * text/plain; q=0.3, text/html | 387 * text/plain; q=0.3, text/html |
| 384 * | 388 * |
| 385 * use code like this: | 389 * use code like this: |
| 386 * | 390 * |
| 387 * HttpClientRequest request = ...; | 391 * HttpClientRequest request = ...; |
| 388 * var v = new HeaderValue(); | 392 * var v = new HeaderValue(); |
| 389 * v.value = "text/plain"; | 393 * v.value = "text/plain"; |
| 390 * v.parameters["q"] = "0.3" | 394 * v.parameters["q"] = "0.3" |
| 391 * request.headers.add(HttpHeaders.ACCEPT, v); | 395 * request.headers.add(HttpHeaders.ACCEPT, v); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 /** | 507 /** |
| 504 * Gets and sets the character set. | 508 * Gets and sets the character set. |
| 505 */ | 509 */ |
| 506 String charset; | 510 String charset; |
| 507 } | 511 } |
| 508 | 512 |
| 509 | 513 |
| 510 /** | 514 /** |
| 511 * Representation of a cookie. For cookies received by the server as | 515 * Representation of a cookie. For cookies received by the server as |
| 512 * Cookie header values only [:name:] and [:value:] fields will be | 516 * Cookie header values only [:name:] and [:value:] fields will be |
| 513 * set. When building a cookie for the Set-Cookie header in the server | 517 * set. When building a cookie for the 'set-cookie' header in the server |
| 514 * and when receiving cookies in the client as Set-Cookie headers all | 518 * and when receiving cookies in the client as 'set-cookie' headers all |
| 515 * fields can be used. | 519 * fields can be used. |
| 516 */ | 520 */ |
| 517 abstract class Cookie { | 521 abstract class Cookie { |
| 518 /** | 522 /** |
| 519 * Creates a new cookie optionally setting the name and value. | 523 * Creates a new cookie optionally setting the name and value. |
| 520 */ | 524 */ |
| 521 factory Cookie([String name, String value]) => new _Cookie(name, value); | 525 factory Cookie([String name, String value]) => new _Cookie(name, value); |
| 522 | 526 |
| 523 /** | 527 /** |
| 524 * Creates a new cookie by parsing a header value from a Set-Cookie | 528 * Creates a new cookie by parsing a header value from a 'set-cookie' |
| 525 * header. | 529 * header. |
| 526 */ | 530 */ |
| 527 factory Cookie.fromSetCookieValue(String value) { | 531 factory Cookie.fromSetCookieValue(String value) { |
| 528 return new _Cookie.fromSetCookieValue(value); | 532 return new _Cookie.fromSetCookieValue(value); |
| 529 } | 533 } |
| 530 | 534 |
| 531 /** | 535 /** |
| 532 * Gets and sets the name. | 536 * Gets and sets the name. |
| 533 */ | 537 */ |
| 534 String name; | 538 String name; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 565 bool secure; | 569 bool secure; |
| 566 | 570 |
| 567 /** | 571 /** |
| 568 * Gets and sets whether this cookie is HTTP only. | 572 * Gets and sets whether this cookie is HTTP only. |
| 569 */ | 573 */ |
| 570 bool httpOnly; | 574 bool httpOnly; |
| 571 | 575 |
| 572 /** | 576 /** |
| 573 * Returns the formatted string representation of the cookie. The | 577 * Returns the formatted string representation of the cookie. The |
| 574 * string representation can be used for for setting the Cookie or | 578 * string representation can be used for for setting the Cookie or |
| 575 * Set-Cookie headers | 579 * 'set-cookie' headers |
| 576 */ | 580 */ |
| 577 String toString(); | 581 String toString(); |
| 578 } | 582 } |
| 579 | 583 |
| 580 | 584 |
| 581 /** | 585 /** |
| 582 * Http request delivered to the HTTP server callback. The [HttpRequest] is a | 586 * Http request delivered to the HTTP server callback. The [HttpRequest] is a |
| 583 * [Stream] of the body content of the request. Listen to the body to handle the | 587 * [Stream] of the body content of the request. Listen to the body to handle the |
| 584 * data and be notified once the entire body is received. | 588 * data and be notified once the entire body is received. |
| 585 */ | 589 */ |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 * request. | 692 * request. |
| 689 */ | 693 */ |
| 690 bool persistentConnection; | 694 bool persistentConnection; |
| 691 | 695 |
| 692 /** | 696 /** |
| 693 * Returns the response headers. | 697 * Returns the response headers. |
| 694 */ | 698 */ |
| 695 HttpHeaders get headers; | 699 HttpHeaders get headers; |
| 696 | 700 |
| 697 /** | 701 /** |
| 698 * Cookies to set in the client (in the Set-Cookie header). | 702 * Cookies to set in the client (in the 'set-cookie' header). |
| 699 */ | 703 */ |
| 700 List<Cookie> get cookies; | 704 List<Cookie> get cookies; |
| 701 | 705 |
| 702 /** | 706 /** |
| 703 * Detaches the underlying socket from the HTTP server. When the | 707 * Detaches the underlying socket from the HTTP server. When the |
| 704 * socket is detached the HTTP server will no longer perform any | 708 * socket is detached the HTTP server will no longer perform any |
| 705 * operations on it. | 709 * operations on it. |
| 706 * | 710 * |
| 707 * This is normally used when a HTTP upgrade request is received | 711 * This is normally used when a HTTP upgrade request is received |
| 708 * and the communication should continue with a different protocol. | 712 * and the communication should continue with a different protocol. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 727 * to force close the idle sockets. | 731 * to force close the idle sockets. |
| 728 */ | 732 */ |
| 729 abstract class HttpClient { | 733 abstract class HttpClient { |
| 730 static const int DEFAULT_HTTP_PORT = 80; | 734 static const int DEFAULT_HTTP_PORT = 80; |
| 731 static const int DEFAULT_HTTPS_PORT = 443; | 735 static const int DEFAULT_HTTPS_PORT = 443; |
| 732 | 736 |
| 733 factory HttpClient() => new _HttpClient(); | 737 factory HttpClient() => new _HttpClient(); |
| 734 | 738 |
| 735 /** | 739 /** |
| 736 * Opens a HTTP connection. The returned [HttpClientRequest] is used to | 740 * Opens a HTTP connection. The returned [HttpClientRequest] is used to |
| 737 * fill in the content of the request before sending it. The "Host" header for | 741 * fill in the content of the request before sending it. The 'host' header for |
| 738 * the request will be set to the value [host]:[port]. This can be overridden | 742 * the request will be set to the value [host]:[port]. This can be overridden |
| 739 * through the [HttpClientRequest] interface before the request is sent. | 743 * through the [HttpClientRequest] interface before the request is sent. |
| 740 * NOTE if [host] is an IP address this will still be set in the "Host" | 744 * NOTE if [host] is an IP address this will still be set in the 'host' |
| 741 * header. | 745 * header. |
| 742 */ | 746 */ |
| 743 Future<HttpClientRequest> open(String method, | 747 Future<HttpClientRequest> open(String method, |
| 744 String host, | 748 String host, |
| 745 int port, | 749 int port, |
| 746 String path); | 750 String path); |
| 747 | 751 |
| 748 /** | 752 /** |
| 749 * Opens a HTTP connection. The returned [HttpClientRequest] is used to | 753 * Opens a HTTP connection. The returned [HttpClientRequest] is used to |
| 750 * fill in the content of the request before sending it. The "Host" header for | 754 * fill in the content of the request before sending it. The 'hosth header for |
| 751 * the request will be set to the value [host]:[port]. This can be overridden | 755 * the request will be set to the value [host]:[port]. This can be overridden |
| 752 * through the [HttpClientRequest] interface before the request is sent. | 756 * through the [HttpClientRequest] interface before the request is sent. |
| 753 * NOTE if [host] is an IP address this will still be set in the "Host" | 757 * NOTE if [host] is an IP address this will still be set in the 'host' |
| 754 * header. | 758 * header. |
| 755 */ | 759 */ |
| 756 Future<HttpClientRequest> openUrl(String method, Uri url); | 760 Future<HttpClientRequest> openUrl(String method, Uri url); |
| 757 | 761 |
| 758 /** | 762 /** |
| 759 * Opens a HTTP connection using the GET method. See [open] for | 763 * Opens a HTTP connection using the GET method. See [open] for |
| 760 * details. Using this method to open a HTTP connection will set the | 764 * details. Using this method to open a HTTP connection will set the |
| 761 * content length to 0. | 765 * content length to 0. |
| 762 */ | 766 */ |
| 763 Future<HttpClientRequest> get(String host, int port, String path); | 767 Future<HttpClientRequest> get(String host, int port, String path); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 * which is also the default. | 879 * which is also the default. |
| 876 */ | 880 */ |
| 877 int contentLength; | 881 int contentLength; |
| 878 | 882 |
| 879 /** | 883 /** |
| 880 * Returns the request headers. | 884 * Returns the request headers. |
| 881 */ | 885 */ |
| 882 HttpHeaders get headers; | 886 HttpHeaders get headers; |
| 883 | 887 |
| 884 /** | 888 /** |
| 885 * Cookies to present to the server (in the Cookie header). | 889 * Cookies to present to the server (in the 'cookie' header). |
| 886 */ | 890 */ |
| 887 List<Cookie> get cookies; | 891 List<Cookie> get cookies; |
| 888 | 892 |
| 889 /** | 893 /** |
| 890 * Gets and sets the requested persistent connection state. | 894 * Gets and sets the requested persistent connection state. |
| 891 * The default value is [:true:]. | 895 * The default value is [:true:]. |
| 892 */ | 896 */ |
| 893 bool persistentConnection; | 897 bool persistentConnection; |
| 894 | 898 |
| 895 /** | 899 /** |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 * Detach the underlying socket from the HTTP client. When the | 1017 * Detach the underlying socket from the HTTP client. When the |
| 1014 * socket is detached the HTTP client will no longer perform any | 1018 * socket is detached the HTTP client will no longer perform any |
| 1015 * operations on it. | 1019 * operations on it. |
| 1016 * | 1020 * |
| 1017 * This is normally used when a HTTP upgrade is negotiated and the | 1021 * This is normally used when a HTTP upgrade is negotiated and the |
| 1018 * communication should continue with a different protocol. | 1022 * communication should continue with a different protocol. |
| 1019 */ | 1023 */ |
| 1020 Future<Socket> detachSocket(); | 1024 Future<Socket> detachSocket(); |
| 1021 | 1025 |
| 1022 /** | 1026 /** |
| 1023 * Cookies set by the server (from the Set-Cookie header). | 1027 * Cookies set by the server (from the 'set-cookie' header). |
| 1024 */ | 1028 */ |
| 1025 List<Cookie> get cookies; | 1029 List<Cookie> get cookies; |
| 1026 | 1030 |
| 1027 /** | 1031 /** |
| 1028 * Returns the certificate of the HTTPS server providing the response. | 1032 * Returns the certificate of the HTTPS server providing the response. |
| 1029 * Returns null if the connection is not a secure TLS or SSL connection. | 1033 * Returns null if the connection is not a secure TLS or SSL connection. |
| 1030 */ | 1034 */ |
| 1031 X509Certificate get certificate; | 1035 X509Certificate get certificate; |
| 1032 | 1036 |
| 1033 /** | 1037 /** |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 class RedirectLimitExceededException extends RedirectException { | 1125 class RedirectLimitExceededException extends RedirectException { |
| 1122 const RedirectLimitExceededException(List<RedirectInfo> redirects) | 1126 const RedirectLimitExceededException(List<RedirectInfo> redirects) |
| 1123 : super("Redirect limit exceeded", redirects); | 1127 : super("Redirect limit exceeded", redirects); |
| 1124 } | 1128 } |
| 1125 | 1129 |
| 1126 | 1130 |
| 1127 class RedirectLoopException extends RedirectException { | 1131 class RedirectLoopException extends RedirectException { |
| 1128 const RedirectLoopException(List<RedirectInfo> redirects) | 1132 const RedirectLoopException(List<RedirectInfo> redirects) |
| 1129 : super("Redirect loop detected", redirects); | 1133 : super("Redirect loop detected", redirects); |
| 1130 } | 1134 } |
| OLD | NEW |