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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 /** | 57 /** |
58 * HTTP server. | 58 * HTTP server. |
59 */ | 59 */ |
60 abstract class HttpServer implements Stream<HttpRequest> { | 60 abstract class HttpServer implements Stream<HttpRequest> { |
61 // TODO(ajohnsen): Document with example, once the stream API is final. | 61 // TODO(ajohnsen): Document with example, once the stream API is final. |
62 // TODO(ajohnsen): Add HttpServer.secure. | 62 // TODO(ajohnsen): Add HttpServer.secure. |
63 /** | 63 /** |
64 * Start listening for HTTP requests on the specified [host] and | 64 * Starts listening for HTTP requests on the specified [address] and |
65 * [port]. If a [port] of 0 is specified the server will choose an | 65 * [port]. If a [port] of 0 is specified the server will choose an |
66 * ephemeral port. The optional argument [backlog] can be used to | 66 * ephemeral port. The optional argument [backlog] can be used to |
67 * specify the listen backlog for the underlying OS listen | 67 * specify the listen backlog for the underlying OS listen |
68 * setup. | 68 * setup. |
69 */ | 69 */ |
70 static Future<HttpServer> bind([String address = "127.0.0.1", | 70 static Future<HttpServer> bind([String address = "127.0.0.1", |
71 int port = 0, | 71 int port = 0, |
72 int backlog = 0]) | 72 int backlog = 0]) |
73 => _HttpServer.bind(address, port, backlog); | 73 => _HttpServer.bind(address, port, backlog); |
74 | 74 |
75 /** | 75 /** |
76 * Start listening for HTTPS requests on the specified [host] and | 76 * Starts listening for HTTPS requests on the specified [address] and |
77 * [port]. If a [port] of 0 is specified the server will choose an | 77 * [port]. If a [port] of 0 is specified the server will choose an |
78 * ephemeral port. The optional argument [backlog] can be used to | 78 * ephemeral port. The optional argument [backlog] can be used to |
79 * specify the listen backlog for the underlying OS listen | 79 * specify the listen backlog for the underlying OS listen |
80 * setup. | 80 * setup. |
81 * | 81 * |
82 * The certificate with Distinguished Name [certificate_name] is looked | 82 * The certificate with Distinguished Name [certificateName] is looked |
83 * up in the certificate database, and is used as the server certificate. | 83 * up in the certificate database, and is used as the server certificate. |
84 * if [requestClientCertificate] is true, the server will request clients | 84 * if [requestClientCertificate] is true, the server will request clients |
85 * to authenticate with a client certificate. | 85 * to authenticate with a client certificate. |
86 */ | 86 */ |
87 | 87 |
88 static Future<HttpServer> bindSecure(String address, | 88 static Future<HttpServer> bindSecure(String address, |
89 int port, | 89 int port, |
90 {int backlog: 0, | 90 {int backlog: 0, |
91 String certificateName, | 91 String certificateName, |
92 bool requestClientCertificate: false}) | 92 bool requestClientCertificate: false}) |
93 => _HttpServer.bindSecure(address, | 93 => _HttpServer.bindSecure(address, |
94 port, | 94 port, |
95 backlog, | 95 backlog, |
96 certificateName, | 96 certificateName, |
97 requestClientCertificate); | 97 requestClientCertificate); |
98 | 98 |
99 /** | 99 /** |
100 * Attach the HTTP server to an existing [:ServerSocket:]. When the | 100 * Attaches the HTTP server to an existing [ServerSocket]. When the |
101 * [HttpServer] is closed, the [HttpServer] will just detach itself, | 101 * [HttpServer] is closed, the [HttpServer] will just detach itself, |
102 * close current connections but not close [serverSocket]. | 102 * closing current connections but not closing [serverSocket]. |
103 */ | 103 */ |
104 factory HttpServer.listenOn(ServerSocket serverSocket) | 104 factory HttpServer.listenOn(ServerSocket serverSocket) |
105 => new _HttpServer.listenOn(serverSocket); | 105 => new _HttpServer.listenOn(serverSocket); |
106 | 106 |
107 /** | 107 /** |
108 * Stop server listening. This will make the [Stream] close with a done | 108 * Permanently stops this [HttpServer] from listening for new connections. |
109 * event. | 109 * This closes this [Stream] of [HttpRequest]s with a done event. |
110 */ | 110 */ |
111 void close(); | 111 void close(); |
112 | 112 |
113 /** | 113 /** |
114 * Returns the port that the server is listening on. This can be | 114 * Returns the port that the server is listening on. This can be |
115 * used to get the actual port used when a value of 0 for [port] is | 115 * used to get the actual port used when a value of 0 for [:port:] is |
116 * specified in the [listen] call. | 116 * specified in the [bind] or [bindSecure] call. |
117 */ | 117 */ |
118 int get port; | 118 int get port; |
119 | 119 |
120 /** | 120 /** |
121 * Set the timeout, in seconds, for sessions of this HTTP server. Default | 121 * Sets the timeout, in seconds, for sessions of this [HttpServer]. |
122 * is 20 minutes. | 122 * The default timeout is 20 minutes. |
123 */ | 123 */ |
124 set sessionTimeout(int timeout); | 124 set sessionTimeout(int timeout); |
125 | 125 |
126 /** | 126 /** |
127 * Returns a [:HttpConnectionsInfo:] object with an overview of the | 127 * Returns an [HttpConnectionsInfo] object summarizing the number of |
128 * current connections handled by the server. | 128 * current connections handled by the server. |
129 */ | 129 */ |
130 HttpConnectionsInfo connectionsInfo(); | 130 HttpConnectionsInfo connectionsInfo(); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 /** | 134 /** |
135 * Overview information of the [:HttpServer:] socket connections. | 135 * Summary statistics about an [HttpServer]s current socket connections. |
136 */ | 136 */ |
137 class HttpConnectionsInfo { | 137 class HttpConnectionsInfo { |
138 /** | 138 /** |
139 * Total number of socket connections. | 139 * Total number of socket connections. |
140 */ | 140 */ |
141 int total = 0; | 141 int total = 0; |
142 | 142 |
143 /** | 143 /** |
144 * Number of active connections where actual request/response | 144 * Number of active connections where actual request/response |
145 * processing is active. | 145 * processing is active. |
146 */ | 146 */ |
147 int active = 0; | 147 int active = 0; |
148 | 148 |
149 /** | 149 /** |
150 * Number of idle connections held by clients as persistent connections. | 150 * Number of idle connections held by clients as persistent connections. |
151 */ | 151 */ |
152 int idle = 0; | 152 int idle = 0; |
153 | 153 |
154 /** | 154 /** |
155 * Number of connections which are preparing to close. Note: These | 155 * Number of connections which are preparing to close. Note: These |
156 * connections are also part of the [:active:] count as they might | 156 * connections are also part of the [:active:] count as they might |
157 * still be sending data to the client before finally closing. | 157 * still be sending data to the client before finally closing. |
158 */ | 158 */ |
159 int closing = 0; | 159 int closing = 0; |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 /** | 163 /** |
164 * Access to the HTTP headers for requests and responses. In some | 164 * Access to the HTTP headers for requests and responses. In some |
165 * situations the headers will be imutable and the mutating methods | 165 * situations the headers will be immutable and the mutating methods |
166 * will then throw exceptions. | 166 * will then throw exceptions. |
167 * | 167 * |
168 * For all operation on HTTP headers the header name is | 168 * For all operations on HTTP headers the header name is |
169 * case-insensitive. | 169 * case-insensitive. |
170 */ | 170 */ |
171 abstract class HttpHeaders { | 171 abstract class HttpHeaders { |
172 static const ACCEPT = "Accept"; | 172 static const ACCEPT = "Accept"; |
173 static const ACCEPT_CHARSET = "Accept-Charset"; | 173 static const ACCEPT_CHARSET = "Accept-Charset"; |
174 static const ACCEPT_ENCODING = "Accept-Encoding"; | 174 static const ACCEPT_ENCODING = "Accept-Encoding"; |
175 static const ACCEPT_LANGUAGE = "Accept-Language"; | 175 static const ACCEPT_LANGUAGE = "Accept-Language"; |
176 static const ACCEPT_RANGES = "Accept-Ranges"; | 176 static const ACCEPT_RANGES = "Accept-Ranges"; |
177 static const AGE = "Age"; | 177 static const AGE = "Age"; |
178 static const ALLOW = "Allow"; | 178 static const ALLOW = "Allow"; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 IF_UNMODIFIED_SINCE, | 264 IF_UNMODIFIED_SINCE, |
265 MAX_FORWARDS, | 265 MAX_FORWARDS, |
266 PROXY_AUTHORIZATION, | 266 PROXY_AUTHORIZATION, |
267 RANGE, | 267 RANGE, |
268 REFERER, | 268 REFERER, |
269 TE, | 269 TE, |
270 USER_AGENT]; | 270 USER_AGENT]; |
271 | 271 |
272 /** | 272 /** |
273 * Returns the list of values for the header named [name]. If there | 273 * Returns the list of values for the header named [name]. If there |
274 * is no headers with the provided name [:null:] will be returned. | 274 * is no header with the provided name, [:null:] will be returned. |
275 */ | 275 */ |
276 List<String> operator[](String name); | 276 List<String> operator[](String name); |
277 | 277 |
278 /** | 278 /** |
279 * Convenience method for the value for a single values header. If | 279 * Convenience method for the value for a single valued header. If |
280 * there is no header with the provided name [:null:] will be | 280 * there is no header with the provided name, [:null:] will be |
281 * returned. If the header has more than one value an exception is | 281 * returned. If the header has more than one value an exception is |
282 * thrown. | 282 * thrown. |
283 */ | 283 */ |
284 String value(String name); | 284 String value(String name); |
285 | 285 |
286 /** | 286 /** |
287 * Adds a header value. The header named [name] will have the value | 287 * Adds a header value. The header named [name] will have the value |
288 * [value] added to its list of values. Some headers are single | 288 * [value] added to its list of values. Some headers are single |
289 * values and for these adding a value will replace the previous | 289 * valued, and for these adding a value will replace the previous |
290 * value. If the value is of type DateTime a HTTP date format will be | 290 * value. If the value is of type DateTime a HTTP date format will be |
291 * applied. If the value is a [:List:] each element of the list will | 291 * applied. If the value is a [:List:] each element of the list will |
292 * be added separately. For all other types the default [:toString:] | 292 * be added separately. For all other types the default [:toString:] |
293 * method will be used. | 293 * method will be used. |
294 */ | 294 */ |
295 void add(String name, Object value); | 295 void add(String name, Object value); |
296 | 296 |
297 /** | 297 /** |
298 * Sets a header. The header named [name] will have all its values | 298 * Sets a header. The header named [name] will have all its values |
299 * cleared before the value [value] is added as its value. | 299 * cleared before the value [value] is added as its value. |
300 */ | 300 */ |
301 void set(String name, Object value); | 301 void set(String name, Object value); |
302 | 302 |
303 /** | 303 /** |
304 * Removes a specific value for a header name. Some headers have | 304 * Removes a specific value for a header name. Some headers have |
305 * system supplied values and for these the system supplied values | 305 * system supplied values and for these the system supplied values |
306 * will still be added to the collection of values for the header. | 306 * will still be added to the collection of values for the header. |
307 */ | 307 */ |
308 void remove(String name, Object value); | 308 void remove(String name, Object value); |
309 | 309 |
310 /** | 310 /** |
311 * Remove all values for the specified header name. Some headers | 311 * Removes all values for the specified header name. Some headers |
312 * have system supplied values and for these the system supplied | 312 * have system supplied values and for these the system supplied |
313 * values will still be added to the collection of values for the | 313 * values will still be added to the collection of values for the |
314 * header. | 314 * header. |
315 */ | 315 */ |
316 void removeAll(String name); | 316 void removeAll(String name); |
317 | 317 |
318 /** | 318 /** |
319 * Enumerate the headers applying the function [f] to each | 319 * Enumerates the headers, applying the function [f] to each |
320 * header. The header name passed in [name] will be all lower | 320 * header. The header name passed in [:name:] will be all lower |
321 * case. | 321 * case. |
322 */ | 322 */ |
323 void forEach(void f(String name, List<String> values)); | 323 void forEach(void f(String name, List<String> values)); |
324 | 324 |
325 /** | 325 /** |
326 * Disable folding for the header named [name] when sending the HTTP | 326 * Disables folding for the header named [name] when sending the HTTP |
327 * header. By default, multiple header values are folded into a | 327 * header. By default, multiple header values are folded into a |
328 * single header line by separating the values with commas. The | 328 * single header line by separating the values with commas. The |
329 * Set-Cookie header has folding disabled by default. | 329 * Set-Cookie header has folding disabled by default. |
330 */ | 330 */ |
331 void noFolding(String name); | 331 void noFolding(String name); |
332 | 332 |
333 /** | 333 /** |
334 * Gets and sets the date. The value of this property will | 334 * Gets and sets the date. The value of this property will |
335 * reflect the "DateTime" header. | 335 * reflect the "DateTime" header. |
336 */ | 336 */ |
337 DateTime date; | 337 DateTime date; |
338 | 338 |
339 /** | 339 /** |
340 * Gets and sets the expiry date. The value of this property will | 340 * Gets and sets the expiry date. The value of this property will |
341 * reflect the "Expires" header. | 341 * reflect the "Expires" header. |
342 */ | 342 */ |
343 DateTime expires; | 343 DateTime expires; |
344 | 344 |
345 /** | 345 /** |
346 * Gets and sets the 'if-modified-since' date. The value of this property will | 346 * Gets and sets the "if-modified-since" date. The value of this property will |
347 * reflect the "if-modified-since" header. | 347 * reflect the "if-modified-since" header. |
348 */ | 348 */ |
349 DateTime ifModifiedSince; | 349 DateTime ifModifiedSince; |
350 | 350 |
351 /** | 351 /** |
352 * Gets and sets the host part of the "Host" header for the | 352 * Gets and sets the host part of the "Host" header for the |
353 * connection. | 353 * connection. |
354 */ | 354 */ |
355 String host; | 355 String host; |
356 | 356 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 /** | 429 /** |
430 * Returns the formatted string representation in the form: | 430 * Returns the formatted string representation in the form: |
431 * | 431 * |
432 * value; parameter1=value1; parameter2=value2 | 432 * value; parameter1=value1; parameter2=value2 |
433 */ | 433 */ |
434 String toString(); | 434 String toString(); |
435 } | 435 } |
436 | 436 |
437 abstract class HttpSession implements Map { | 437 abstract class HttpSession implements Map { |
438 /** | 438 /** |
439 * Get the id for the current session. | 439 * Gets the id for the current session. |
440 */ | 440 */ |
441 String get id; | 441 String get id; |
442 | 442 |
443 /** | 443 /** |
444 * Destroy the session. This will terminate the session and any further | 444 * Destroys the session. This will terminate the session and any further |
445 * connections with this id will be given a new id and session. | 445 * connections with this id will be given a new id and session. |
446 */ | 446 */ |
447 void destroy(); | 447 void destroy(); |
448 | 448 |
449 /** | 449 /** |
450 * Set a callback that will be called when the session is timed out. | 450 * Sets a callback that will be called when the session is timed out. |
451 */ | 451 */ |
452 void set onTimeout(void callback()); | 452 void set onTimeout(void callback()); |
453 | 453 |
454 /** | 454 /** |
455 * Is true if the session have not been sent to the client yet. | 455 * Is true if the session has not been sent to the client yet. |
456 */ | 456 */ |
457 bool get isNew; | 457 bool get isNew; |
458 } | 458 } |
459 | 459 |
460 | 460 |
461 /** | 461 /** |
462 * Representation of a content type. | 462 * Representation of a content type. |
463 */ | 463 */ |
464 abstract class ContentType implements HeaderValue { | 464 abstract class ContentType implements HeaderValue { |
465 /** | 465 /** |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 622 |
623 /** | 623 /** |
624 * Returns the client certificate of the client making the request. | 624 * Returns the client certificate of the client making the request. |
625 * Returns null if the connection is not a secure TLS or SSL connection, | 625 * Returns null if the connection is not a secure TLS or SSL connection, |
626 * or if the server does not request a client certificate, or if the client | 626 * or if the server does not request a client certificate, or if the client |
627 * does not provide one. | 627 * does not provide one. |
628 */ | 628 */ |
629 X509Certificate get certificate; | 629 X509Certificate get certificate; |
630 | 630 |
631 /** | 631 /** |
632 * Get the session for the given request. If the session is | 632 * Gets the session for the given request. If the session is |
633 * being initialized by this call, [:isNew:] will be true for the returned | 633 * being initialized by this call, [:isNew:] will be true for the returned |
634 * session. | 634 * session. |
635 * See [:HttpServer.sessionTimeout:] on how to change default timeout. | 635 * See [HttpServer.sessionTimeout] on how to change default timeout. |
636 */ | 636 */ |
637 HttpSession get session; | 637 HttpSession get session; |
638 | 638 |
639 /** | 639 /** |
640 * Returns the HTTP protocol version used in the request. This will | 640 * Returns the HTTP protocol version used in the request. This will |
641 * be "1.0" or "1.1". | 641 * be "1.0" or "1.1". |
642 */ | 642 */ |
643 String get protocolVersion; | 643 String get protocolVersion; |
644 | 644 |
645 /** | 645 /** |
646 * Get information about the client connection. Returns [null] if the socket | 646 * Gets information about the client connection. Returns [null] if the socket |
647 * isn't available. | 647 * is not available. |
648 */ | 648 */ |
649 HttpConnectionInfo get connectionInfo; | 649 HttpConnectionInfo get connectionInfo; |
650 | 650 |
651 /** | 651 /** |
652 * Get the [HttpResponse] object, used for sending back the response to the | 652 * Gets the [HttpResponse] object, used for sending back the response to the |
653 * client. | 653 * client. |
654 */ | 654 */ |
655 HttpResponse get response; | 655 HttpResponse get response; |
656 } | 656 } |
657 | 657 |
658 | 658 |
659 /** | 659 /** |
660 * HTTP response to be send back to the client. | 660 * HTTP response to be send back to the client. |
661 */ | 661 */ |
662 abstract class HttpResponse implements IOSink<HttpResponse> { | 662 abstract class HttpResponse implements IOSink<HttpResponse> { |
(...skipping 30 matching lines...) Expand all Loading... |
693 * Returns the response headers. | 693 * Returns the response headers. |
694 */ | 694 */ |
695 HttpHeaders get headers; | 695 HttpHeaders get headers; |
696 | 696 |
697 /** | 697 /** |
698 * Cookies to set in the client (in the Set-Cookie header). | 698 * Cookies to set in the client (in the Set-Cookie header). |
699 */ | 699 */ |
700 List<Cookie> get cookies; | 700 List<Cookie> get cookies; |
701 | 701 |
702 /** | 702 /** |
703 * Detach the underlying socket from the HTTP server. When the | 703 * Detaches the underlying socket from the HTTP server. When the |
704 * socket is detached the HTTP server will no longer perform any | 704 * socket is detached the HTTP server will no longer perform any |
705 * operations on it. | 705 * operations on it. |
706 * | 706 * |
707 * This is normally used when a HTTP upgrade request is received | 707 * This is normally used when a HTTP upgrade request is received |
708 * and the communication should continue with a different protocol. | 708 * and the communication should continue with a different protocol. |
709 */ | 709 */ |
710 Future<Socket> detachSocket(); | 710 Future<Socket> detachSocket(); |
711 | 711 |
712 /** | 712 /** |
713 * Get information about the client connection. Returns [null] if the socket | 713 * Gets information about the client connection. Returns [null] if the socket |
714 * isn't available. | 714 * is not available. |
715 */ | 715 */ |
716 HttpConnectionInfo get connectionInfo; | 716 HttpConnectionInfo get connectionInfo; |
717 } | 717 } |
718 | 718 |
719 | 719 |
720 /** | 720 /** |
721 * HTTP client factory. The [HttpClient] handles all the sockets associated | 721 * HTTP client factory. The [HttpClient] handles all the sockets associated |
722 * with the [HttpClientConnection]s and when the endpoint supports it, it will | 722 * with the [HttpClientConnection]s and when the endpoint supports it, it will |
723 * try to reuse opened sockets for several requests to support HTTP 1.1 | 723 * try to reuse opened sockets for several requests to support HTTP 1.1 |
724 * persistent connections. This means that sockets will be kept open for some | 724 * persistent connections. This means that sockets will be kept open for some |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 List<Cookie> get cookies; | 887 List<Cookie> get cookies; |
888 | 888 |
889 /** | 889 /** |
890 * Gets and sets the requested persistent connection state. | 890 * Gets and sets the requested persistent connection state. |
891 * The default value is [:true:]. | 891 * The default value is [:true:]. |
892 */ | 892 */ |
893 bool persistentConnection; | 893 bool persistentConnection; |
894 | 894 |
895 /** | 895 /** |
896 * A [HttpClientResponse] future that will complete once the response is | 896 * A [HttpClientResponse] future that will complete once the response is |
897 * available. If an error occours before the response is available, this | 897 * available. If an error occurs before the response is available, this |
898 * future will complete with an error. | 898 * future will complete with an error. |
899 */ | 899 */ |
900 Future<HttpClientResponse> get response; | 900 Future<HttpClientResponse> get response; |
901 | 901 |
902 /** | 902 /** |
903 * Close the request for input. Returns the value of [response]. | 903 * Close the request for input. Returns the value of [response]. |
904 */ | 904 */ |
905 Future<HttpClientResponse> close(); | 905 Future<HttpClientResponse> close(); |
906 | 906 |
907 /** | 907 /** |
(...skipping 19 matching lines...) Expand all Loading... |
927 /** | 927 /** |
928 * Set this property to the maximum number of redirects to follow | 928 * Set this property to the maximum number of redirects to follow |
929 * when [followRedirects] is [:true:]. If this number is exceeded the | 929 * when [followRedirects] is [:true:]. If this number is exceeded the |
930 * [onError] callback will be called with a [RedirectLimitExceeded] | 930 * [onError] callback will be called with a [RedirectLimitExceeded] |
931 * exception. The default value is 5. | 931 * exception. The default value is 5. |
932 */ | 932 */ |
933 int maxRedirects; | 933 int maxRedirects; |
934 | 934 |
935 /** | 935 /** |
936 * Get information about the client connection. Returns [null] if the socket | 936 * Get information about the client connection. Returns [null] if the socket |
937 * isn't available. | 937 * is not available. |
938 */ | 938 */ |
939 HttpConnectionInfo get connectionInfo; | 939 HttpConnectionInfo get connectionInfo; |
940 } | 940 } |
941 | 941 |
942 | 942 |
943 /** | 943 /** |
944 * HTTP response for a client connection. The [HttpClientResponse] is a | 944 * HTTP response for a client connection. The [HttpClientResponse] is a |
945 * [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 |
946 * the data and be notified once the entire body is received. | 946 * the data and be notified once the entire body is received. |
947 | 947 |
948 */ | 948 */ |
949 abstract class HttpClientResponse implements Stream<List<int>> { | 949 abstract class HttpClientResponse implements Stream<List<int>> { |
950 /** | 950 /** |
951 * Returns the status code. | 951 * Returns the status code. |
952 */ | 952 */ |
953 int get statusCode; | 953 int get statusCode; |
954 | 954 |
955 /** | 955 /** |
956 * Returns the reason phrase associated with the status code. | 956 * Returns the reason phrase associated with the status code. |
957 */ | 957 */ |
958 String get reasonPhrase; | 958 String get reasonPhrase; |
959 | 959 |
960 /** | 960 /** |
961 * Returns the content length of the request body. If the size of | 961 * Returns the content length of the request body. Returns -1 if the size of |
962 * the request body is not known in advance this -1. | 962 * the request body is not known in advance. |
963 */ | 963 */ |
964 int get contentLength; | 964 int get contentLength; |
965 | 965 |
966 /** | 966 /** |
967 * Gets the persistent connection state returned by the server. | 967 * Gets the persistent connection state returned by the server. |
968 */ | 968 */ |
969 bool get persistentConnection; | 969 bool get persistentConnection; |
970 | 970 |
971 /** | 971 /** |
972 * Returns whether the status code is one of the normal redirect | 972 * Returns whether the status code is one of the normal redirect |
973 * codes [:HttpStatus.MOVED_PERMANENTLY:], [:HttpStatus.FOUND:], | 973 * codes [HttpStatus.MOVED_PERMANENTLY], [HttpStatus.FOUND], |
974 * [:HttpStatus.MOVED_TEMPORARILY:], [:HttpStatus.SEE_OTHER:] and | 974 * [HttpStatus.MOVED_TEMPORARILY], [HttpStatus.SEE_OTHER] and |
975 * [:HttpStatus.TEMPORARY_REDIRECT:]. | 975 * [HttpStatus.TEMPORARY_REDIRECT]. |
976 */ | 976 */ |
977 bool get isRedirect; | 977 bool get isRedirect; |
978 | 978 |
979 /** | 979 /** |
980 * Returns the series of redirects this connection has been through. The | 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 | 981 * list will be empty if no redirects were followed. [redirects] will be |
982 * updated both in the case of an automatic and a manual redirect. | 982 * updated both in the case of an automatic and a manual redirect. |
983 */ | 983 */ |
984 List<RedirectInfo> get redirects; | 984 List<RedirectInfo> get redirects; |
985 | 985 |
986 /** | 986 /** |
987 * Redirect this connection to a new URL. The default value for | 987 * Redirects this connection to a new URL. The default value for |
988 * [method] is the method for the current request. The default value | 988 * [method] is the method for the current request. The default value |
989 * for [url] is the value of the [:HttpHeaders.LOCATION:] header of | 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 | 990 * the current response. All body data must have been read from the |
991 * current response before calling [redirect]. | 991 * current response before calling [redirect]. |
992 * | 992 * |
993 * All headers added to the request will be added to the redirection | 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 | 994 * request. However, any body sent with the request will not be |
995 * part of the redirection request(s). | 995 * part of the redirection request. |
996 * | 996 * |
997 * If [followLoops] is set to [true], redirect will follow the redirect, | 997 * If [followLoops] is set to [true], redirect will follow the redirect, |
998 * even if was already visited. Default value is [false]. | 998 * even if the URL was already visited. The default value is [false]. |
999 * | 999 * |
1000 * [redirect] will ignore [maxRedirects] and always perform the redirect. | 1000 * [redirect] will ignore [maxRedirects] and will always perform the redirect. |
1001 */ | 1001 */ |
1002 Future<HttpClientResponse> redirect([String method, | 1002 Future<HttpClientResponse> redirect([String method, |
1003 Uri url, | 1003 Uri url, |
1004 bool followLoops]); | 1004 bool followLoops]); |
1005 | 1005 |
1006 | 1006 |
1007 /** | 1007 /** |
1008 * Returns the response headers. | 1008 * Returns the response headers. |
1009 */ | 1009 */ |
1010 HttpHeaders get headers; | 1010 HttpHeaders get headers; |
(...skipping 13 matching lines...) Expand all Loading... |
1024 */ | 1024 */ |
1025 List<Cookie> get cookies; | 1025 List<Cookie> get cookies; |
1026 | 1026 |
1027 /** | 1027 /** |
1028 * Returns the certificate of the HTTPS server providing the response. | 1028 * Returns the certificate of the HTTPS server providing the response. |
1029 * Returns null if the connection is not a secure TLS or SSL connection. | 1029 * Returns null if the connection is not a secure TLS or SSL connection. |
1030 */ | 1030 */ |
1031 X509Certificate get certificate; | 1031 X509Certificate get certificate; |
1032 | 1032 |
1033 /** | 1033 /** |
1034 * Get information about the client connection. Returns [null] if the socket | 1034 * Gets information about the client connection. Returns [null] if the socket |
1035 * isn't available. | 1035 * is not available. |
1036 */ | 1036 */ |
1037 HttpConnectionInfo get connectionInfo; | 1037 HttpConnectionInfo get connectionInfo; |
1038 } | 1038 } |
1039 | 1039 |
1040 | 1040 |
1041 abstract class HttpClientCredentials { } | 1041 abstract class HttpClientCredentials { } |
1042 | 1042 |
1043 | 1043 |
1044 /** | 1044 /** |
1045 * Represent credentials for basic authentication. | 1045 * Represents credentials for basic authentication. |
1046 */ | 1046 */ |
1047 abstract class HttpClientBasicCredentials extends HttpClientCredentials { | 1047 abstract class HttpClientBasicCredentials extends HttpClientCredentials { |
1048 factory HttpClientBasicCredentials(String username, String password) => | 1048 factory HttpClientBasicCredentials(String username, String password) => |
1049 new _HttpClientBasicCredentials(username, password); | 1049 new _HttpClientBasicCredentials(username, password); |
1050 } | 1050 } |
1051 | 1051 |
1052 | 1052 |
1053 /** | 1053 /** |
1054 * Represent credentials for digest authentication. | 1054 * Represents credentials for digest authentication. |
1055 */ | 1055 */ |
1056 abstract class HttpClientDigestCredentials extends HttpClientCredentials { | 1056 abstract class HttpClientDigestCredentials extends HttpClientCredentials { |
1057 factory HttpClientDigestCredentials(String username, String password) => | 1057 factory HttpClientDigestCredentials(String username, String password) => |
1058 new _HttpClientDigestCredentials(username, password); | 1058 new _HttpClientDigestCredentials(username, password); |
1059 } | 1059 } |
1060 | 1060 |
1061 | 1061 |
1062 /** | 1062 /** |
1063 * Connection information. | 1063 * Information about an [HttpRequest], [HttpResponse], [HttpClientRequest], or |
| 1064 * [HttpClientResponse] connection. |
1064 */ | 1065 */ |
1065 abstract class HttpConnectionInfo { | 1066 abstract class HttpConnectionInfo { |
1066 String get remoteHost; | 1067 String get remoteHost; |
1067 int get remotePort; | 1068 int get remotePort; |
1068 int get localPort; | 1069 int get localPort; |
1069 } | 1070 } |
1070 | 1071 |
1071 | 1072 |
1072 /** | 1073 /** |
1073 * Redirect information. | 1074 * Redirect information. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 class RedirectLimitExceededException extends RedirectException { | 1121 class RedirectLimitExceededException extends RedirectException { |
1121 const RedirectLimitExceededException(List<RedirectInfo> redirects) | 1122 const RedirectLimitExceededException(List<RedirectInfo> redirects) |
1122 : super("Redirect limit exceeded", redirects); | 1123 : super("Redirect limit exceeded", redirects); |
1123 } | 1124 } |
1124 | 1125 |
1125 | 1126 |
1126 class RedirectLoopException extends RedirectException { | 1127 class RedirectLoopException extends RedirectException { |
1127 const RedirectLoopException(List<RedirectInfo> redirects) | 1128 const RedirectLoopException(List<RedirectInfo> redirects) |
1128 : super("Redirect loop detected", redirects); | 1129 : super("Redirect loop detected", redirects); |
1129 } | 1130 } |
OLD | NEW |