|
3 | 3 | Author: Jan Wielemaker |
4 | 4 | E-mail: J.Wielemaker@vu.nl |
5 | 5 | WWW: http://www.swi-prolog.org |
6 | | - Copyright (c) 2002-2016, University of Amsterdam |
| 6 | + Copyright (c) 2002-2018, University of Amsterdam |
7 | 7 | VU University Amsterdam |
| 8 | + CWI, Amsterdam |
8 | 9 | All rights reserved. |
9 | 10 |
|
10 | 11 | Redistribution and use in source and binary forms, with or without |
|
285 | 286 | % * status_code(-Code) |
286 | 287 | % If this option is present and Code unifies with the HTTP |
287 | 288 | % status code, do *not* translate errors (4xx, 5xx) into an |
288 | | -% exception. Instead, http_open/3 behaves as if 200 (success) is |
| 289 | +% exception. Instead, http_open/3 behaves as if 2xx (success) is |
289 | 290 | % returned, providing the application to read the error document |
290 | 291 | % from the returned stream. |
291 | 292 | % |
|
361 | 362 | % ]) |
362 | 363 | % == |
363 | 364 | % |
364 | | -% @error existence_error(url, Id) |
365 | | -% @see ssl_context/3 for SSL related options if |
366 | | -% library(http/http_ssl_plugin) is loaded. |
| 365 | +% @throws error(existence_error(url, Id),Context) is raised if the |
| 366 | +% HTTP result code is not in the range 200..299. Context has the |
| 367 | +% shape context(Message, status(Code, TextCode)), where `Code` is the |
| 368 | +% numeric HTTP code and `TextCode` is the textual description thereof |
| 369 | +% provided by the server. `Message` may provide additional details or |
| 370 | +% may be unbound. |
| 371 | +% |
| 372 | +% @see ssl_context/3 for SSL related options if |
| 373 | +% library(http/http_ssl_plugin) is loaded. |
367 | 374 |
|
368 | 375 | :- multifile |
369 | 376 | socket:proxy_for_url/3. % +URL, +Host, -ProxyList |
|
669 | 676 | Options = [method(post)|Options0]. |
670 | 677 | add_method(Options0, [method(get)|Options0]). |
671 | 678 |
|
672 | | - |
673 | 679 | %! do_open(+HTTPVersion, +HTTPStatusCode, +HTTPStatusComment, +Header, |
674 | 680 | %! +Options, +Parts, +Host, +In, -FinalIn) is det. |
675 | 681 | % |
676 | | -% Handle the HTTP status. If 200, we are ok. If a redirect, redo |
677 | | -% the open, returning a new stream. Else issue an error. |
| 682 | +% Handle the HTTP status once available. If 200-299, we are ok. If a |
| 683 | +% redirect, redo the open, returning a new stream. Else issue an |
| 684 | +% error. |
678 | 685 | % |
679 | 686 | % @error existence_error(url, URL) |
680 | 687 |
|
|
717 | 724 | ( option(status_code(Code), Options), |
718 | 725 | Lines \== [] |
719 | 726 | -> true |
720 | | - ; Code == 200 |
| 727 | + ; successful_code(Code) |
721 | 728 | ), |
722 | 729 | !, |
723 | 730 | parts_uri(Parts, URI), |
|
746 | 753 | throw(error(Formal, context(_, status(Code, Comment)))). |
747 | 754 |
|
748 | 755 |
|
| 756 | +successful_code(Code) :- |
| 757 | + between(200, 299, Code). |
| 758 | + |
749 | 759 | %! redirect_limit_exceeded(+Options:list(compound), -Max:nonneg) is semidet. |
750 | 760 | % |
751 | 761 | % True if we have exceeded the maximum redirection length (default 10). |
|
0 commit comments