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

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

Issue 11783034: Re-implement support for client redirects. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2_io/dart
Patch Set: Review fixes Created 7 years, 11 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 | sdk/lib/io/http_impl.dart » ('j') | 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) 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
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
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 [:true:] if this request should
915 * automatically follow redirects. The default is [:true:].
916 *
917 * Automatic redirect will only happen for "GET" and "HEAD" requests
918 * and only for the status codes [:HttpHeaders.MOVED_PERMANENTLY:]
919 * (301), [:HttpStatus.FOUND:] (302),
920 * [:HttpStatus.MOVED_TEMPORARILY:] (302, alias for
921 * [:HttpStatus.FOUND:]), [:HttpStatus.SEE_OTHER:] (303) and
922 * [:HttpStatus.TEMPORARY_REDIRECT:] (307). For
923 * [:HttpStatus.SEE_OTHER:] (303) autmatic redirect will also happen
924 * for "POST" requests with the method changed to "GET" when
925 * following the redirect.
926 *
927 * All headers added to the request will be added to the redirection
928 * request(s). However, any body send with the request will not be
929 * part of the redirection request(s).
930 */
931 bool followRedirects;
932
933 /**
934 * Set this property to the maximum number of redirects to follow
935 * when [followRedirects] is [:true:]. If this number is exceeded the
936 * [onError] callback will be called with a [RedirectLimitExceeded]
937 * exception. The default value is 5.
938 */
939 int maxRedirects;
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
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. The
981 * list will be empty if no redirects was followed. [redirects] will be
982 * updated both in the case of an automatic and a manual redirect.
983 */
984 List<RedirectInfo> get redirects;
985
986 /**
987 * Redirect this connection to a new URL. The default value for
988 * [method] is the method for the current request. The default value
989 * for [url] is the value of the [:HttpHeaders.LOCATION:] header of
990 * the current response. All body data must have been read from the
991 * current response before calling [redirect].
992 *
993 * All headers added to the request will be added to the redirection
994 * request(s). However, any body send with the request will not be
995 * part of the redirection request(s).
996 *
997 * If [followLoops] is set to [true], redirect will follow the redirect,
998 * even if was already visited. Default value is [false].
999 *
1000 * [redirect] will ignore [maxRedirects] and always perform the redirect.
1001 */
1002 Future<HttpClientResponse> redirect([String method,
1003 Uri url,
1004 bool followLoops]);
1005
1006
1007 /**
998 * Returns the response headers. 1008 * Returns the response headers.
999 */ 1009 */
1000 HttpHeaders get headers; 1010 HttpHeaders get headers;
1001 1011
1002 /** 1012 /**
1003 * Cookies set by the server (from the Set-Cookie header). 1013 * Cookies set by the server (from the Set-Cookie header).
1004 */ 1014 */
1005 List<Cookie> get cookies; 1015 List<Cookie> get cookies;
1006 1016
1007 /** 1017 /**
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 class RedirectLimitExceededException extends RedirectException { 1104 class RedirectLimitExceededException extends RedirectException {
1095 const RedirectLimitExceededException(List<RedirectInfo> redirects) 1105 const RedirectLimitExceededException(List<RedirectInfo> redirects)
1096 : super("Redirect limit exceeded", redirects); 1106 : super("Redirect limit exceeded", redirects);
1097 } 1107 }
1098 1108
1099 1109
1100 class RedirectLoopException extends RedirectException { 1110 class RedirectLoopException extends RedirectException {
1101 const RedirectLoopException(List<RedirectInfo> redirects) 1111 const RedirectLoopException(List<RedirectInfo> redirects)
1102 : super("Redirect loop detected", redirects); 1112 : super("Redirect loop detected", redirects);
1103 } 1113 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698