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. | |
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, such as the method, URI, | |
707 * and headers, about the request. | |
Kathy Walrath
2013/08/27 07:18:29
I'd move "about the request" up after information,
mem
2013/08/27 08:13:53
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. | |
Kathy Walrath
2013/08/27 07:18:29
should that be [method]?
mem
2013/08/27 08:13:53
Done.
| |
711 * | |
712 * final HOST = '127.0.0.1'; // localhost. | |
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 * ... | |
720 * case 'POST': | |
721 * ... | |
722 * } | |
723 * }, | |
724 * onError: printError); // .listen failed. | |
Kathy Walrath
2013/08/27 07:18:29
The "." notation seems weird to me here. How about
mem
2013/08/27 08:13:53
Done.
| |
725 * }, onError: printError); // .then failed. | |
Kathy Walrath
2013/08/27 07:18:29
.then -> then or then()
mem
2013/08/27 08:13:53
Done.
| |
726 * | |
727 * Listen to the HttpRequest to handle the | |
701 * data and be notified once the entire body is received. | 728 * data and be notified once the entire body is received. |
729 * The HttpRequest object contains an [HttpResponse] object, | |
730 * to which the server can write its response. | |
731 * For example, here's a skeletal callback function for a request: | |
Kathy Walrath
2013/08/27 07:18:29
It'd be nice to see handleRequest specified somewh
mem
2013/08/27 08:13:53
Done.
| |
732 * | |
733 * void handleRequest(HttpRequest req) { | |
734 * HttpResponse res = req.response; // Send the response via this object. | |
735 * print('${req.method}: ${req.uri.path}'); // Print the method and URI. | |
736 * | |
737 * req.listen((List<int> buffer) { // Listen for the request content. | |
738 * // buffer contains the content of the request. | |
739 * ... | |
740 * res.write( ... ); | |
741 * }, | |
742 * onError: printError); | |
743 * } | |
702 */ | 744 */ |
703 abstract class HttpRequest implements Stream<List<int>> { | 745 abstract class HttpRequest implements Stream<List<int>> { |
704 /** | 746 /** |
705 * Returns the content length of the request body. If the size of | 747 * Returns the content length of the request body. |
706 * the request body is not known in advance this -1. | 748 * |
749 * If the size of the request body is not known in advance, | |
750 * this returns -1. | |
Kathy Walrath
2013/08/27 07:18:29
We usually use noun phrases for properties, even f
mem
2013/08/27 08:13:53
Done.
| |
707 */ | 751 */ |
708 int get contentLength; | 752 int get contentLength; |
709 | 753 |
710 /** | 754 /** |
711 * Returns the method for the request. | 755 * Returns the method, such as 'GET' or 'POST', for the request. |
Kathy Walrath
2013/08/27 07:18:29
The method, ... request (read-only).
(or follow w
mem
2013/08/27 08:13:53
Done.
| |
712 */ | 756 */ |
713 String get method; | 757 String get method; |
714 | 758 |
715 /** | 759 /** |
716 * Returns the URI for the request. This provides access to the | 760 * Returns the URI for the request. |
Kathy Walrath
2013/08/27 07:18:29
The URI... (read-only).
mem
2013/08/27 08:13:53
Done.
| |
717 * path, query string and fragment identifier for the request. | 761 * |
762 * This provides access to the | |
763 * path, query string, and fragment identifier for the request. | |
718 */ | 764 */ |
719 Uri get uri; | 765 Uri get uri; |
720 | 766 |
721 /** | 767 /** |
722 * Returns the request headers. | 768 * Returns the request headers. |
Kathy Walrath
2013/08/27 07:18:29
nounify, add "read only"
mem
2013/08/27 08:13:53
Done.
| |
723 */ | 769 */ |
724 HttpHeaders get headers; | 770 HttpHeaders get headers; |
725 | 771 |
726 /** | 772 /** |
727 * Returns the cookies in the request (from the Cookie headers). | 773 * Returns the cookies in the request (from the Cookie headers). |
Kathy Walrath
2013/08/27 07:18:29
nounify, add "read only"
Actually, I wonder if "r
mem
2013/08/27 08:13:53
Done.
| |
728 */ | 774 */ |
729 List<Cookie> get cookies; | 775 List<Cookie> get cookies; |
730 | 776 |
731 /** | 777 /** |
732 * Returns the persistent connection state signaled by the client. | 778 * Returns the persistent connection state signaled by the client. |
Kathy Walrath
2013/08/27 07:18:29
nounify
mem
2013/08/27 08:13:53
Done.
| |
733 */ | 779 */ |
734 bool get persistentConnection; | 780 bool get persistentConnection; |
735 | 781 |
736 /** | 782 /** |
737 * Returns the client certificate of the client making the request. | 783 * Returns the client certificate of the client making the request. |
Kathy Walrath
2013/08/27 07:18:29
nounify, read-only
mem
2013/08/27 08:13:53
Done.
| |
784 * | |
738 * Returns null if the connection is not a secure TLS or SSL connection, | 785 * Returns 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 | 786 * or if the server does not request a client certificate, or if the client |
740 * does not provide one. | 787 * does not provide one. |
741 */ | 788 */ |
742 X509Certificate get certificate; | 789 X509Certificate get certificate; |
743 | 790 |
744 /** | 791 /** |
745 * Gets the session for the given request. If the session is | 792 * Gets the session for the given request. |
Kathy Walrath
2013/08/27 07:18:29
nounify, read-only
mem
2013/08/27 08:13:53
Done.
| |
793 * | |
794 * If the session is | |
746 * being initialized by this call, [:isNew:] will be true for the returned | 795 * being initialized by this call, [:isNew:] will be true for the returned |
747 * session. | 796 * session. |
748 * See [HttpServer.sessionTimeout] on how to change default timeout. | 797 * See [HttpServer.sessionTimeout] on how to change default timeout. |
749 */ | 798 */ |
750 HttpSession get session; | 799 HttpSession get session; |
751 | 800 |
752 /** | 801 /** |
753 * Returns the HTTP protocol version used in the request. This will | 802 * Returns the HTTP protocol version used in the request, |
Kathy Walrath
2013/08/27 07:18:29
nounify
mem
2013/08/27 08:13:53
Done.
| |
754 * be "1.0" or "1.1". | 803 * either "1.0" or "1.1". |
755 */ | 804 */ |
756 String get protocolVersion; | 805 String get protocolVersion; |
757 | 806 |
758 /** | 807 /** |
759 * Gets information about the client connection. Returns [null] if the socket | 808 * Gets information about the client connection. |
Kathy Walrath
2013/08/27 07:18:29
nounify, read-only
mem
2013/08/27 08:13:53
Done.
| |
760 * is not available. | 809 * |
810 * Returns [null] if the socket is not available. | |
761 */ | 811 */ |
762 HttpConnectionInfo get connectionInfo; | 812 HttpConnectionInfo get connectionInfo; |
763 | 813 |
764 /** | 814 /** |
765 * Gets the [HttpResponse] object, used for sending back the response to the | 815 * Gets the [HttpResponse] object, used for sending back the response to the |
766 * client. | 816 * client. |
767 * | 817 * |
768 * If the [contentLength] of the body isn't 0, and the body isn't being read, | 818 * 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 | 819 * any write calls on the [HttpResponse] will automatically drain the request |
770 * body. | 820 * body. |
771 */ | 821 */ |
772 HttpResponse get response; | 822 HttpResponse get response; |
Kathy Walrath
2013/08/27 07:18:29
nounify, read-only
mem
2013/08/27 08:13:53
Done.
| |
773 } | 823 } |
774 | 824 |
775 | 825 |
776 /** | 826 /** |
777 * An [HttpResponse] represents the headers and data to be returned to | 827 * An [HttpResponse] represents the headers and data to be returned to |
778 * a client in response to an HTTP request. | 828 * a client in response to an HTTP request. |
779 * | 829 * |
780 * This object has a number of properties for setting up the HTTP | 830 * This object has a number of properties for setting up the HTTP |
781 * header of the response. When the header has been set up the methods | 831 * header of the response. When the header has been set up the methods |
782 * from the [IOSink] can be used to write the actual body of the HTTP | 832 * from the [IOSink] can be used to write the actual body of the HTTP |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1522 final String message; | 1572 final String message; |
1523 final List<RedirectInfo> redirects; | 1573 final List<RedirectInfo> redirects; |
1524 | 1574 |
1525 const RedirectException(String this.message, | 1575 const RedirectException(String this.message, |
1526 List<RedirectInfo> this.redirects); | 1576 List<RedirectInfo> this.redirects); |
1527 | 1577 |
1528 String toString() => "RedirectException: $message"; | 1578 String toString() => "RedirectException: $message"; |
1529 | 1579 |
1530 Uri get uri => redirects.last.location; | 1580 Uri get uri => redirects.last.location; |
1531 } | 1581 } |
OLD | NEW |