Skip to content

Commit 182c775

Browse files
AnniepooJan Wielemaker
authored andcommitted
MODIFIED: http_open/3: accept status codes 201 thru 299 as successful.
1 parent 5b40e87 commit 182c775

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

http_open.pl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Author: Jan Wielemaker
44
E-mail: J.Wielemaker@vu.nl
55
WWW: http://www.swi-prolog.org
6-
Copyright (c) 2002-2016, University of Amsterdam
6+
Copyright (c) 2002-2018, University of Amsterdam
77
VU University Amsterdam
8+
CWI, Amsterdam
89
All rights reserved.
910
1011
Redistribution and use in source and binary forms, with or without
@@ -285,7 +286,7 @@
285286
% * status_code(-Code)
286287
% If this option is present and Code unifies with the HTTP
287288
% 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
289290
% returned, providing the application to read the error document
290291
% from the returned stream.
291292
%
@@ -361,9 +362,15 @@
361362
% ])
362363
% ==
363364
%
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.
367374

368375
:- multifile
369376
socket:proxy_for_url/3. % +URL, +Host, -ProxyList
@@ -669,12 +676,12 @@
669676
Options = [method(post)|Options0].
670677
add_method(Options0, [method(get)|Options0]).
671678

672-
673679
%! do_open(+HTTPVersion, +HTTPStatusCode, +HTTPStatusComment, +Header,
674680
%! +Options, +Parts, +Host, +In, -FinalIn) is det.
675681
%
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.
678685
%
679686
% @error existence_error(url, URL)
680687

@@ -717,7 +724,7 @@
717724
( option(status_code(Code), Options),
718725
Lines \== []
719726
-> true
720-
; Code == 200
727+
; successful_code(Code)
721728
),
722729
!,
723730
parts_uri(Parts, URI),
@@ -746,6 +753,9 @@
746753
throw(error(Formal, context(_, status(Code, Comment)))).
747754

748755

756+
successful_code(Code) :-
757+
between(200, 299, Code).
758+
749759
%! redirect_limit_exceeded(+Options:list(compound), -Max:nonneg) is semidet.
750760
%
751761
% True if we have exceeded the maximum redirection length (default 10).

0 commit comments

Comments
 (0)