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

Side by Side Diff: runtime/bin/http.dart

Issue 10938010: Switch from interfaces to abstract classes in dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 /** 5 /**
6 * HTTP status codes. 6 * HTTP status codes.
7 */ 7 */
8 interface HttpStatus { 8 abstract class HttpStatus {
9 static const int CONTINUE = 100; 9 static const int CONTINUE = 100;
10 static const int SWITCHING_PROTOCOLS = 101; 10 static const int SWITCHING_PROTOCOLS = 101;
11 static const int OK = 200; 11 static const int OK = 200;
12 static const int CREATED = 201; 12 static const int CREATED = 201;
13 static const int ACCEPTED = 202; 13 static const int ACCEPTED = 202;
14 static const int NON_AUTHORITATIVE_INFORMATION = 203; 14 static const int NON_AUTHORITATIVE_INFORMATION = 203;
15 static const int NO_CONTENT = 204; 15 static const int NO_CONTENT = 204;
16 static const int RESET_CONTENT = 205; 16 static const int RESET_CONTENT = 205;
17 static const int PARTIAL_CONTENT = 206; 17 static const int PARTIAL_CONTENT = 206;
18 static const int MULTIPLE_CHOICES = 300; 18 static const int MULTIPLE_CHOICES = 300;
(...skipping 29 matching lines...) Expand all
48 static const int GATEWAY_TIMEOUT = 504; 48 static const int GATEWAY_TIMEOUT = 504;
49 static const int HTTP_VERSION_NOT_SUPPORTED = 505; 49 static const int HTTP_VERSION_NOT_SUPPORTED = 505;
50 // Client generated status code. 50 // Client generated status code.
51 static const int NETWORK_CONNECT_TIMEOUT_ERROR = 599; 51 static const int NETWORK_CONNECT_TIMEOUT_ERROR = 599;
52 } 52 }
53 53
54 54
55 /** 55 /**
56 * HTTP server. 56 * HTTP server.
57 */ 57 */
58 interface HttpServer default _HttpServer { 58 abstract class HttpServer {
59 HttpServer(); 59 factory HttpServer() => new _HttpServer();
60 60
61 /** 61 /**
62 * Start listening for HTTP requests on the specified [host] and 62 * Start listening for HTTP requests on the specified [host] and
63 * [port]. If a [port] of 0 is specified the server will choose an 63 * [port]. If a [port] of 0 is specified the server will choose an
64 * ephemeral port. The optional argument [backlog] can be used to 64 * ephemeral port. The optional argument [backlog] can be used to
65 * specify the listen backlog for the underlying OS listen 65 * specify the listen backlog for the underlying OS listen
66 * setup. See [addRequestHandler] and [defaultRequestHandler] for 66 * setup. See [addRequestHandler] and [defaultRequestHandler] for
67 * information on how incoming HTTP requests are handled. 67 * information on how incoming HTTP requests are handled.
68 */ 68 */
69 void listen(String host, int port, [int backlog]); 69 void listen(String host, int port, [int backlog]);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 116
117 /** 117 /**
118 * Access to the HTTP headers for requests and responses. In some 118 * Access to the HTTP headers for requests and responses. In some
119 * situations the headers will be imutable and the mutating methods 119 * situations the headers will be imutable and the mutating methods
120 * will then throw exceptions. 120 * will then throw exceptions.
121 * 121 *
122 * For all operation on HTTP headers the header name is 122 * For all operation on HTTP headers the header name is
123 * case-insensitive. 123 * case-insensitive.
124 */ 124 */
125 interface HttpHeaders default _HttpHeaders { 125 abstract class HttpHeaders {
126 static const ACCEPT = "Accept"; 126 static const ACCEPT = "Accept";
127 static const ACCEPT_CHARSET = "Accept-Charset"; 127 static const ACCEPT_CHARSET = "Accept-Charset";
128 static const ACCEPT_ENCODING = "Accept-Encoding"; 128 static const ACCEPT_ENCODING = "Accept-Encoding";
129 static const ACCEPT_LANGUAGE = "Accept-Language"; 129 static const ACCEPT_LANGUAGE = "Accept-Language";
130 static const ACCEPT_RANGES = "Accept-Ranges"; 130 static const ACCEPT_RANGES = "Accept-Ranges";
131 static const AGE = "Age"; 131 static const AGE = "Age";
132 static const ALLOW = "Allow"; 132 static const ALLOW = "Allow";
133 static const AUTHORIZATION = "Authorization"; 133 static const AUTHORIZATION = "Authorization";
134 static const CACHE_CONTROL = "Cache-Control"; 134 static const CACHE_CONTROL = "Cache-Control";
135 static const CONNECTION = "Connection"; 135 static const CONNECTION = "Connection";
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 * 347 *
348 * To parse the header values use the [:fromString:] constructor. 348 * To parse the header values use the [:fromString:] constructor.
349 * 349 *
350 * HttpRequest request = ...; 350 * HttpRequest request = ...;
351 * List<String> values = request.headers[HttpHeaders.ACCEPT]; 351 * List<String> values = request.headers[HttpHeaders.ACCEPT];
352 * values.forEach((value) { 352 * values.forEach((value) {
353 * HeaderValue v = new HeaderValue.fromString(value); 353 * HeaderValue v = new HeaderValue.fromString(value);
354 * // Use v.value and v.parameters 354 * // Use v.value and v.parameters
355 * }); 355 * });
356 */ 356 */
357 interface HeaderValue default _HeaderValue { 357 abstract class HeaderValue {
358 /** 358 /**
359 * Creates a new header value object setting the value part. 359 * Creates a new header value object setting the value part.
360 */ 360 */
361 HeaderValue([String value]); 361 factory HeaderValue([String value = ""]) => new _HeaderValue(value);
362 362
363 /** 363 /**
364 * Creates a new header value object from parsing a header value 364 * Creates a new header value object from parsing a header value
365 * string with both value and optional parameters. 365 * string with both value and optional parameters.
366 */ 366 */
367 HeaderValue.fromString(String value); 367 factory HeaderValue.fromString(String value) {
368 return new _HeaderValue.fromString(value);
369 }
368 370
369 /** 371 /**
370 * Gets and sets the header value. 372 * Gets and sets the header value.
371 */ 373 */
372 String value; 374 String value;
373 375
374 /** 376 /**
375 * Gets the map of parameters. 377 * Gets the map of parameters.
376 */ 378 */
377 Map<String, String> get parameters; 379 Map<String, String> get parameters;
378 380
379 /** 381 /**
380 * Returns the formatted string representation in the form: 382 * Returns the formatted string representation in the form:
381 * 383 *
382 * value; parameter1=value1; parameter2=value2 384 * value; parameter1=value1; parameter2=value2
383 */ 385 */
384 String toString(); 386 String toString();
385 } 387 }
386 388
387 389
388 /** 390 /**
389 * Representation of a content type. 391 * Representation of a content type.
390 */ 392 */
391 interface ContentType extends HeaderValue default _ContentType { 393 abstract class ContentType implements HeaderValue {
392 /** 394 /**
393 * Creates a new content type object setting the primary type and 395 * Creates a new content type object setting the primary type and
394 * sub type. If either is not passed their values will be the empty 396 * sub type. If either is not passed their values will be the empty
395 * string. 397 * string.
Søren Gjesse 2012/09/18 09:34:16 No need for documentation of the default values.
Mads Ager (google) 2012/09/18 10:46:39 Done.
396 */ 398 */
397 ContentType([String primaryType, String subType]); 399 factory ContentType([String primaryType = "", String subType = ""]) {
400 return new _ContentType(primaryType, subType);
401 }
398 402
399 /** 403 /**
400 * Creates a new content type object from parsing a Content-Type 404 * Creates a new content type object from parsing a Content-Type
401 * header value. As primary type, sub type and parameter names and 405 * header value. As primary type, sub type and parameter names and
402 * values are not case sensitive all these values will be converted 406 * values are not case sensitive all these values will be converted
403 * to lower case. Parsing this string 407 * to lower case. Parsing this string
404 * 408 *
405 * text/html; charset=utf-8 409 * text/html; charset=utf-8
406 * 410 *
407 * will create a content type object with primary type [:text:], sub 411 * will create a content type object with primary type [:text:], sub
408 * type [:html:] and parameter [:charset:] with value [:utf-8:]. 412 * type [:html:] and parameter [:charset:] with value [:utf-8:].
409 */ 413 */
410 ContentType.fromString(String value); 414 factory ContentType.fromString(String value) {
415 return new _ContentType.fromString(value);
416 }
411 417
412 /** 418 /**
413 * Gets and sets the content type in the form "primaryType/subType". 419 * Gets and sets the content type in the form "primaryType/subType".
414 */ 420 */
415 String value; 421 String value;
416 422
417 /** 423 /**
418 * Gets and sets the primary type. 424 * Gets and sets the primary type.
419 */ 425 */
420 String primaryType; 426 String primaryType;
(...skipping 10 matching lines...) Expand all
431 } 437 }
432 438
433 439
434 /** 440 /**
435 * Representation of a cookie. For cookies received by the server as 441 * Representation of a cookie. For cookies received by the server as
436 * Cookie header values only [:name:] and [:value:] fields will be 442 * Cookie header values only [:name:] and [:value:] fields will be
437 * set. When building a cookie for the Set-Cookie header in the server 443 * set. When building a cookie for the Set-Cookie header in the server
438 * and when receiving cookies in the client as Set-Cookie headers all 444 * and when receiving cookies in the client as Set-Cookie headers all
439 * fields can be used. 445 * fields can be used.
440 */ 446 */
441 interface Cookie default _Cookie { 447 abstract class Cookie {
442 /** 448 /**
443 * Creates a new cookie optionally setting the name and value. 449 * Creates a new cookie optionally setting the name and value.
444 */ 450 */
445 Cookie([String name, String value]); 451 factory Cookie([String name, String value]) => new _Cookie(name, value);
446 452
447 /** 453 /**
448 * Creates a new cookie by parsing a header value from a Set-Cookie 454 * Creates a new cookie by parsing a header value from a Set-Cookie
449 * header. 455 * header.
450 */ 456 */
451 Cookie.fromSetCookieValue(String value); 457 factory Cookie.fromSetCookieValue(String value) {
458 return new _Cookie.fromSetCookieValue(value);
459 }
452 460
453 /** 461 /**
454 * Gets and sets the name. 462 * Gets and sets the name.
455 */ 463 */
456 String name; 464 String name;
457 465
458 /** 466 /**
459 * Gets and sets the value. 467 * Gets and sets the value.
460 */ 468 */
461 String value; 469 String value;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 * string representation can be used for for setting the Cookie or 504 * string representation can be used for for setting the Cookie or
497 * Set-Cookie headers 505 * Set-Cookie headers
498 */ 506 */
499 String toString(); 507 String toString();
500 } 508 }
501 509
502 510
503 /** 511 /**
504 * Http request delivered to the HTTP server callback. 512 * Http request delivered to the HTTP server callback.
505 */ 513 */
506 interface HttpRequest default _HttpRequest { 514 abstract class HttpRequest {
507 /** 515 /**
508 * Returns the content length of the request body. If the size of 516 * Returns the content length of the request body. If the size of
509 * the request body is not known in advance this -1. 517 * the request body is not known in advance this -1.
510 */ 518 */
511 int get contentLength; 519 int get contentLength;
512 520
513 /** 521 /**
514 * Returns the persistent connection state signaled by the client. 522 * Returns the persistent connection state signaled by the client.
515 */ 523 */
516 bool get persistentConnection; 524 bool get persistentConnection;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 * Get information about the client connection. Returns [null] if the socket 574 * Get information about the client connection. Returns [null] if the socket
567 * isn't available. 575 * isn't available.
568 */ 576 */
569 HttpConnectionInfo get connectionInfo; 577 HttpConnectionInfo get connectionInfo;
570 } 578 }
571 579
572 580
573 /** 581 /**
574 * HTTP response to be send back to the client. 582 * HTTP response to be send back to the client.
575 */ 583 */
576 interface HttpResponse default _HttpResponse { 584 abstract class HttpResponse {
577 /** 585 /**
578 * Gets and sets the content length of the response. If the size of 586 * Gets and sets the content length of the response. If the size of
579 * the response is not known in advance set the content length to 587 * the response is not known in advance set the content length to
580 * -1 - which is also the default if not set. 588 * -1 - which is also the default if not set.
581 */ 589 */
582 int contentLength; 590 int contentLength;
583 591
584 /** 592 /**
585 * Gets and sets the status code. Any integer value is accepted, but 593 * Gets and sets the status code. Any integer value is accepted, but
586 * for the official HTTP status codes use the fields from 594 * for the official HTTP status codes use the fields from
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 650
643 /** 651 /**
644 * HTTP client factory. The [HttpClient] handles all the sockets associated 652 * HTTP client factory. The [HttpClient] handles all the sockets associated
645 * with the [HttpClientConnection]s and when the endpoint supports it, it will 653 * with the [HttpClientConnection]s and when the endpoint supports it, it will
646 * try to reuse opened sockets for several requests to support HTTP 1.1 654 * try to reuse opened sockets for several requests to support HTTP 1.1
647 * persistent connections. This means that sockets will be kept open for some 655 * persistent connections. This means that sockets will be kept open for some
648 * time after a requests have completed, unless HTTP procedures indicate that it 656 * time after a requests have completed, unless HTTP procedures indicate that it
649 * must be closed as part of completing the request. Use [:HttpClient.shutdown:] 657 * must be closed as part of completing the request. Use [:HttpClient.shutdown:]
650 * to force close the idle sockets. 658 * to force close the idle sockets.
651 */ 659 */
652 interface HttpClient default _HttpClient { 660 abstract class HttpClient {
653 static const int DEFAULT_HTTP_PORT = 80; 661 static const int DEFAULT_HTTP_PORT = 80;
654 662
655 HttpClient(); 663 factory HttpClient() => new _HttpClient();
656 664
657 /** 665 /**
658 * Opens a HTTP connection. The returned [HttpClientConnection] is 666 * Opens a HTTP connection. The returned [HttpClientConnection] is
659 * used to register callbacks for asynchronous events on the HTTP 667 * used to register callbacks for asynchronous events on the HTTP
660 * connection. The "Host" header for the request will be set to the 668 * connection. The "Host" header for the request will be set to the
661 * value [host]:[port]. This can be overridden through the 669 * value [host]:[port]. This can be overridden through the
662 * HttpClientRequest interface before the request is sent. NOTE if 670 * HttpClientRequest interface before the request is sent. NOTE if
663 * [host] is an IP address this will still be set in the "Host" 671 * [host] is an IP address this will still be set in the "Host"
664 * header. 672 * header.
665 */ 673 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 /** 718 /**
711 * A [HttpClientConnection] is returned by all [HttpClient] methods 719 * A [HttpClientConnection] is returned by all [HttpClient] methods
712 * that initiate a connection to an HTTP server. The handlers will be 720 * that initiate a connection to an HTTP server. The handlers will be
713 * called as the connection state progresses. 721 * called as the connection state progresses.
714 * 722 *
715 * The setting of all handlers is optional. If [onRequest] is not set 723 * The setting of all handlers is optional. If [onRequest] is not set
716 * the request will be send without any additional headers and an 724 * the request will be send without any additional headers and an
717 * empty body. If [onResponse] is not set the response will be read 725 * empty body. If [onResponse] is not set the response will be read
718 * and discarded. 726 * and discarded.
719 */ 727 */
720 interface HttpClientConnection { 728 abstract class HttpClientConnection {
721 /** 729 /**
722 * Sets the handler that is called when the connection is established. 730 * Sets the handler that is called when the connection is established.
723 */ 731 */
724 void set onRequest(void callback(HttpClientRequest request)); 732 void set onRequest(void callback(HttpClientRequest request));
725 733
726 /** 734 /**
727 * Sets callback to be called when the request has been send and 735 * Sets callback to be called when the request has been send and
728 * the response is ready for processing. The callback is called when 736 * the response is ready for processing. The callback is called when
729 * all headers of the response are received and data is ready to be 737 * all headers of the response are received and data is ready to be
730 * received. 738 * received.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 * Get information about the client connection. Returns [null] if the socket 787 * Get information about the client connection. Returns [null] if the socket
780 * isn't available. 788 * isn't available.
781 */ 789 */
782 HttpConnectionInfo get connectionInfo; 790 HttpConnectionInfo get connectionInfo;
783 } 791 }
784 792
785 793
786 /** 794 /**
787 * HTTP request for a client connection. 795 * HTTP request for a client connection.
788 */ 796 */
789 interface HttpClientRequest default _HttpClientRequest { 797 abstract class HttpClientRequest {
790 /** 798 /**
791 * Gets and sets the content length of the request. If the size of 799 * Gets and sets the content length of the request. If the size of
792 * the request is not known in advance set content length to -1, 800 * the request is not known in advance set content length to -1,
793 * which is also the default. 801 * which is also the default.
794 */ 802 */
795 int contentLength; 803 int contentLength;
796 804
797 /** 805 /**
798 * Returns the request headers. 806 * Returns the request headers.
799 */ 807 */
(...skipping 19 matching lines...) Expand all
819 * send. Calling any methods that will change the header after 827 * send. Calling any methods that will change the header after
820 * having retrieved the output stream will throw an exception. 828 * having retrieved the output stream will throw an exception.
821 */ 829 */
822 OutputStream get outputStream; 830 OutputStream get outputStream;
823 } 831 }
824 832
825 833
826 /** 834 /**
827 * HTTP response for a client connection. 835 * HTTP response for a client connection.
828 */ 836 */
829 interface HttpClientResponse default _HttpClientResponse { 837 abstract class HttpClientResponse {
830 /** 838 /**
831 * Returns the status code. 839 * Returns the status code.
832 */ 840 */
833 int get statusCode; 841 int get statusCode;
834 842
835 /** 843 /**
836 * Returns the reason phrase associated with the status code. 844 * Returns the reason phrase associated with the status code.
837 */ 845 */
838 String get reasonPhrase; 846 String get reasonPhrase;
839 847
(...skipping 29 matching lines...) Expand all
869 /** 877 /**
870 * Returns the input stream for the response. This is used to read 878 * Returns the input stream for the response. This is used to read
871 * the response data. 879 * the response data.
872 */ 880 */
873 InputStream get inputStream; 881 InputStream get inputStream;
874 } 882 }
875 883
876 /** 884 /**
877 * Connection information. 885 * Connection information.
878 */ 886 */
879 interface HttpConnectionInfo { 887 abstract class HttpConnectionInfo {
880 String get remoteHost; 888 String get remoteHost;
881 int get remotePort; 889 int get remotePort;
882 int get localPort; 890 int get localPort;
883 } 891 }
884 892
885 893
886 /** 894 /**
887 * Redirect information. 895 * Redirect information.
888 */ 896 */
889 interface RedirectInfo { 897 abstract class RedirectInfo {
890 /** 898 /**
891 * Returns the status code used for the redirect. 899 * Returns the status code used for the redirect.
892 */ 900 */
893 int get statusCode; 901 int get statusCode;
894 902
895 /** 903 /**
896 * Returns the method used for the redirect. 904 * Returns the method used for the redirect.
897 */ 905 */
898 String get method; 906 String get method;
899 907
900 /** 908 /**
901 * Returns the location for the redirect. 909 * Returns the location for the redirect.
902 */ 910 */
903 Uri get location; 911 Uri get location;
904 } 912 }
905 913
906 914
907 /** 915 /**
908 * When detaching a socket from either the [:HttpServer:] or the 916 * When detaching a socket from either the [:HttpServer:] or the
909 * [:HttpClient:] due to a HTTP connection upgrade there might be 917 * [:HttpClient:] due to a HTTP connection upgrade there might be
910 * unparsed data already read from the socket. This unparsed data 918 * unparsed data already read from the socket. This unparsed data
911 * together with the detached socket is returned in an instance of 919 * together with the detached socket is returned in an instance of
912 * this class. 920 * this class.
913 */ 921 */
914 interface DetachedSocket default _DetachedSocket { 922 abstract class DetachedSocket {
915 Socket get socket; 923 Socket get socket;
916 List<int> get unparsedData; 924 List<int> get unparsedData;
917 } 925 }
918 926
919 927
920 class HttpException implements Exception { 928 class HttpException implements Exception {
921 const HttpException([String this.message = ""]); 929 const HttpException([String this.message = ""]);
922 String toString() => "HttpException: $message"; 930 String toString() => "HttpException: $message";
923 final String message; 931 final String message;
924 } 932 }
925 933
926 934
927 class RedirectException extends HttpException { 935 class RedirectException extends HttpException {
928 const RedirectException(String message, 936 const RedirectException(String message,
929 List<RedirectInfo> this.redirects) : super(message); 937 List<RedirectInfo> this.redirects) : super(message);
930 final List<RedirectInfo> redirects; 938 final List<RedirectInfo> redirects;
931 } 939 }
932 940
933 941
934 class RedirectLimitExceededException extends RedirectException { 942 class RedirectLimitExceededException extends RedirectException {
935 const RedirectLimitExceededException(List<RedirectInfo> redirects) 943 const RedirectLimitExceededException(List<RedirectInfo> redirects)
936 : super("Redirect limit exceeded", redirects); 944 : super("Redirect limit exceeded", redirects);
937 } 945 }
938 946
939 947
940 class RedirectLoopException extends RedirectException { 948 class RedirectLoopException extends RedirectException {
941 const RedirectLoopException(List<RedirectInfo> redirects) 949 const RedirectLoopException(List<RedirectInfo> redirects)
942 : super("Redirect loop detected", redirects); 950 : super("Redirect loop detected", redirects);
943 } 951 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698