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 /** | 5 /** |
6 * HTTP status codes. | 6 * HTTP status codes. |
7 */ | 7 */ |
8 interface HttpStatus { | 8 interface HttpStatus { |
9 static final int CONTINUE = 100; | 9 static final int CONTINUE = 100; |
10 static final int SWITCHING_PROTOCOLS = 101; | 10 static final int SWITCHING_PROTOCOLS = 101; |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 */ | 499 */ |
500 void set onResponse(void callback(HttpClientResponse response)); | 500 void set onResponse(void callback(HttpClientResponse response)); |
501 | 501 |
502 /** | 502 /** |
503 * Sets the handler that gets called if an error occurs while | 503 * Sets the handler that gets called if an error occurs while |
504 * connecting or processing the HTTP request. | 504 * connecting or processing the HTTP request. |
505 */ | 505 */ |
506 void set onError(void callback(e)); | 506 void set onError(void callback(e)); |
507 | 507 |
508 /** | 508 /** |
509 * Set this property to [:true:] if this connection should | |
510 * automatically follow redirects. The default is [:false:]. | |
Anders Johnsen
2012/05/08 12:58:16
I can see wget does this by default. Why would we
Søren Gjesse
2012/05/08 13:32:16
Well we can - changed the default to true.
| |
511 */ | |
512 bool followRedirect; | |
513 | |
514 /** | |
515 * Set this property to the maximum number of redirects to follow | |
516 * when [followRedirect] is [:true:]. If this number is exceeded the | |
517 * [onError] callback will be called with an [RedirectLimitExceeded] | |
Mads Ager (google)
2012/05/08 12:48:53
an -> a?
Søren Gjesse
2012/05/08 13:32:16
Done.
| |
518 * exception. The default value is 5. | |
519 */ | |
520 int maxRedirects; | |
521 | |
522 /** | |
523 * Returns the series of redirects this connection has been through. | |
524 */ | |
525 List<RedirectInfo> get redirects(); | |
Anders Johnsen
2012/05/08 12:58:16
Really cool!
Søren Gjesse
2012/05/08 13:32:16
Thanks.
| |
526 | |
527 /** | |
528 * Redirect this connection to a new URL. The default value for | |
529 * [method] is the method for the current request. The default value | |
530 * for [url] is the value of the [:HttpStatus.LOCATION:] header of | |
531 * the current response. All body data nost have been read from the | |
Mads Ager (google)
2012/05/08 12:48:53
nost -> must
Anders Johnsen
2012/05/08 12:58:16
nost->most.
Søren Gjesse
2012/05/08 13:32:16
Done.
Søren Gjesse
2012/05/08 13:32:16
most -> must :-)
| |
532 * current response before calling [redirect]. | |
533 */ | |
534 void redirect([String method, Uri url]); | |
535 | |
536 /** | |
509 * Detach the underlying socket from the HTTP client. When the | 537 * Detach the underlying socket from the HTTP client. When the |
510 * socket is detached the HTTP client will no longer perform any | 538 * socket is detached the HTTP client will no longer perform any |
511 * operations on it. | 539 * operations on it. |
512 * | 540 * |
513 * This is normally used when a HTTP upgrade is negotiated and the | 541 * This is normally used when a HTTP upgrade is negotiated and the |
514 * communication should continue with a different protocol. | 542 * communication should continue with a different protocol. |
515 */ | 543 */ |
516 DetachedSocket detachSocket(); | 544 DetachedSocket detachSocket(); |
517 } | 545 } |
518 | 546 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 */ | 588 */ |
561 String get reasonPhrase(); | 589 String get reasonPhrase(); |
562 | 590 |
563 /** | 591 /** |
564 * Returns the content length of the request body. If the size of | 592 * Returns the content length of the request body. If the size of |
565 * the request body is not known in advance this -1. | 593 * the request body is not known in advance this -1. |
566 */ | 594 */ |
567 int get contentLength(); | 595 int get contentLength(); |
568 | 596 |
569 /** | 597 /** |
598 * Returns whether the status code is one of the normal redirect | |
599 * codes [:HttpStatus.MOVED_PERMANENTLY:], [:HttpStatus.FOUND:], | |
600 * [:HttpStatus.MOVED_TEMPORARILY:], [:HttpStatus.SEE_OTHER:] and | |
601 * [:HttpStatus.TEMPORARY_REDIRECT:]. | |
602 */ | |
603 bool get isRedirect(); | |
604 | |
605 /** | |
570 * Returns the response headers. | 606 * Returns the response headers. |
571 */ | 607 */ |
572 HttpHeaders get headers(); | 608 HttpHeaders get headers(); |
573 | 609 |
574 /** | 610 /** |
575 * Returns the input stream for the response. This is used to read | 611 * Returns the input stream for the response. This is used to read |
576 * the response data. | 612 * the response data. |
577 */ | 613 */ |
578 InputStream get inputStream(); | 614 InputStream get inputStream(); |
579 } | 615 } |
580 | 616 |
581 | 617 |
582 /** | 618 /** |
619 * Redirect information. | |
620 */ | |
621 interface RedirectInfo { | |
622 /** | |
623 * Returns the status code used for the redirect. | |
624 */ | |
625 int get statusCode(); | |
626 | |
627 /** | |
628 * Returns the method used for the redirect. | |
629 */ | |
630 String get method(); | |
631 | |
632 /** | |
633 * Returns the location for the redirect. | |
634 */ | |
635 Uri get location(); | |
636 } | |
637 | |
638 | |
639 /** | |
583 * When detaching a socket from either the [:HttpServer:] or the | 640 * When detaching a socket from either the [:HttpServer:] or the |
584 * [:HttpClient:] due to a HTTP connection upgrade there might be | 641 * [:HttpClient:] due to a HTTP connection upgrade there might be |
585 * unparsed data already read from the socket. This unparsed data | 642 * unparsed data already read from the socket. This unparsed data |
586 * together with the detached socket is returned in an instance of | 643 * together with the detached socket is returned in an instance of |
587 * this class. | 644 * this class. |
588 */ | 645 */ |
589 interface DetachedSocket default _DetachedSocket { | 646 interface DetachedSocket default _DetachedSocket { |
590 Socket get socket(); | 647 Socket get socket(); |
591 List<int> get unparsedData(); | 648 List<int> get unparsedData(); |
592 } | 649 } |
593 | 650 |
594 | 651 |
595 class HttpException implements Exception { | 652 class HttpException implements Exception { |
596 const HttpException([String this.message = ""]); | 653 const HttpException([String this.message = ""]); |
597 String toString() => "HttpException: $message"; | 654 String toString() => "HttpException: $message"; |
598 final String message; | 655 final String message; |
599 } | 656 } |
657 | |
658 | |
659 class RedirectException extends HttpException { | |
660 const RedirectException(String message, | |
661 List<RedirectInfo> this.redirects) : super(message); | |
662 final List<RedirectInfo> redirects; | |
663 } | |
664 | |
665 | |
666 class RedirectLimitExceeded extends RedirectException { | |
667 const RedirectLimitExceeded(List<RedirectInfo> redirects) | |
668 : super("Redirect limit exceeded", redirects); | |
669 } | |
670 | |
671 | |
672 class RedirectLoop extends RedirectException { | |
673 const RedirectLoop(List<RedirectInfo> redirects) | |
674 : super("Redirect loop detected", redirects); | |
675 } | |
OLD | NEW |