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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 /** | 689 /** |
690 * Returns the formatted string representation of the cookie. The | 690 * Returns the formatted string representation of the cookie. The |
691 * string representation can be used for for setting the Cookie or | 691 * string representation can be used for for setting the Cookie or |
692 * 'set-cookie' headers | 692 * 'set-cookie' headers |
693 */ | 693 */ |
694 String toString(); | 694 String toString(); |
695 } | 695 } |
696 | 696 |
697 | 697 |
698 /** | 698 /** |
699 * Http request delivered to the HTTP server callback. The [HttpRequest] is a | 699 * A server-side object |
700 * [Stream] of the body content of the request. Listen to the body to handle the | 700 * that contains the content of and information about an HTTP request. |
701 * | |
702 * __Note__: Check out the | |
703 * [http_server](http://pub.dartlang.org/packages/http_server) | |
704 * package, which makes working with the low-level | |
705 * dart:io HTTP server subsystem easier. | |
706 * | |
707 * HttpRequest objects are generated by an [HttpServer], | |
708 * which listens for HTTP requests on a specific host and port. | |
709 * For each request received, the HttpServer, which is a [Stream], | |
710 * generates an HttpRequest object and adds it to the stream. | |
711 * | |
712 * An HttpRequest object delivers the body content of the request | |
713 * as a stream of code units. | |
Søren Gjesse
2013/08/27 12:38:13
code units -> bytes
| |
714 * The object also contains information about the request, | |
715 * such as the method, URI, and headers. | |
716 * | |
717 * In the following code, an HttpServer listens | |
718 * for HTTP requests and, within the callback function, | |
719 * uses the HttpRequest object's `method` property to dispatch requests. | |
720 * | |
721 * final HOST = InternetAddress.LOOPBACK_IP_V4; | |
722 * final PORT = 4040; | |
723 * | |
724 * HttpServer.bind(HOST, PORT).then((_server) { | |
725 * _server.listen((HttpRequest request) { | |
726 * switch (request.method) { | |
727 * case 'GET': | |
728 * handleGetRequest(request); | |
729 * break; | |
730 * case 'POST': | |
731 * ... | |
732 * } | |
733 * }, | |
734 * onError: handleError); // listen() failed. | |
735 * }).catchError(handleError); | |
736 * | |
737 * Listen to the HttpRequest stream to handle the | |
701 * data and be notified once the entire body is received. | 738 * data and be notified once the entire body is received. |
739 * An HttpRequest object contains an [HttpResponse] object, | |
740 * to which the server can write its response. | |
741 * For example, here's a skeletal callback function | |
742 * that responds to a request: | |
743 * | |
744 * void handleGetRequest(HttpRequest req) { | |
745 * HttpResponse res = req.response; | |
746 * var body = []; | |
747 * req.listen((List<int> buffer) => body.add(buffer), | |
748 * onDone: () { | |
749 * res.write('Received ${body.length} for request '); | |
750 * res.write(' ${req.method}: ${req.uri.path}'); | |
751 * res.close(); | |
752 * }, | |
753 * onError: handleError); | |
754 * } | |
702 */ | 755 */ |
703 abstract class HttpRequest implements Stream<List<int>> { | 756 abstract class HttpRequest implements Stream<List<int>> { |
704 /** | 757 /** |
705 * Returns the content length of the request body. If the size of | 758 * The content length of the request body (read-only). |
706 * the request body is not known in advance this -1. | 759 * |
760 * If the size of the request body is not known in advance, | |
761 * this value is -1. | |
707 */ | 762 */ |
708 int get contentLength; | 763 int get contentLength; |
709 | 764 |
710 /** | 765 /** |
711 * Returns the method for the request. | 766 * The method, such as 'GET' or 'POST', for the request (read-only). |
712 */ | 767 */ |
713 String get method; | 768 String get method; |
714 | 769 |
715 /** | 770 /** |
716 * Returns the URI for the request. This provides access to the | 771 * The URI for the request (read-only). |
717 * path, query string and fragment identifier for the request. | 772 * |
773 * This provides access to the | |
774 * path, query string, and fragment identifier for the request. | |
718 */ | 775 */ |
719 Uri get uri; | 776 Uri get uri; |
720 | 777 |
721 /** | 778 /** |
722 * Returns the request headers. | 779 * The request headers (read-only). |
723 */ | 780 */ |
724 HttpHeaders get headers; | 781 HttpHeaders get headers; |
725 | 782 |
726 /** | 783 /** |
727 * Returns the cookies in the request (from the Cookie headers). | 784 * The cookies in the request, from the Cookie headers (read-only). |
728 */ | 785 */ |
729 List<Cookie> get cookies; | 786 List<Cookie> get cookies; |
730 | 787 |
731 /** | 788 /** |
732 * Returns the persistent connection state signaled by the client. | 789 * The persistent connection state signaled by the client (read-only). |
733 */ | 790 */ |
734 bool get persistentConnection; | 791 bool get persistentConnection; |
735 | 792 |
736 /** | 793 /** |
737 * Returns the client certificate of the client making the request. | 794 * The client certificate of the client making the request (read-only). |
738 * Returns null if the connection is not a secure TLS or SSL connection, | 795 * |
796 * This value is null if the connection is not a secure TLS or SSL connection, | |
739 * or if the server does not request a client certificate, or if the client | 797 * or if the server does not request a client certificate, or if the client |
740 * does not provide one. | 798 * does not provide one. |
741 */ | 799 */ |
742 X509Certificate get certificate; | 800 X509Certificate get certificate; |
743 | 801 |
744 /** | 802 /** |
745 * Gets the session for the given request. If the session is | 803 * The session for the given request (read-only). |
746 * being initialized by this call, [:isNew:] will be true for the returned | 804 * |
805 * If the session is | |
806 * being initialized by this call, [:isNew:] is true for the returned | |
747 * session. | 807 * session. |
748 * See [HttpServer.sessionTimeout] on how to change default timeout. | 808 * See [HttpServer.sessionTimeout] on how to change default timeout. |
749 */ | 809 */ |
750 HttpSession get session; | 810 HttpSession get session; |
751 | 811 |
752 /** | 812 /** |
753 * Returns the HTTP protocol version used in the request. This will | 813 * The HTTP protocol version used in the request, |
754 * be "1.0" or "1.1". | 814 * either "1.0" or "1.1" (read-only). |
755 */ | 815 */ |
756 String get protocolVersion; | 816 String get protocolVersion; |
757 | 817 |
758 /** | 818 /** |
759 * Gets information about the client connection. Returns [null] if the socket | 819 * Information about the client connection (read-only). |
760 * is not available. | 820 * |
821 * Returns [null] if the socket is not available. | |
761 */ | 822 */ |
762 HttpConnectionInfo get connectionInfo; | 823 HttpConnectionInfo get connectionInfo; |
763 | 824 |
764 /** | 825 /** |
765 * Gets the [HttpResponse] object, used for sending back the response to the | 826 * The [HttpResponse] object, used for sending back the response to the |
766 * client. | 827 * client (read-only). |
767 * | 828 * |
768 * If the [contentLength] of the body isn't 0, and the body isn't being read, | 829 * If the [contentLength] of the body isn't 0, and the body isn't being read, |
769 * any write calls on the [HttpResponse] will automatically drain the request | 830 * any write calls on the [HttpResponse] automatically drain the request |
770 * body. | 831 * body. |
771 */ | 832 */ |
772 HttpResponse get response; | 833 HttpResponse get response; |
773 } | 834 } |
774 | 835 |
775 | 836 |
776 /** | 837 /** |
777 * An [HttpResponse] represents the headers and data to be returned to | 838 * An [HttpResponse] represents the headers and data to be returned to |
778 * a client in response to an HTTP request. | 839 * a client in response to an HTTP request. |
779 * | 840 * |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1522 final String message; | 1583 final String message; |
1523 final List<RedirectInfo> redirects; | 1584 final List<RedirectInfo> redirects; |
1524 | 1585 |
1525 const RedirectException(String this.message, | 1586 const RedirectException(String this.message, |
1526 List<RedirectInfo> this.redirects); | 1587 List<RedirectInfo> this.redirects); |
1527 | 1588 |
1528 String toString() => "RedirectException: $message"; | 1589 String toString() => "RedirectException: $message"; |
1529 | 1590 |
1530 Uri get uri => redirects.last.location; | 1591 Uri get uri => redirects.last.location; |
1531 } | 1592 } |
OLD | NEW |