Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 * | 838 * |
| 839 * The setting of all handlers is optional. If [onRequest] is not set | 839 * The setting of all handlers is optional. If [onRequest] is not set |
| 840 * the request will be send without any additional headers and an | 840 * the request will be send without any additional headers and an |
| 841 * empty body. If [onResponse] is not set the response will be read | 841 * empty body. If [onResponse] is not set the response will be read |
| 842 * and discarded. | 842 * and discarded. |
| 843 */ | 843 */ |
| 844 abstract class HttpClientConnection { | 844 abstract class HttpClientConnection { |
| 845 // TODO(ajohnsen): Move these methods to the right place (request or response) | 845 // TODO(ajohnsen): Move these methods to the right place (request or response) |
| 846 | 846 |
| 847 /** | 847 /** |
| 848 * Set this property to [:true:] if this connection should | |
| 849 * automatically follow redirects. The default is [:true:]. | |
| 850 * | |
| 851 * Automatic redirect will only happen for "GET" and "HEAD" requests | |
| 852 * and only for the status codes [:HttpHeaders.MOVED_PERMANENTLY:] | |
| 853 * (301), [:HttpStatus.FOUND:] (302), | |
| 854 * [:HttpStatus.MOVED_TEMPORARILY:] (302, alias for | |
| 855 * [:HttpStatus.FOUND:]), [:HttpStatus.SEE_OTHER:] (303) and | |
| 856 * [:HttpStatus.TEMPORARY_REDIRECT:] (307). For | |
| 857 * [:HttpStatus.SEE_OTHER:] (303) autmatic redirect will also happen | |
| 858 * for "POST" requests with the method changed to "GET" when | |
| 859 * following the redirect. | |
| 860 * | |
| 861 * All headers added to the request will be added to the redirection | |
| 862 * request(s). However, any body send with the request will not be | |
| 863 * part of the redirection request(s). | |
| 864 */ | |
| 865 bool followRedirects; | |
| 866 | |
| 867 /** | |
| 868 * Set this property to the maximum number of redirects to follow | |
| 869 * when [followRedirects] is [:true:]. If this number is exceeded the | |
| 870 * [onError] callback will be called with a [RedirectLimitExceeded] | |
| 871 * exception. The default value is 5. | |
| 872 */ | |
| 873 int maxRedirects; | |
| 874 | |
| 875 /** | |
| 876 * Returns the series of redirects this connection has been through. | |
| 877 */ | |
| 878 List<RedirectInfo> get redirects; | |
| 879 | |
| 880 /** | |
| 881 * Redirect this connection to a new URL. The default value for | |
| 882 * [method] is the method for the current request. The default value | |
| 883 * for [url] is the value of the [:HttpHeaders.LOCATION:] header of | |
| 884 * the current response. All body data must have been read from the | |
| 885 * current response before calling [redirect]. | |
| 886 * | |
| 887 * All headers added to the request will be added to the redirection | |
| 888 * request(s). However, any body send with the request will not be | |
| 889 * part of the redirection request(s). | |
| 890 */ | |
| 891 void redirect([String method, Uri url]); | |
| 892 | |
| 893 /** | |
| 894 * Detach the underlying socket from the HTTP client. When the | 848 * Detach the underlying socket from the HTTP client. When the |
| 895 * socket is detached the HTTP client will no longer perform any | 849 * socket is detached the HTTP client will no longer perform any |
| 896 * operations on it. | 850 * operations on it. |
| 897 * | 851 * |
| 898 * This is normally used when a HTTP upgrade is negotiated and the | 852 * This is normally used when a HTTP upgrade is negotiated and the |
| 899 * communication should continue with a different protocol. | 853 * communication should continue with a different protocol. |
| 900 */ | 854 */ |
| 901 DetachedSocket detachSocket(); | 855 DetachedSocket detachSocket(); |
| 902 | 856 |
| 903 /** | 857 /** |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 * A [HttpClientResponse] future that will complete once the response is | 902 * A [HttpClientResponse] future that will complete once the response is |
| 949 * available. If an error occours before the response is available, this | 903 * available. If an error occours before the response is available, this |
| 950 * future will complete with an error. | 904 * future will complete with an error. |
| 951 */ | 905 */ |
| 952 Future<HttpClientResponse> get response; | 906 Future<HttpClientResponse> get response; |
| 953 | 907 |
| 954 /** | 908 /** |
| 955 * Close the request for input. Returns the value of [response]. | 909 * Close the request for input. Returns the value of [response]. |
| 956 */ | 910 */ |
| 957 Future<HttpClientResponse> close(); | 911 Future<HttpClientResponse> close(); |
| 912 | |
| 913 /** | |
| 914 * Set this property to the maximum number of redirects to follow | |
| 915 * when [followRedirects] is [:true:]. If this number is exceeded the | |
| 916 * [onError] callback will be called with a [RedirectLimitExceeded] | |
| 917 * exception. The default value is 5. | |
| 918 */ | |
| 919 int maxRedirects; | |
|
Søren Gjesse
2013/01/09 08:43:49
Place maxRedirects after followRedirects.
Anders Johnsen
2013/01/09 10:03:00
Done.
| |
| 920 | |
| 921 /** | |
| 922 * Set this property to [:true:] if this request should | |
| 923 * automatically follow redirects. The default is [:true:]. | |
| 924 * | |
| 925 * Automatic redirect will only happen for "GET" and "HEAD" requests | |
| 926 * and only for the status codes [:HttpHeaders.MOVED_PERMANENTLY:] | |
| 927 * (301), [:HttpStatus.FOUND:] (302), | |
| 928 * [:HttpStatus.MOVED_TEMPORARILY:] (302, alias for | |
| 929 * [:HttpStatus.FOUND:]), [:HttpStatus.SEE_OTHER:] (303) and | |
| 930 * [:HttpStatus.TEMPORARY_REDIRECT:] (307). For | |
| 931 * [:HttpStatus.SEE_OTHER:] (303) autmatic redirect will also happen | |
| 932 * for "POST" requests with the method changed to "GET" when | |
| 933 * following the redirect. | |
| 934 * | |
| 935 * All headers added to the request will be added to the redirection | |
| 936 * request(s). However, any body send with the request will not be | |
| 937 * part of the redirection request(s). | |
| 938 */ | |
| 939 bool followRedirects; | |
| 958 } | 940 } |
| 959 | 941 |
| 960 | 942 |
| 961 /** | 943 /** |
| 962 * HTTP response for a client connection. The [HttpClientResponse] is a | 944 * HTTP response for a client connection. The [HttpClientResponse] is a |
| 963 * [Stream] of the body content of the response. Listen to the body to handle | 945 * [Stream] of the body content of the response. Listen to the body to handle |
| 964 * the data and be notified once the entire body is received. | 946 * the data and be notified once the entire body is received. |
| 965 | 947 |
| 966 */ | 948 */ |
| 967 abstract class HttpClientResponse implements Stream<List<int>> { | 949 abstract class HttpClientResponse implements Stream<List<int>> { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 988 | 970 |
| 989 /** | 971 /** |
| 990 * Returns whether the status code is one of the normal redirect | 972 * Returns whether the status code is one of the normal redirect |
| 991 * codes [:HttpStatus.MOVED_PERMANENTLY:], [:HttpStatus.FOUND:], | 973 * codes [:HttpStatus.MOVED_PERMANENTLY:], [:HttpStatus.FOUND:], |
| 992 * [:HttpStatus.MOVED_TEMPORARILY:], [:HttpStatus.SEE_OTHER:] and | 974 * [:HttpStatus.MOVED_TEMPORARILY:], [:HttpStatus.SEE_OTHER:] and |
| 993 * [:HttpStatus.TEMPORARY_REDIRECT:]. | 975 * [:HttpStatus.TEMPORARY_REDIRECT:]. |
| 994 */ | 976 */ |
| 995 bool get isRedirect; | 977 bool get isRedirect; |
| 996 | 978 |
| 997 /** | 979 /** |
| 980 * Returns the series of redirects this connection has been through. | |
|
Søren Gjesse
2013/01/09 08:43:49
Document that no redirects is the empty list and n
Anders Johnsen
2013/01/09 10:03:00
Done.
| |
| 981 */ | |
| 982 List<RedirectInfo> get redirects; | |
| 983 | |
| 984 /** | |
| 985 * Redirect this connection to a new URL. The default value for | |
| 986 * [method] is the method for the current request. The default value | |
| 987 * for [url] is the value of the [:HttpHeaders.LOCATION:] header of | |
| 988 * the current response. All body data must have been read from the | |
| 989 * current response before calling [redirect]. | |
| 990 * | |
| 991 * All headers added to the request will be added to the redirection | |
| 992 * request(s). However, any body send with the request will not be | |
| 993 * part of the redirection request(s). | |
| 994 * | |
| 995 * If [followLoops] is set to [true], redirect will follow the redirect, | |
| 996 * even if was already visited. Default value is [false]. | |
|
Søren Gjesse
2013/01/09 08:43:49
Maybe we need to add some additional documentation
Anders Johnsen
2013/01/09 10:03:00
Done.
| |
| 997 */ | |
| 998 Future<HttpClientResponse> redirect([String method, | |
| 999 Uri url, | |
| 1000 bool followLoops]); | |
| 1001 | |
| 1002 | |
| 1003 /** | |
| 998 * Returns the response headers. | 1004 * Returns the response headers. |
| 999 */ | 1005 */ |
| 1000 HttpHeaders get headers; | 1006 HttpHeaders get headers; |
| 1001 | 1007 |
| 1002 /** | 1008 /** |
| 1003 * Cookies set by the server (from the Set-Cookie header). | 1009 * Cookies set by the server (from the Set-Cookie header). |
| 1004 */ | 1010 */ |
| 1005 List<Cookie> get cookies; | 1011 List<Cookie> get cookies; |
| 1006 | 1012 |
| 1007 /** | 1013 /** |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 class RedirectLimitExceededException extends RedirectException { | 1100 class RedirectLimitExceededException extends RedirectException { |
| 1095 const RedirectLimitExceededException(List<RedirectInfo> redirects) | 1101 const RedirectLimitExceededException(List<RedirectInfo> redirects) |
| 1096 : super("Redirect limit exceeded", redirects); | 1102 : super("Redirect limit exceeded", redirects); |
| 1097 } | 1103 } |
| 1098 | 1104 |
| 1099 | 1105 |
| 1100 class RedirectLoopException extends RedirectException { | 1106 class RedirectLoopException extends RedirectException { |
| 1101 const RedirectLoopException(List<RedirectInfo> redirects) | 1107 const RedirectLoopException(List<RedirectInfo> redirects) |
| 1102 : super("Redirect loop detected", redirects); | 1108 : super("Redirect loop detected", redirects); |
| 1103 } | 1109 } |
| OLD | NEW |