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

Side by Side Diff: sdk/lib/io/http.dart

Issue 2754013002: Format all dart: library files (Closed)
Patch Set: Format all dart: library files Created 3 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
« no previous file with comments | « sdk/lib/io/file_system_entity.dart ('k') | sdk/lib/io/http_date.dart » ('j') | 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 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static const int INTERNAL_SERVER_ERROR = 500; 46 static const int INTERNAL_SERVER_ERROR = 500;
47 static const int NOT_IMPLEMENTED = 501; 47 static const int NOT_IMPLEMENTED = 501;
48 static const int BAD_GATEWAY = 502; 48 static const int BAD_GATEWAY = 502;
49 static const int SERVICE_UNAVAILABLE = 503; 49 static const int SERVICE_UNAVAILABLE = 503;
50 static const int GATEWAY_TIMEOUT = 504; 50 static const int GATEWAY_TIMEOUT = 504;
51 static const int HTTP_VERSION_NOT_SUPPORTED = 505; 51 static const int HTTP_VERSION_NOT_SUPPORTED = 505;
52 // Client generated status code. 52 // Client generated status code.
53 static const int NETWORK_CONNECT_TIMEOUT_ERROR = 599; 53 static const int NETWORK_CONNECT_TIMEOUT_ERROR = 599;
54 } 54 }
55 55
56
57 /** 56 /**
58 * A server that delivers content, such as web pages, using the HTTP protocol. 57 * A server that delivers content, such as web pages, using the HTTP protocol.
59 * 58 *
60 * The HttpServer is a [Stream] that provides [HttpRequest] objects. Each 59 * The HttpServer is a [Stream] that provides [HttpRequest] objects. Each
61 * HttpRequest has an associated [HttpResponse] object. 60 * HttpRequest has an associated [HttpResponse] object.
62 * The server responds to a request by writing to that HttpResponse object. 61 * The server responds to a request by writing to that HttpResponse object.
63 * The following example shows how to bind an HttpServer to an IPv6 62 * The following example shows how to bind an HttpServer to an IPv6
64 * [InternetAddress] on port 80 (the standard port for HTTP servers) 63 * [InternetAddress] on port 80 (the standard port for HTTP servers)
65 * and how to listen for requests. 64 * and how to listen for requests.
66 * Port 80 is the default HTTP port. However, on most systems accessing 65 * Port 80 is the default HTTP port. However, on most systems accessing
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 * Content-Type: text/plain; charset=utf-8 173 * Content-Type: text/plain; charset=utf-8
175 * X-Frame-Options: SAMEORIGIN 174 * X-Frame-Options: SAMEORIGIN
176 * X-Content-Type-Options: nosniff 175 * X-Content-Type-Options: nosniff
177 * X-XSS-Protection: 1; mode=block 176 * X-XSS-Protection: 1; mode=block
178 * 177 *
179 * If the `Server` header is added here and the `serverHeader` is set as 178 * If the `Server` header is added here and the `serverHeader` is set as
180 * well then the value of `serverHeader` takes precedence. 179 * well then the value of `serverHeader` takes precedence.
181 */ 180 */
182 HttpHeaders get defaultResponseHeaders; 181 HttpHeaders get defaultResponseHeaders;
183 182
184 /** 183 /**
185 * Whether the [HttpServer] should compress the content, if possible. 184 * Whether the [HttpServer] should compress the content, if possible.
186 * 185 *
187 * The content can only be compressed when the response is using 186 * The content can only be compressed when the response is using
188 * chunked Transfer-Encoding and the incoming request has `gzip` 187 * chunked Transfer-Encoding and the incoming request has `gzip`
189 * as an accepted encoding in the Accept-Encoding header. 188 * as an accepted encoding in the Accept-Encoding header.
190 * 189 *
191 * The default value is `false` (compression disabled). 190 * The default value is `false` (compression disabled).
192 * To enable, set `autoCompress` to `true`. 191 * To enable, set `autoCompress` to `true`.
193 */ 192 */
194 bool autoCompress; 193 bool autoCompress;
195 194
196 /** 195 /**
197 * Get or set the timeout used for idle keep-alive connections. If no further 196 * Get or set the timeout used for idle keep-alive connections. If no further
198 * request is seen within [idleTimeout] after the previous request was 197 * request is seen within [idleTimeout] after the previous request was
199 * completed, the connection is dropped. 198 * completed, the connection is dropped.
200 * 199 *
201 * Default is 120 seconds. 200 * Default is 120 seconds.
202 * 201 *
203 * Note that it may take up to `2 * idleTimeout` before a idle connection is 202 * Note that it may take up to `2 * idleTimeout` before a idle connection is
204 * aborted. 203 * aborted.
205 * 204 *
206 * To disable, set [idleTimeout] to `null`. 205 * To disable, set [idleTimeout] to `null`.
207 */ 206 */
208 Duration idleTimeout; 207 Duration idleTimeout;
209 208
210
211 /** 209 /**
212 * Starts listening for HTTP requests on the specified [address] and 210 * Starts listening for HTTP requests on the specified [address] and
213 * [port]. 211 * [port].
214 * 212 *
215 * The [address] can either be a [String] or an 213 * The [address] can either be a [String] or an
216 * [InternetAddress]. If [address] is a [String], [bind] will 214 * [InternetAddress]. If [address] is a [String], [bind] will
217 * perform a [InternetAddress.lookup] and use the first value in the 215 * perform a [InternetAddress.lookup] and use the first value in the
218 * list. To listen on the loopback adapter, which will allow only 216 * list. To listen on the loopback adapter, which will allow only
219 * incoming connections from the local host, use the value 217 * incoming connections from the local host, use the value
220 * [InternetAddress.LOOPBACK_IP_V4] or 218 * [InternetAddress.LOOPBACK_IP_V4] or
(...skipping 16 matching lines...) Expand all
237 * value of [:0:] (the default) a reasonable value will be chosen by 235 * value of [:0:] (the default) a reasonable value will be chosen by
238 * the system. 236 * the system.
239 * 237 *
240 * The optional argument [shared] specifies whether additional HttpServer 238 * The optional argument [shared] specifies whether additional HttpServer
241 * objects can bind to the same combination of `address`, `port` and `v6Only`. 239 * objects can bind to the same combination of `address`, `port` and `v6Only`.
242 * If `shared` is `true` and more `HttpServer`s from this isolate or other 240 * If `shared` is `true` and more `HttpServer`s from this isolate or other
243 * isolates are bound to the port, then the incoming connections will be 241 * isolates are bound to the port, then the incoming connections will be
244 * distributed among all the bound `HttpServer`s. Connections can be 242 * distributed among all the bound `HttpServer`s. Connections can be
245 * distributed over multiple isolates this way. 243 * distributed over multiple isolates this way.
246 */ 244 */
247 static Future<HttpServer> bind(address, 245 static Future<HttpServer> bind(address, int port,
248 int port, 246 {int backlog: 0, bool v6Only: false, bool shared: false}) =>
249 {int backlog: 0, 247 _HttpServer.bind(address, port, backlog, v6Only, shared);
250 bool v6Only: false,
251 bool shared: false})
252 => _HttpServer.bind(address, port, backlog, v6Only, shared);
253 248
254 /** 249 /**
255 * The [address] can either be a [String] or an 250 * The [address] can either be a [String] or an
256 * [InternetAddress]. If [address] is a [String], [bind] will 251 * [InternetAddress]. If [address] is a [String], [bind] will
257 * perform a [InternetAddress.lookup] and use the first value in the 252 * perform a [InternetAddress.lookup] and use the first value in the
258 * list. To listen on the loopback adapter, which will allow only 253 * list. To listen on the loopback adapter, which will allow only
259 * incoming connections from the local host, use the value 254 * incoming connections from the local host, use the value
260 * [InternetAddress.LOOPBACK_IP_V4] or 255 * [InternetAddress.LOOPBACK_IP_V4] or
261 * [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming 256 * [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming
262 * connection from the network use either one of the values 257 * connection from the network use either one of the values
(...skipping 21 matching lines...) Expand all
284 * set using [SecurityContext.setClientAuthorities]. 279 * set using [SecurityContext.setClientAuthorities].
285 * 280 *
286 * The optional argument [shared] specifies whether additional HttpServer 281 * The optional argument [shared] specifies whether additional HttpServer
287 * objects can bind to the same combination of `address`, `port` and `v6Only`. 282 * objects can bind to the same combination of `address`, `port` and `v6Only`.
288 * If `shared` is `true` and more `HttpServer`s from this isolate or other 283 * If `shared` is `true` and more `HttpServer`s from this isolate or other
289 * isolates are bound to the port, then the incoming connections will be 284 * isolates are bound to the port, then the incoming connections will be
290 * distributed among all the bound `HttpServer`s. Connections can be 285 * distributed among all the bound `HttpServer`s. Connections can be
291 * distributed over multiple isolates this way. 286 * distributed over multiple isolates this way.
292 */ 287 */
293 288
294 static Future<HttpServer> bindSecure(address, 289 static Future<HttpServer> bindSecure(
295 int port, 290 address, int port, SecurityContext context,
296 SecurityContext context, 291 {int backlog: 0,
297 {int backlog: 0, 292 bool v6Only: false,
298 bool v6Only: false, 293 bool requestClientCertificate: false,
299 bool requestClientCertificate: false, 294 bool shared: false}) =>
300 bool shared: false}) 295 _HttpServer.bindSecure(address, port, context, backlog, v6Only,
301 => _HttpServer.bindSecure(address, 296 requestClientCertificate, shared);
302 port,
303 context,
304 backlog,
305 v6Only,
306 requestClientCertificate,
307 shared);
308 297
309 /** 298 /**
310 * Attaches the HTTP server to an existing [ServerSocket]. When the 299 * Attaches the HTTP server to an existing [ServerSocket]. When the
311 * [HttpServer] is closed, the [HttpServer] will just detach itself, 300 * [HttpServer] is closed, the [HttpServer] will just detach itself,
312 * closing current connections but not closing [serverSocket]. 301 * closing current connections but not closing [serverSocket].
313 */ 302 */
314 factory HttpServer.listenOn(ServerSocket serverSocket) 303 factory HttpServer.listenOn(ServerSocket serverSocket) =>
315 => new _HttpServer.listenOn(serverSocket); 304 new _HttpServer.listenOn(serverSocket);
316 305
317 /** 306 /**
318 * Permanently stops this [HttpServer] from listening for new 307 * Permanently stops this [HttpServer] from listening for new
319 * connections. This closes the [Stream] of [HttpRequest]s with a 308 * connections. This closes the [Stream] of [HttpRequest]s with a
320 * done event. The returned future completes when the server is 309 * done event. The returned future completes when the server is
321 * stopped. For a server started using [bind] or [bindSecure] this 310 * stopped. For a server started using [bind] or [bindSecure] this
322 * means that the port listened on no longer in use. 311 * means that the port listened on no longer in use.
323 * 312 *
324 * If [force] is `true`, active connections will be closed immediately. 313 * If [force] is `true`, active connections will be closed immediately.
325 */ 314 */
(...skipping 19 matching lines...) Expand all
345 */ 334 */
346 set sessionTimeout(int timeout); 335 set sessionTimeout(int timeout);
347 336
348 /** 337 /**
349 * Returns an [HttpConnectionsInfo] object summarizing the number of 338 * Returns an [HttpConnectionsInfo] object summarizing the number of
350 * current connections handled by the server. 339 * current connections handled by the server.
351 */ 340 */
352 HttpConnectionsInfo connectionsInfo(); 341 HttpConnectionsInfo connectionsInfo();
353 } 342 }
354 343
355
356 /** 344 /**
357 * Summary statistics about an [HttpServer]s current socket connections. 345 * Summary statistics about an [HttpServer]s current socket connections.
358 */ 346 */
359 class HttpConnectionsInfo { 347 class HttpConnectionsInfo {
360 /** 348 /**
361 * Total number of socket connections. 349 * Total number of socket connections.
362 */ 350 */
363 int total = 0; 351 int total = 0;
364 352
365 /** 353 /**
366 * Number of active connections where actual request/response 354 * Number of active connections where actual request/response
367 * processing is active. 355 * processing is active.
368 */ 356 */
369 int active = 0; 357 int active = 0;
370 358
371 /** 359 /**
372 * Number of idle connections held by clients as persistent connections. 360 * Number of idle connections held by clients as persistent connections.
373 */ 361 */
374 int idle = 0; 362 int idle = 0;
375 363
376 /** 364 /**
377 * Number of connections which are preparing to close. Note: These 365 * Number of connections which are preparing to close. Note: These
378 * connections are also part of the [:active:] count as they might 366 * connections are also part of the [:active:] count as they might
379 * still be sending data to the client before finally closing. 367 * still be sending data to the client before finally closing.
380 */ 368 */
381 int closing = 0; 369 int closing = 0;
382 } 370 }
383 371
384
385 /** 372 /**
386 * Headers for HTTP requests and responses. 373 * Headers for HTTP requests and responses.
387 * 374 *
388 * In some situations, headers are immutable: 375 * In some situations, headers are immutable:
389 * 376 *
390 * * HttpRequest and HttpClientResponse always have immutable headers. 377 * * HttpRequest and HttpClientResponse always have immutable headers.
391 * 378 *
392 * * HttpResponse and HttpClientRequest have immutable headers 379 * * HttpResponse and HttpClientRequest have immutable headers
393 * from the moment the body is written to. 380 * from the moment the body is written to.
394 * 381 *
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 static const USER_AGENT = "user-agent"; 444 static const USER_AGENT = "user-agent";
458 static const VARY = "vary"; 445 static const VARY = "vary";
459 static const VIA = "via"; 446 static const VIA = "via";
460 static const WARNING = "warning"; 447 static const WARNING = "warning";
461 static const WWW_AUTHENTICATE = "www-authenticate"; 448 static const WWW_AUTHENTICATE = "www-authenticate";
462 449
463 // Cookie headers from RFC 6265. 450 // Cookie headers from RFC 6265.
464 static const COOKIE = "cookie"; 451 static const COOKIE = "cookie";
465 static const SET_COOKIE = "set-cookie"; 452 static const SET_COOKIE = "set-cookie";
466 453
467 static const GENERAL_HEADERS = const [CACHE_CONTROL, 454 static const GENERAL_HEADERS = const [
468 CONNECTION, 455 CACHE_CONTROL,
469 DATE, 456 CONNECTION,
470 PRAGMA, 457 DATE,
471 TRAILER, 458 PRAGMA,
472 TRANSFER_ENCODING, 459 TRAILER,
473 UPGRADE, 460 TRANSFER_ENCODING,
474 VIA, 461 UPGRADE,
475 WARNING]; 462 VIA,
463 WARNING
464 ];
476 465
477 static const ENTITY_HEADERS = const [ALLOW, 466 static const ENTITY_HEADERS = const [
478 CONTENT_ENCODING, 467 ALLOW,
479 CONTENT_LANGUAGE, 468 CONTENT_ENCODING,
480 CONTENT_LENGTH, 469 CONTENT_LANGUAGE,
481 CONTENT_LOCATION, 470 CONTENT_LENGTH,
482 CONTENT_MD5, 471 CONTENT_LOCATION,
483 CONTENT_RANGE, 472 CONTENT_MD5,
484 CONTENT_TYPE, 473 CONTENT_RANGE,
485 EXPIRES, 474 CONTENT_TYPE,
486 LAST_MODIFIED]; 475 EXPIRES,
476 LAST_MODIFIED
477 ];
487 478
479 static const RESPONSE_HEADERS = const [
480 ACCEPT_RANGES,
481 AGE,
482 ETAG,
483 LOCATION,
484 PROXY_AUTHENTICATE,
485 RETRY_AFTER,
486 SERVER,
487 VARY,
488 WWW_AUTHENTICATE
489 ];
488 490
489 static const RESPONSE_HEADERS = const [ACCEPT_RANGES, 491 static const REQUEST_HEADERS = const [
490 AGE, 492 ACCEPT,
491 ETAG, 493 ACCEPT_CHARSET,
492 LOCATION, 494 ACCEPT_ENCODING,
493 PROXY_AUTHENTICATE, 495 ACCEPT_LANGUAGE,
494 RETRY_AFTER, 496 AUTHORIZATION,
495 SERVER, 497 EXPECT,
496 VARY, 498 FROM,
497 WWW_AUTHENTICATE]; 499 HOST,
498 500 IF_MATCH,
499 static const REQUEST_HEADERS = const [ACCEPT, 501 IF_MODIFIED_SINCE,
500 ACCEPT_CHARSET, 502 IF_NONE_MATCH,
501 ACCEPT_ENCODING, 503 IF_RANGE,
502 ACCEPT_LANGUAGE, 504 IF_UNMODIFIED_SINCE,
503 AUTHORIZATION, 505 MAX_FORWARDS,
504 EXPECT, 506 PROXY_AUTHORIZATION,
505 FROM, 507 RANGE,
506 HOST, 508 REFERER,
507 IF_MATCH, 509 TE,
508 IF_MODIFIED_SINCE, 510 USER_AGENT
509 IF_NONE_MATCH, 511 ];
510 IF_RANGE,
511 IF_UNMODIFIED_SINCE,
512 MAX_FORWARDS,
513 PROXY_AUTHORIZATION,
514 RANGE,
515 REFERER,
516 TE,
517 USER_AGENT];
518 512
519 /** 513 /**
520 * Gets and sets the date. The value of this property will 514 * Gets and sets the date. The value of this property will
521 * reflect the 'date' header. 515 * reflect the 'date' header.
522 */ 516 */
523 DateTime date; 517 DateTime date;
524 518
525 /** 519 /**
526 * Gets and sets the expiry date. The value of this property will 520 * Gets and sets the expiry date. The value of this property will
527 * reflect the 'expires' header. 521 * reflect the 'expires' header.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 560
567 /** 561 /**
568 * Gets and sets the chunked transfer encoding header value. 562 * Gets and sets the chunked transfer encoding header value.
569 */ 563 */
570 bool chunkedTransferEncoding; 564 bool chunkedTransferEncoding;
571 565
572 /** 566 /**
573 * Returns the list of values for the header named [name]. If there 567 * Returns the list of values for the header named [name]. If there
574 * is no header with the provided name, [:null:] will be returned. 568 * is no header with the provided name, [:null:] will be returned.
575 */ 569 */
576 List<String> operator[](String name); 570 List<String> operator [](String name);
577 571
578 /** 572 /**
579 * Convenience method for the value for a single valued header. If 573 * Convenience method for the value for a single valued header. If
580 * there is no header with the provided name, [:null:] will be 574 * there is no header with the provided name, [:null:] will be
581 * returned. If the header has more than one value an exception is 575 * returned. If the header has more than one value an exception is
582 * thrown. 576 * thrown.
583 */ 577 */
584 String value(String name); 578 String value(String name);
585 579
586 /** 580 /**
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 void noFolding(String name); 625 void noFolding(String name);
632 626
633 /** 627 /**
634 * Remove all headers. Some headers have system supplied values and 628 * Remove all headers. Some headers have system supplied values and
635 * for these the system supplied values will still be added to the 629 * for these the system supplied values will still be added to the
636 * collection of values for the header. 630 * collection of values for the header.
637 */ 631 */
638 void clear(); 632 void clear();
639 } 633 }
640 634
641
642 /** 635 /**
643 * Representation of a header value in the form: 636 * Representation of a header value in the form:
644 * 637 *
645 * [:value; parameter1=value1; parameter2=value2:] 638 * [:value; parameter1=value1; parameter2=value2:]
646 * 639 *
647 * [HeaderValue] can be used to conveniently build and parse header 640 * [HeaderValue] can be used to conveniently build and parse header
648 * values on this form. 641 * values on this form.
649 * 642 *
650 * To build an [:accepts:] header with the value 643 * To build an [:accepts:] header with the value
651 * 644 *
(...skipping 23 matching lines...) Expand all
675 */ 668 */
676 factory HeaderValue([String value = "", Map<String, String> parameters]) { 669 factory HeaderValue([String value = "", Map<String, String> parameters]) {
677 return new _HeaderValue(value, parameters); 670 return new _HeaderValue(value, parameters);
678 } 671 }
679 672
680 /** 673 /**
681 * Creates a new header value object from parsing a header value 674 * Creates a new header value object from parsing a header value
682 * string with both value and optional parameters. 675 * string with both value and optional parameters.
683 */ 676 */
684 static HeaderValue parse(String value, 677 static HeaderValue parse(String value,
685 {String parameterSeparator: ";", 678 {String parameterSeparator: ";",
686 String valueSeparator: null, 679 String valueSeparator: null,
687 bool preserveBackslash: false}) { 680 bool preserveBackslash: false}) {
688 return _HeaderValue.parse(value, 681 return _HeaderValue.parse(value,
689 parameterSeparator: parameterSeparator, 682 parameterSeparator: parameterSeparator,
690 valueSeparator: valueSeparator, 683 valueSeparator: valueSeparator,
691 preserveBackslash: preserveBackslash); 684 preserveBackslash: preserveBackslash);
692 } 685 }
693 686
694 /** 687 /**
695 * Gets the header value. 688 * Gets the header value.
696 */ 689 */
697 String get value; 690 String get value;
698 691
699 /** 692 /**
700 * Gets the map of parameters. 693 * Gets the map of parameters.
701 * 694 *
(...skipping 26 matching lines...) Expand all
728 * Sets a callback that will be called when the session is timed out. 721 * Sets a callback that will be called when the session is timed out.
729 */ 722 */
730 void set onTimeout(void callback()); 723 void set onTimeout(void callback());
731 724
732 /** 725 /**
733 * Is true if the session has not been sent to the client yet. 726 * Is true if the session has not been sent to the client yet.
734 */ 727 */
735 bool get isNew; 728 bool get isNew;
736 } 729 }
737 730
738
739 /** 731 /**
740 * Representation of a content type. An instance of [ContentType] is 732 * Representation of a content type. An instance of [ContentType] is
741 * immutable. 733 * immutable.
742 */ 734 */
743 abstract class ContentType implements HeaderValue { 735 abstract class ContentType implements HeaderValue {
744 /** 736 /**
745 * Content type for plain text using UTF-8 encoding. 737 * Content type for plain text using UTF-8 encoding.
746 * 738 *
747 * text/plain; charset=utf-8 739 * text/plain; charset=utf-8
748 */ 740 */
(...skipping 22 matching lines...) Expand all
771 763
772 /** 764 /**
773 * Creates a new content type object setting the primary type and 765 * Creates a new content type object setting the primary type and
774 * sub type. The charset and additional parameters can also be set 766 * sub type. The charset and additional parameters can also be set
775 * using [charset] and [parameters]. If charset is passed and 767 * using [charset] and [parameters]. If charset is passed and
776 * [parameters] contains charset as well the passed [charset] will 768 * [parameters] contains charset as well the passed [charset] will
777 * override the value in parameters. Keys passed in parameters will be 769 * override the value in parameters. Keys passed in parameters will be
778 * converted to lower case. The `charset` entry, whether passed as `charset` 770 * converted to lower case. The `charset` entry, whether passed as `charset`
779 * or in `parameters`, will have its value converted to lower-case. 771 * or in `parameters`, will have its value converted to lower-case.
780 */ 772 */
781 factory ContentType(String primaryType, 773 factory ContentType(String primaryType, String subType,
782 String subType, 774 {String charset, Map<String, String> parameters}) {
783 {String charset, Map<String, String> parameters}) {
784 return new _ContentType(primaryType, subType, charset, parameters); 775 return new _ContentType(primaryType, subType, charset, parameters);
785 } 776 }
786 777
787 /** 778 /**
788 * Creates a new content type object from parsing a Content-Type 779 * Creates a new content type object from parsing a Content-Type
789 * header value. As primary type, sub type and parameter names and 780 * header value. As primary type, sub type and parameter names and
790 * values are not case sensitive all these values will be converted 781 * values are not case sensitive all these values will be converted
791 * to lower case. Parsing this string 782 * to lower case. Parsing this string
792 * 783 *
793 * text/html; charset=utf-8 784 * text/html; charset=utf-8
(...skipping 19 matching lines...) Expand all
813 * Gets the sub type. 804 * Gets the sub type.
814 */ 805 */
815 String get subType; 806 String get subType;
816 807
817 /** 808 /**
818 * Gets the character set. 809 * Gets the character set.
819 */ 810 */
820 String get charset; 811 String get charset;
821 } 812 }
822 813
823
824 /** 814 /**
825 * Representation of a cookie. For cookies received by the server as 815 * Representation of a cookie. For cookies received by the server as
826 * Cookie header values only [:name:] and [:value:] fields will be 816 * Cookie header values only [:name:] and [:value:] fields will be
827 * set. When building a cookie for the 'set-cookie' header in the server 817 * set. When building a cookie for the 'set-cookie' header in the server
828 * and when receiving cookies in the client as 'set-cookie' headers all 818 * and when receiving cookies in the client as 'set-cookie' headers all
829 * fields can be used. 819 * fields can be used.
830 */ 820 */
831 abstract class Cookie { 821 abstract class Cookie {
832 /** 822 /**
833 * Gets and sets the name. 823 * Gets and sets the name.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 876 }
887 877
888 /** 878 /**
889 * Returns the formatted string representation of the cookie. The 879 * Returns the formatted string representation of the cookie. The
890 * string representation can be used for for setting the Cookie or 880 * string representation can be used for for setting the Cookie or
891 * 'set-cookie' headers 881 * 'set-cookie' headers
892 */ 882 */
893 String toString(); 883 String toString();
894 } 884 }
895 885
896
897 /** 886 /**
898 * A server-side object 887 * A server-side object
899 * that contains the content of and information about an HTTP request. 888 * that contains the content of and information about an HTTP request.
900 * 889 *
901 * __Note__: Check out the 890 * __Note__: Check out the
902 * [http_server](http://pub.dartlang.org/packages/http_server) 891 * [http_server](http://pub.dartlang.org/packages/http_server)
903 * package, which makes working with the low-level 892 * package, which makes working with the low-level
904 * dart:io HTTP server subsystem easier. 893 * dart:io HTTP server subsystem easier.
905 * 894 *
906 * `HttpRequest` objects are generated by an [HttpServer], 895 * `HttpRequest` objects are generated by an [HttpServer],
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 * The [HttpResponse] object, used for sending back the response to the 1022 * The [HttpResponse] object, used for sending back the response to the
1034 * client. 1023 * client.
1035 * 1024 *
1036 * If the [contentLength] of the body isn't 0, and the body isn't being read, 1025 * If the [contentLength] of the body isn't 0, and the body isn't being read,
1037 * any write calls on the [HttpResponse] automatically drain the request 1026 * any write calls on the [HttpResponse] automatically drain the request
1038 * body. 1027 * body.
1039 */ 1028 */
1040 HttpResponse get response; 1029 HttpResponse get response;
1041 } 1030 }
1042 1031
1043
1044 /** 1032 /**
1045 * An HTTP response, which returns the headers and data 1033 * An HTTP response, which returns the headers and data
1046 * from the server to the client in response to an HTTP request. 1034 * from the server to the client in response to an HTTP request.
1047 * 1035 *
1048 * Every HttpRequest object provides access to the associated [HttpResponse] 1036 * Every HttpRequest object provides access to the associated [HttpResponse]
1049 * object through the `response` property. 1037 * object through the `response` property.
1050 * The server sends its response to the client by writing to the 1038 * The server sends its response to the client by writing to the
1051 * HttpResponse object. 1039 * HttpResponse object.
1052 * 1040 *
1053 * ## Writing the response 1041 * ## Writing the response
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 */ 1180 */
1193 Future<Socket> detachSocket({bool writeHeaders: true}); 1181 Future<Socket> detachSocket({bool writeHeaders: true});
1194 1182
1195 /** 1183 /**
1196 * Gets information about the client connection. Returns [:null:] if the 1184 * Gets information about the client connection. Returns [:null:] if the
1197 * socket is not available. 1185 * socket is not available.
1198 */ 1186 */
1199 HttpConnectionInfo get connectionInfo; 1187 HttpConnectionInfo get connectionInfo;
1200 } 1188 }
1201 1189
1202
1203 /** 1190 /**
1204 * A client that receives content, such as web pages, from 1191 * A client that receives content, such as web pages, from
1205 * a server using the HTTP protocol. 1192 * a server using the HTTP protocol.
1206 * 1193 *
1207 * HttpClient contains a number of methods to send an [HttpClientRequest] 1194 * HttpClient contains a number of methods to send an [HttpClientRequest]
1208 * to an Http server and receive an [HttpClientResponse] back. 1195 * to an Http server and receive an [HttpClientResponse] back.
1209 * For example, you can use the [get], [getUrl], [post], and [postUrl] methods 1196 * For example, you can use the [get], [getUrl], [post], and [postUrl] methods
1210 * for GET and POST requests, respectively. 1197 * for GET and POST requests, respectively.
1211 * 1198 *
1212 * ## Making a simple GET request: an example 1199 * ## Making a simple GET request: an example
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 * The `Host` header for the request will be set to the value 1348 * The `Host` header for the request will be set to the value
1362 * [host]:[port]. This can be overridden through the 1349 * [host]:[port]. This can be overridden through the
1363 * [HttpClientRequest] interface before the request is sent. NOTE 1350 * [HttpClientRequest] interface before the request is sent. NOTE
1364 * if [host] is an IP address this will still be set in the `Host` 1351 * if [host] is an IP address this will still be set in the `Host`
1365 * header. 1352 * header.
1366 * 1353 *
1367 * For additional information on the sequence of events during an 1354 * For additional information on the sequence of events during an
1368 * HTTP transaction, and the objects returned by the futures, see 1355 * HTTP transaction, and the objects returned by the futures, see
1369 * the overall documentation for the class [HttpClient]. 1356 * the overall documentation for the class [HttpClient].
1370 */ 1357 */
1371 Future<HttpClientRequest> open(String method, 1358 Future<HttpClientRequest> open(
1372 String host, 1359 String method, String host, int port, String path);
1373 int port,
1374 String path);
1375 1360
1376 /** 1361 /**
1377 * Opens a HTTP connection. 1362 * Opens a HTTP connection.
1378 * 1363 *
1379 * The HTTP method is specified in [method] and the URL to use in 1364 * The HTTP method is specified in [method] and the URL to use in
1380 * [url]. 1365 * [url].
1381 * 1366 *
1382 * The `Host` header for the request will be set to the value 1367 * The `Host` header for the request will be set to the value
1383 * [host]:[port]. This can be overridden through the 1368 * [host]:[port]. This can be overridden through the
1384 * [HttpClientRequest] interface before the request is sent. NOTE 1369 * [HttpClientRequest] interface before the request is sent. NOTE
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 * url, {"http_proxy": ..., "no_proxy": ...}); 1587 * url, {"http_proxy": ..., "no_proxy": ...});
1603 * } 1588 * }
1604 * 1589 *
1605 * If a proxy requires authentication it is possible to configure 1590 * If a proxy requires authentication it is possible to configure
1606 * the username and password as well. Use the format 1591 * the username and password as well. Use the format
1607 * [:username:password@hostname:port:] to include the username and 1592 * [:username:password@hostname:port:] to include the username and
1608 * password. Alternatively the API [addProxyCredentials] can be used 1593 * password. Alternatively the API [addProxyCredentials] can be used
1609 * to set credentials for proxies which require authentication. 1594 * to set credentials for proxies which require authentication.
1610 */ 1595 */
1611 static String findProxyFromEnvironment(Uri url, 1596 static String findProxyFromEnvironment(Uri url,
1612 {Map<String, String> environment}) { 1597 {Map<String, String> environment}) {
1613 return _HttpClient._findProxyFromEnvironment(url, environment); 1598 return _HttpClient._findProxyFromEnvironment(url, environment);
1614 } 1599 }
1615 1600
1616 /** 1601 /**
1617 * Sets the function to be called when a proxy is requesting 1602 * Sets the function to be called when a proxy is requesting
1618 * authentication. Information on the proxy in use and the security 1603 * authentication. Information on the proxy in use and the security
1619 * realm for the authentication are passed in the arguments [host], 1604 * realm for the authentication are passed in the arguments [host],
1620 * [port] and [realm]. 1605 * [port] and [realm].
1621 * 1606 *
1622 * The function returns a [Future] which should complete when the 1607 * The function returns a [Future] which should complete when the
1623 * authentication has been resolved. If credentials cannot be 1608 * authentication has been resolved. If credentials cannot be
1624 * provided the [Future] should complete with [:false:]. If 1609 * provided the [Future] should complete with [:false:]. If
1625 * credentials are available the function should add these using 1610 * credentials are available the function should add these using
1626 * [addProxyCredentials] before completing the [Future] with the value 1611 * [addProxyCredentials] before completing the [Future] with the value
1627 * [:true:]. 1612 * [:true:].
1628 * 1613 *
1629 * If the [Future] completes with [:true:] the request will be retried 1614 * If the [Future] completes with [:true:] the request will be retried
1630 * using the updated credentials. Otherwise response processing will 1615 * using the updated credentials. Otherwise response processing will
1631 * continue normally. 1616 * continue normally.
1632 */ 1617 */
1633 set authenticateProxy( 1618 set authenticateProxy(
1634 Future<bool> f(String host, int port, String scheme, String realm)); 1619 Future<bool> f(String host, int port, String scheme, String realm));
1635 1620
1636 /** 1621 /**
1637 * Add credentials to be used for authorizing HTTP proxies. 1622 * Add credentials to be used for authorizing HTTP proxies.
1638 */ 1623 */
1639 void addProxyCredentials(String host, 1624 void addProxyCredentials(
1640 int port, 1625 String host, int port, String realm, HttpClientCredentials credentials);
1641 String realm,
1642 HttpClientCredentials credentials);
1643 1626
1644 /** 1627 /**
1645 * Sets a callback that will decide whether to accept a secure connection 1628 * Sets a callback that will decide whether to accept a secure connection
1646 * with a server certificate that cannot be authenticated by any of our 1629 * with a server certificate that cannot be authenticated by any of our
1647 * trusted root certificates. 1630 * trusted root certificates.
1648 * 1631 *
1649 * When an secure HTTP request if made, using this HttpClient, and the 1632 * When an secure HTTP request if made, using this HttpClient, and the
1650 * server returns a server certificate that cannot be authenticated, the 1633 * server returns a server certificate that cannot be authenticated, the
1651 * callback is called asynchronously with the [X509Certificate] object and 1634 * callback is called asynchronously with the [X509Certificate] object and
1652 * the server's hostname and port. If the value of [badCertificateCallback] 1635 * the server's hostname and port. If the value of [badCertificateCallback]
1653 * is [:null:], the bad certificate is rejected, as if the callback 1636 * is [:null:], the bad certificate is rejected, as if the callback
1654 * returned [:false:] 1637 * returned [:false:]
1655 * 1638 *
1656 * If the callback returns true, the secure connection is accepted and the 1639 * If the callback returns true, the secure connection is accepted and the
1657 * [:Future<HttpClientRequest>:] that was returned from the call making the 1640 * [:Future<HttpClientRequest>:] that was returned from the call making the
1658 * request completes with a valid HttpRequest object. If the callback returns 1641 * request completes with a valid HttpRequest object. If the callback returns
1659 * false, the [:Future<HttpClientRequest>:] completes with an exception. 1642 * false, the [:Future<HttpClientRequest>:] completes with an exception.
1660 * 1643 *
1661 * If a bad certificate is received on a connection attempt, the library calls 1644 * If a bad certificate is received on a connection attempt, the library calls
1662 * the function that was the value of badCertificateCallback at the time 1645 * the function that was the value of badCertificateCallback at the time
1663 * the request is made, even if the value of badCertificateCallback 1646 * the request is made, even if the value of badCertificateCallback
1664 * has changed since then. 1647 * has changed since then.
1665 */ 1648 */
1666 set badCertificateCallback(bool callback(X509Certificate cert, 1649 set badCertificateCallback(
1667 String host, 1650 bool callback(X509Certificate cert, String host, int port));
1668 int port));
1669 1651
1670 /** 1652 /**
1671 * Shut down the HTTP client. If [force] is [:false:] (the default) 1653 * Shut down the HTTP client. If [force] is [:false:] (the default)
1672 * the [:HttpClient:] will be kept alive until all active 1654 * the [:HttpClient:] will be kept alive until all active
1673 * connections are done. If [force] is [:true:] any active 1655 * connections are done. If [force] is [:true:] any active
1674 * connections will be closed to immediately release all 1656 * connections will be closed to immediately release all
1675 * resources. These closed connections will receive an [:onError:] 1657 * resources. These closed connections will receive an [:onError:]
1676 * callback to indicate that the client was shut down. In both cases 1658 * callback to indicate that the client was shut down. In both cases
1677 * trying to establish a new connection after calling [close] 1659 * trying to establish a new connection after calling [close]
1678 * will throw an exception. 1660 * will throw an exception.
1679 */ 1661 */
1680 void close({bool force: false}); 1662 void close({bool force: false});
1681 } 1663 }
1682 1664
1683
1684 /** 1665 /**
1685 * HTTP request for a client connection. 1666 * HTTP request for a client connection.
1686 * 1667 *
1687 * To set up a request, set the headers using the headers property 1668 * To set up a request, set the headers using the headers property
1688 * provided in this class and write the data to the body of the request. 1669 * provided in this class and write the data to the body of the request.
1689 * HttpClientRequest is an [IOSink]. Use the methods from IOSink, 1670 * HttpClientRequest is an [IOSink]. Use the methods from IOSink,
1690 * such as writeCharCode(), to write the body of the HTTP 1671 * such as writeCharCode(), to write the body of the HTTP
1691 * request. When one of the IOSink methods is used for the first 1672 * request. When one of the IOSink methods is used for the first
1692 * time, the request header is sent. Calling any methods that 1673 * time, the request header is sent. Calling any methods that
1693 * change the header after it is sent throws an exception. 1674 * change the header after it is sent throws an exception.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 */ 1782 */
1802 Future<HttpClientResponse> close(); 1783 Future<HttpClientResponse> close();
1803 1784
1804 /** 1785 /**
1805 * Get information about the client connection. Returns [:null:] if the socket 1786 * Get information about the client connection. Returns [:null:] if the socket
1806 * is not available. 1787 * is not available.
1807 */ 1788 */
1808 HttpConnectionInfo get connectionInfo; 1789 HttpConnectionInfo get connectionInfo;
1809 } 1790 }
1810 1791
1811
1812 /** 1792 /**
1813 * HTTP response for a client connection. 1793 * HTTP response for a client connection.
1814 * 1794 *
1815 * The body of a [HttpClientResponse] object is a 1795 * The body of a [HttpClientResponse] object is a
1816 * [Stream] of data from the server. Listen to the body to handle 1796 * [Stream] of data from the server. Listen to the body to handle
1817 * the data and be notified when the entire body is received. 1797 * the data and be notified when the entire body is received.
1818 * 1798 *
1819 * new HttpClient().get('localhost', 80, '/file.txt') 1799 * new HttpClient().get('localhost', 80, '/file.txt')
1820 * .then((HttpClientRequest request) => request.close()) 1800 * .then((HttpClientRequest request) => request.close())
1821 * .then((HttpClientResponse response) { 1801 * .then((HttpClientResponse response) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 * 1866 *
1887 * All headers added to the request will be added to the redirection 1867 * All headers added to the request will be added to the redirection
1888 * request. However, any body sent with the request will not be 1868 * request. However, any body sent with the request will not be
1889 * part of the redirection request. 1869 * part of the redirection request.
1890 * 1870 *
1891 * If [followLoops] is set to [:true:], redirect will follow the redirect, 1871 * If [followLoops] is set to [:true:], redirect will follow the redirect,
1892 * even if the URL was already visited. The default value is [:false:]. 1872 * even if the URL was already visited. The default value is [:false:].
1893 * 1873 *
1894 * [redirect] will ignore [maxRedirects] and will always perform the redirect. 1874 * [redirect] will ignore [maxRedirects] and will always perform the redirect.
1895 */ 1875 */
1896 Future<HttpClientResponse> redirect([String method, 1876 Future<HttpClientResponse> redirect(
1897 Uri url, 1877 [String method, Uri url, bool followLoops]);
1898 bool followLoops]);
1899
1900 1878
1901 /** 1879 /**
1902 * Returns the client response headers. 1880 * Returns the client response headers.
1903 * 1881 *
1904 * The client response headers are immutable. 1882 * The client response headers are immutable.
1905 */ 1883 */
1906 HttpHeaders get headers; 1884 HttpHeaders get headers;
1907 1885
1908 /** 1886 /**
1909 * Detach the underlying socket from the HTTP client. When the 1887 * Detach the underlying socket from the HTTP client. When the
(...skipping 16 matching lines...) Expand all
1926 */ 1904 */
1927 X509Certificate get certificate; 1905 X509Certificate get certificate;
1928 1906
1929 /** 1907 /**
1930 * Gets information about the client connection. Returns [:null:] if the socke t 1908 * Gets information about the client connection. Returns [:null:] if the socke t
1931 * is not available. 1909 * is not available.
1932 */ 1910 */
1933 HttpConnectionInfo get connectionInfo; 1911 HttpConnectionInfo get connectionInfo;
1934 } 1912 }
1935 1913
1936 1914 abstract class HttpClientCredentials {}
1937 abstract class HttpClientCredentials { }
1938
1939 1915
1940 /** 1916 /**
1941 * Represents credentials for basic authentication. 1917 * Represents credentials for basic authentication.
1942 */ 1918 */
1943 abstract class HttpClientBasicCredentials extends HttpClientCredentials { 1919 abstract class HttpClientBasicCredentials extends HttpClientCredentials {
1944 factory HttpClientBasicCredentials(String username, String password) => 1920 factory HttpClientBasicCredentials(String username, String password) =>
1945 new _HttpClientBasicCredentials(username, password); 1921 new _HttpClientBasicCredentials(username, password);
1946 } 1922 }
1947 1923
1948
1949 /** 1924 /**
1950 * Represents credentials for digest authentication. Digest 1925 * Represents credentials for digest authentication. Digest
1951 * authentication is only supported for servers using the MD5 1926 * authentication is only supported for servers using the MD5
1952 * algorithm and quality of protection (qop) of either "none" or 1927 * algorithm and quality of protection (qop) of either "none" or
1953 * "auth". 1928 * "auth".
1954 */ 1929 */
1955 abstract class HttpClientDigestCredentials extends HttpClientCredentials { 1930 abstract class HttpClientDigestCredentials extends HttpClientCredentials {
1956 factory HttpClientDigestCredentials(String username, String password) => 1931 factory HttpClientDigestCredentials(String username, String password) =>
1957 new _HttpClientDigestCredentials(username, password); 1932 new _HttpClientDigestCredentials(username, password);
1958 } 1933 }
1959 1934
1960
1961 /** 1935 /**
1962 * Information about an [HttpRequest], [HttpResponse], [HttpClientRequest], or 1936 * Information about an [HttpRequest], [HttpResponse], [HttpClientRequest], or
1963 * [HttpClientResponse] connection. 1937 * [HttpClientResponse] connection.
1964 */ 1938 */
1965 abstract class HttpConnectionInfo { 1939 abstract class HttpConnectionInfo {
1966 InternetAddress get remoteAddress; 1940 InternetAddress get remoteAddress;
1967 int get remotePort; 1941 int get remotePort;
1968 int get localPort; 1942 int get localPort;
1969 } 1943 }
1970 1944
1971
1972 /** 1945 /**
1973 * Redirect information. 1946 * Redirect information.
1974 */ 1947 */
1975 abstract class RedirectInfo { 1948 abstract class RedirectInfo {
1976 /** 1949 /**
1977 * Returns the status code used for the redirect. 1950 * Returns the status code used for the redirect.
1978 */ 1951 */
1979 int get statusCode; 1952 int get statusCode;
1980 1953
1981 /** 1954 /**
1982 * Returns the method used for the redirect. 1955 * Returns the method used for the redirect.
1983 */ 1956 */
1984 String get method; 1957 String get method;
1985 1958
1986 /** 1959 /**
1987 * Returns the location for the redirect. 1960 * Returns the location for the redirect.
1988 */ 1961 */
1989 Uri get location; 1962 Uri get location;
1990 } 1963 }
1991 1964
1992
1993 /** 1965 /**
1994 * When detaching a socket from either the [:HttpServer:] or the 1966 * When detaching a socket from either the [:HttpServer:] or the
1995 * [:HttpClient:] due to a HTTP connection upgrade there might be 1967 * [:HttpClient:] due to a HTTP connection upgrade there might be
1996 * unparsed data already read from the socket. This unparsed data 1968 * unparsed data already read from the socket. This unparsed data
1997 * together with the detached socket is returned in an instance of 1969 * together with the detached socket is returned in an instance of
1998 * this class. 1970 * this class.
1999 */ 1971 */
2000 abstract class DetachedSocket { 1972 abstract class DetachedSocket {
2001 Socket get socket; 1973 Socket get socket;
2002 List<int> get unparsedData; 1974 List<int> get unparsedData;
2003 } 1975 }
2004 1976
2005
2006 class HttpException implements IOException { 1977 class HttpException implements IOException {
2007 final String message; 1978 final String message;
2008 final Uri uri; 1979 final Uri uri;
2009 1980
2010 const HttpException(this.message, {this.uri}); 1981 const HttpException(this.message, {this.uri});
2011 1982
2012 String toString() { 1983 String toString() {
2013 var b = new StringBuffer() 1984 var b = new StringBuffer()..write('HttpException: ')..write(message);
2014 ..write('HttpException: ')
2015 ..write(message);
2016 if (uri != null) { 1985 if (uri != null) {
2017 b.write(', uri = $uri'); 1986 b.write(', uri = $uri');
2018 } 1987 }
2019 return b.toString(); 1988 return b.toString();
2020 } 1989 }
2021 } 1990 }
2022 1991
2023
2024 class RedirectException implements HttpException { 1992 class RedirectException implements HttpException {
2025 final String message; 1993 final String message;
2026 final List<RedirectInfo> redirects; 1994 final List<RedirectInfo> redirects;
2027 1995
2028 const RedirectException(this.message, this.redirects); 1996 const RedirectException(this.message, this.redirects);
2029 1997
2030 String toString() => "RedirectException: $message"; 1998 String toString() => "RedirectException: $message";
2031 1999
2032 Uri get uri => redirects.last.location; 2000 Uri get uri => redirects.last.location;
2033 } 2001 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_system_entity.dart ('k') | sdk/lib/io/http_date.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698