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

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

Issue 13938003: Update the dartdoc for HttpClient (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 * header of the response. When the header has been set up the methods 681 * header of the response. When the header has been set up the methods
682 * from the [IOSink] can be used to write the actual body of the HTTP 682 * from the [IOSink] can be used to write the actual body of the HTTP
683 * response. When one of the [IOSink] methods is used for the 683 * response. When one of the [IOSink] methods is used for the
684 * first time the request header is send. Calling any methods that 684 * first time the request header is send. Calling any methods that
685 * will change the header after it is sent will throw an exception. 685 * will change the header after it is sent will throw an exception.
686 * 686 *
687 * When writing string data through the [IOSink] the encoding used 687 * When writing string data through the [IOSink] the encoding used
688 * will be determined from the "charset" parameter of the 688 * will be determined from the "charset" parameter of the
689 * "Content-Type" header. 689 * "Content-Type" header.
690 * 690 *
691 * HttpResponse response = ... 691 * HttpResponse response = ...
692 * response.headers.contentType 692 * response.headers.contentType
693 * = new ContentType("application", "json", charset: "utf-8"); 693 * = new ContentType("application", "json", charset: "utf-8");
694 * response.write(...); // Strings written will be UTF-8 encoded. 694 * response.write(...); // Strings written will be UTF-8 encoded.
695 * 695 *
696 * If no charset is provided the default of ISO-8859-1 (Latin 1) will 696 * If no charset is provided the default of ISO-8859-1 (Latin 1) will
697 * be used. 697 * be used.
698 * 698 *
699 * HttpResponse response = ... 699 * HttpResponse response = ...
700 * response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); 700 * response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
701 * response.write(...); // Strings written will be ISO-8859-1 encoded. 701 * response.write(...); // Strings written will be ISO-8859-1 encoded.
702 * 702 *
703 * If an unsupported encoding is used an exception will be thrown if 703 * If an unsupported encoding is used an exception will be thrown if
704 * using one of the write methods taking a string. 704 * using one of the write methods taking a string.
705 */ 705 */
706 abstract class HttpResponse implements IOSink<HttpResponse> { 706 abstract class HttpResponse implements IOSink<HttpResponse> {
707 // TODO(ajohnsen): Add documentation of how to pipe a file to the response. 707 // TODO(ajohnsen): Add documentation of how to pipe a file to the response.
708 /** 708 /**
709 * Gets and sets the content length of the response. If the size of 709 * Gets and sets the content length of the response. If the size of
710 * the response is not known in advance set the content length to 710 * the response is not known in advance set the content length to
711 * -1 - which is also the default if not set. 711 * -1 - which is also the default if not set.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 755
756 /** 756 /**
757 * Gets information about the client connection. Returns [null] if the socket 757 * Gets information about the client connection. Returns [null] if the socket
758 * is not available. 758 * is not available.
759 */ 759 */
760 HttpConnectionInfo get connectionInfo; 760 HttpConnectionInfo get connectionInfo;
761 } 761 }
762 762
763 763
764 /** 764 /**
765 * HTTP client factory. The [HttpClient] handles all the sockets associated 765 * The [HttpClient] class implements the client side of the HTTP
766 * with the [HttpClientConnection]s and when the endpoint supports it, it will 766 * protocol. It contains a number of methods to send a HTTP request
767 * try to reuse opened sockets for several requests to support HTTP 1.1 767 * to a HTTP server and receive a HTTP response back.
768 * persistent connections. This means that sockets will be kept open for some 768 *
769 * time after a requests have completed, unless HTTP procedures indicate that it 769 * This is handles as a two step process where two futures are
Bill Hesse 2013/04/09 07:56:27 This is a two-step process, triggered by two futur
Bill Hesse 2013/04/09 07:56:27 "handled"
Søren Gjesse 2013/04/12 07:27:22 Done.
Søren Gjesse 2013/04/12 07:27:22 Rephrased as suggested.
770 * must be closed as part of completing the request. Use [:HttpClient.close:] 770 * used. There is a future for when the request is ready and another
771 * to force close the idle sockets. 771 * future for when the response is received. When the request is ready
Anders Johnsen 2013/04/09 08:04:28 Maybe add that a ready response means that a Socke
Søren Gjesse 2013/04/12 07:27:22 Done.
772 * a [HttpClientRequest] object is provided where one can set HTTP
773 * headers and include a body in the request as well. The request
774 * object has a [:close:] that is called to send the request to the server.
775 *
776 * When the HTTP response is ready a [HttpClientResponse] object is
777 * provided which provide access to the headers and body of the response.
Bill Hesse 2013/04/09 07:56:27 provides
Søren Gjesse 2013/04/12 07:27:22 Done.
778 *
779 * HttpClient client = new HttpClient();
780 * client.getUrl(new Uri.fromString("http://www.example.com/"))
781 * .then((HttpClientRequest request) {
782 * // Prepare the request.
783 *
784 * // Set handler for the response object.
785 * request.response.then((HttpClientResponse response) {
786 * // Process the response.
787 * });
788 *
789 * // Call close on the request to send it to the server.
790 * request.close();
791 * });
792 *
793 * The [:close:] method on the [HttpClientRequest] object also returns
794 * the future for the [HttpClientResponse]. This means that the code
795 * above can be written like this:
796 *
797 * HttpClient client = new HttpClient();
798 * client.getUrl(new Uri.fromString("http://www.example.com/"))
799 * .then((HttpClientRequest request) {
800 * // Prepare the request then call close on it to send it.
801 * return request.close();
802 * })
803 * .then((HttpClientResponse response) {
804 * // Process the response.
805 * });
806 *
807 * All [HttpClient] request sets the following header by default:
Bill Hesse 2013/04/09 07:56:27 requests set
Anders Johnsen 2013/04/09 08:04:28 requests
Søren Gjesse 2013/04/12 07:27:22 Done.
Søren Gjesse 2013/04/12 07:27:22 Done.
808 *
809 * Accept-Encoding: gzip
810 *
811 * This allows the HTTP server to use gzip compression for the body it
Anders Johnsen 2013/04/09 08:04:28 it -> if
Søren Gjesse 2013/04/12 07:27:22 Done.
812 * possible. If this behavior is not desired set the
813 * "Accept-Encoding" header to something else.
814 *
815 * The [HttpClient] handles all sockets associated HTTP requests and
Bill Hesse 2013/04/09 07:56:27 caches all sockets associated with HTTP requests,
Anders Johnsen 2013/04/09 08:04:28 associated with
Søren Gjesse 2013/04/12 07:27:22 Done.
Søren Gjesse 2013/04/12 07:27:22 Done.
816 * when the server supports it, it will try to reuse opened sockets
817 * for several requests to support HTTP 1.1 persistent
818 * connections. This means that sockets will be kept open for some
819 * time after a requests have completed, unless HTTP procedures
Bill Hesse 2013/04/09 07:56:27 unless the protocol requires the request to close
Søren Gjesse 2013/04/12 07:27:22 Done.
820 * indicate that it must be closed as part of completing the
821 * request. Use [:HttpClient.close:] to force close the idle sockets.
772 */ 822 */
773 abstract class HttpClient { 823 abstract class HttpClient {
774 static const int DEFAULT_HTTP_PORT = 80; 824 static const int DEFAULT_HTTP_PORT = 80;
775 static const int DEFAULT_HTTPS_PORT = 443; 825 static const int DEFAULT_HTTPS_PORT = 443;
776 826
777 factory HttpClient() => new _HttpClient(); 827 factory HttpClient() => new _HttpClient();
778 828
779 /** 829 /**
780 * Opens a HTTP connection. The returned [HttpClientRequest] is used to 830 * Opens a HTTP connection. The returned [HttpClientRequest] is used to
781 * fill in the content of the request before sending it. The 'host' header for 831 * fill in the content of the request before sending it. The 'host' header for
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 * 949 *
900 * [:no_proxy:] and [:NO_PROXY:] specify a comma separated list of 950 * [:no_proxy:] and [:NO_PROXY:] specify a comma separated list of
901 * postfixes of hostnames for which not to use the proxy 951 * postfixes of hostnames for which not to use the proxy
902 * server. E.g. the value "localhost,127.0.0.1" will make requests 952 * server. E.g. the value "localhost,127.0.0.1" will make requests
903 * to both "localhost" and "127.0.0.1" not use a proxy. If both are set 953 * to both "localhost" and "127.0.0.1" not use a proxy. If both are set
904 * the lower case one takes precedence. 954 * the lower case one takes precedence.
905 * 955 *
906 * To activate this way of resolving proxies assign this function to 956 * To activate this way of resolving proxies assign this function to
907 * the [findProxy] property on the [HttpClient]. 957 * the [findProxy] property on the [HttpClient].
908 * 958 *
909 * HttpClient client = new HttpClient(); 959 * HttpClient client = new HttpClient();
910 * client.findProxy = HttpClient.findProxyFromEnvironment; 960 * client.findProxy = HttpClient.findProxyFromEnvironment;
911 * 961 *
912 * If you don't want to use the system environment you can use a 962 * If you don't want to use the system environment you can use a
913 * different one by wrapping the function. 963 * different one by wrapping the function.
914 * 964 *
915 * HttpClient client = new HttpClient(); 965 * HttpClient client = new HttpClient();
916 * client.findProxy = (url) { 966 * client.findProxy = (url) {
917 * return HttpClient.findProxyFromEnvironment( 967 * return HttpClient.findProxyFromEnvironment(
918 * url, {"http_proxy": ..., "no_proxy": ...}); 968 * url, {"http_proxy": ..., "no_proxy": ...});
919 * } 969 * }
920 */ 970 */
921 static String findProxyFromEnvironment(Uri url, 971 static String findProxyFromEnvironment(Uri url,
922 {Map<String, String> environment}) { 972 {Map<String, String> environment}) {
923 return _HttpClient._findProxyFromEnvironment(url, environment); 973 return _HttpClient._findProxyFromEnvironment(url, environment);
924 } 974 }
925 975
926 /** 976 /**
927 * Shutdown the HTTP client. If [force] is [:false:] (the default) 977 * Shutdown the HTTP client. If [force] is [:false:] (the default)
928 * the [:HttpClient:] will be kept alive until all active 978 * the [:HttpClient:] will be kept alive until all active
929 * connections are done. If [force] is [:true:] any active 979 * connections are done. If [force] is [:true:] any active
(...skipping 14 matching lines...) Expand all
944 * header of the request. When the header has been set up the methods 994 * header of the request. When the header has been set up the methods
945 * from the [IOSink] can be used to write the actual body of the HTTP 995 * from the [IOSink] can be used to write the actual body of the HTTP
946 * request. When one of the [IOSink] methods is used for the first 996 * request. When one of the [IOSink] methods is used for the first
947 * time the request header is send. Calling any methods that will 997 * time the request header is send. Calling any methods that will
948 * change the header after it is sent will throw an exception. 998 * change the header after it is sent will throw an exception.
949 * 999 *
950 * When writing string data through the [IOSink] the 1000 * When writing string data through the [IOSink] the
951 * encoding used will be determined from the "charset" parameter of 1001 * encoding used will be determined from the "charset" parameter of
952 * the "Content-Type" header. 1002 * the "Content-Type" header.
953 * 1003 *
954 * HttpClientRequest request = ... 1004 * HttpClientRequest request = ...
955 * request.headers.contentType 1005 * request.headers.contentType
956 * = new ContentType("application", "json", charset: "utf-8"); 1006 * = new ContentType("application", "json", charset: "utf-8");
957 * request.write(...); // Strings written will be UTF-8 encoded. 1007 * request.write(...); // Strings written will be UTF-8 encoded.
958 * 1008 *
959 * If no charset is provided the default of ISO-8859-1 (Latin 1) will 1009 * If no charset is provided the default of ISO-8859-1 (Latin 1) will
960 * be used. 1010 * be used.
961 * 1011 *
962 * HttpClientRequest request = ... 1012 * HttpClientRequest request = ...
963 * request.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); 1013 * request.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
964 * request.write(...); // Strings written will be ISO-8859-1 encoded. 1014 * request.write(...); // Strings written will be ISO-8859-1 encoded.
965 * 1015 *
966 * If an unsupported encoding is used an exception will be thrown if 1016 * If an unsupported encoding is used an exception will be thrown if
967 * using one of the write methods taking a string. 1017 * using one of the write methods taking a string.
968 */ 1018 */
969 abstract class HttpClientRequest 1019 abstract class HttpClientRequest
970 implements IOSink<HttpClientRequest> { 1020 implements IOSink<HttpClientRequest> {
971 /** 1021 /**
972 * Gets and sets the content length of the request. If the size of 1022 * Gets and sets the content length of the request. If the size of
973 * the request is not known in advance set content length to -1, 1023 * the request is not known in advance set content length to -1,
974 * which is also the default. 1024 * which is also the default.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 class RedirectLimitExceededException extends RedirectException { 1269 class RedirectLimitExceededException extends RedirectException {
1220 const RedirectLimitExceededException(List<RedirectInfo> redirects) 1270 const RedirectLimitExceededException(List<RedirectInfo> redirects)
1221 : super("Redirect limit exceeded", redirects); 1271 : super("Redirect limit exceeded", redirects);
1222 } 1272 }
1223 1273
1224 1274
1225 class RedirectLoopException extends RedirectException { 1275 class RedirectLoopException extends RedirectException {
1226 const RedirectLoopException(List<RedirectInfo> redirects) 1276 const RedirectLoopException(List<RedirectInfo> redirects)
1227 : super("Redirect loop detected", redirects); 1277 : super("Redirect loop detected", redirects);
1228 } 1278 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698