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 * An [HttpServer] listens for HTTP requests on a specific host and port. | |
Søren Gjesse
2013/08/27 09:11:10
This section mentions a callback function. I think
mem
2013/08/27 12:31:56
Done.
| |
703 * When a request comes in, the server's callback function receives | |
704 * an HttpRequest object—a [Stream] that delivers the body content | |
705 * of the request. | |
706 * The object also contains information about the request, | |
707 * such as the method, URI, and headers, about the request. | |
Kathy Walrath
2013/08/27 08:23:11
strike ", about the request"
mem
2013/08/27 12:31:56
Done.
| |
708 * The following code listens | |
709 * for HTTP requests and, within the callback function, | |
710 * uses the HttpRequest object's [method] property to triage requests. | |
Søren Gjesse
2013/08/27 09:11:10
Maybe change triage to dispatch.
mem
2013/08/27 12:31:56
Done.
| |
711 * | |
712 * final HOST = '127.0.0.1'; // localhost. | |
Søren Gjesse
2013/08/27 09:11:10
Use InternetAddress.LOOPBACK_IP_V4 instead of '127
mem
2013/08/27 12:31:56
Done.
| |
713 * final PORT = 4040; | |
714 * | |
715 * HttpServer.bind(HOST, PORT).then((_server) { | |
716 * _server.listen((HttpRequest request) { | |
717 * switch (request.method) { | |
718 * case 'GET': | |
719 * handleGetRequest(request); | |
720 * break; | |
721 * case 'POST': | |
722 * ... | |
723 * } | |
724 * }, | |
725 * onError: printError); // listen() failed. | |
726 * }, onError: printError); // then() failed. | |
Søren Gjesse
2013/08/27 09:11:10
Future.then does not have an optional named onErro
mem
2013/08/27 12:31:56
Done.
| |
727 * | |
728 * Listen to the HttpRequest to handle the | |
701 * data and be notified once the entire body is received. | 729 * data and be notified once the entire body is received. |
730 * The HttpRequest object contains an [HttpResponse] object, | |
731 * to which the server can write its response. | |
732 * For example, here's a skeletal callback function for a request: | |
733 * | |
734 * void handleGetRequest(HttpRequest req) { | |
735 * HttpResponse res = req.response; // Send the response via this object. | |
736 * print('${req.method}: ${req.uri.path}'); // Print the method and URI. | |
Søren Gjesse
2013/08/27 09:11:10
I don't think we should use pint in the examples.
mem
2013/08/27 12:31:56
Done.
| |
737 * | |
738 * req.listen((List<int> buffer) { // Listen for the request content. | |
739 * // buffer contains the content of the request. | |
Søren Gjesse
2013/08/27 09:11:10
As this is a stream the buffer might not contain a
mem
2013/08/27 12:31:56
Done.
| |
740 * ... | |
741 * res.write( ... ); | |
742 * }, | |
743 * onError: printError); | |
744 * } | |
702 */ | 745 */ |
703 abstract class HttpRequest implements Stream<List<int>> { | 746 abstract class HttpRequest implements Stream<List<int>> { |
704 /** | 747 /** |
705 * Returns the content length of the request body. If the size of | 748 * The content length of the request body (read-only). |
706 * the request body is not known in advance this -1. | 749 * |
750 * If the size of the request body is not known in advance, | |
751 * this value is -1. | |
707 */ | 752 */ |
708 int get contentLength; | 753 int get contentLength; |
709 | 754 |
710 /** | 755 /** |
711 * Returns the method for the request. | 756 * The method, such as 'GET' or 'POST', for the request (read-only). |
712 */ | 757 */ |
713 String get method; | 758 String get method; |
714 | 759 |
715 /** | 760 /** |
716 * Returns the URI for the request. This provides access to the | 761 * The URI for the request (read-only). |
717 * path, query string and fragment identifier for the request. | 762 * |
763 * This provides access to the | |
764 * path, query string, and fragment identifier for the request. | |
718 */ | 765 */ |
719 Uri get uri; | 766 Uri get uri; |
720 | 767 |
721 /** | 768 /** |
722 * Returns the request headers. | 769 * The request headers (read-only). |
723 */ | 770 */ |
724 HttpHeaders get headers; | 771 HttpHeaders get headers; |
725 | 772 |
726 /** | 773 /** |
727 * Returns the cookies in the request (from the Cookie headers). | 774 * The cookies in the request (from the Cookie headers), also read-only. |
Søren Gjesse
2013/08/27 09:11:10
also read-only -> (read only)
for consistency.
mem
2013/08/27 12:31:56
Done.
| |
728 */ | 775 */ |
729 List<Cookie> get cookies; | 776 List<Cookie> get cookies; |
730 | 777 |
731 /** | 778 /** |
732 * Returns the persistent connection state signaled by the client. | 779 * The persistent connection state signaled by the client (read-only). |
733 */ | 780 */ |
734 bool get persistentConnection; | 781 bool get persistentConnection; |
735 | 782 |
736 /** | 783 /** |
737 * Returns the client certificate of the client making the request. | 784 * 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, | 785 * |
786 * 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 | 787 * or if the server does not request a client certificate, or if the client |
740 * does not provide one. | 788 * does not provide one. |
741 */ | 789 */ |
742 X509Certificate get certificate; | 790 X509Certificate get certificate; |
743 | 791 |
744 /** | 792 /** |
745 * Gets the session for the given request. If the session is | 793 * The session for the given request (read-only). |
746 * being initialized by this call, [:isNew:] will be true for the returned | 794 * |
795 * If the session is | |
796 * being initialized by this call, [:isNew:] is true for the returned | |
747 * session. | 797 * session. |
748 * See [HttpServer.sessionTimeout] on how to change default timeout. | 798 * See [HttpServer.sessionTimeout] on how to change default timeout. |
749 */ | 799 */ |
750 HttpSession get session; | 800 HttpSession get session; |
751 | 801 |
752 /** | 802 /** |
753 * Returns the HTTP protocol version used in the request. This will | 803 * The HTTP protocol version used in the request, |
754 * be "1.0" or "1.1". | 804 * either "1.0" or "1.1" (read-only). |
755 */ | 805 */ |
756 String get protocolVersion; | 806 String get protocolVersion; |
757 | 807 |
758 /** | 808 /** |
759 * Gets information about the client connection. Returns [null] if the socket | 809 * Information about the client connection (read-only). |
760 * is not available. | 810 * |
811 * Returns [null] if the socket is not available. | |
761 */ | 812 */ |
762 HttpConnectionInfo get connectionInfo; | 813 HttpConnectionInfo get connectionInfo; |
763 | 814 |
764 /** | 815 /** |
765 * Gets the [HttpResponse] object, used for sending back the response to the | 816 * The [HttpResponse] object, used for sending back the response to the |
766 * client. | 817 * client (read-only). |
767 * | 818 * |
768 * If the [contentLength] of the body isn't 0, and the body isn't being read, | 819 * 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 | 820 * any write calls on the [HttpResponse] automatically drain the request |
770 * body. | 821 * body. |
771 */ | 822 */ |
772 HttpResponse get response; | 823 HttpResponse get response; |
773 } | 824 } |
774 | 825 |
775 | 826 |
776 /** | 827 /** |
777 * An [HttpResponse] represents the headers and data to be returned to | 828 * An [HttpResponse] represents the headers and data to be returned to |
778 * a client in response to an HTTP request. | 829 * a client in response to an HTTP request. |
779 * | 830 * |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1522 final String message; | 1573 final String message; |
1523 final List<RedirectInfo> redirects; | 1574 final List<RedirectInfo> redirects; |
1524 | 1575 |
1525 const RedirectException(String this.message, | 1576 const RedirectException(String this.message, |
1526 List<RedirectInfo> this.redirects); | 1577 List<RedirectInfo> this.redirects); |
1527 | 1578 |
1528 String toString() => "RedirectException: $message"; | 1579 String toString() => "RedirectException: $message"; |
1529 | 1580 |
1530 Uri get uri => redirects.last.location; | 1581 Uri get uri => redirects.last.location; |
1531 } | 1582 } |
OLD | NEW |