Help with http_get/3

I am using http_get/3 to connect to a foreign server with the following code:

% SWI-Prolog (threaded, 64 bits, version 9.3.28)

:- use_module(library(http/http_header)).
:- use_module(library(http/http_client)).
:- use_module(library(http/http_json)).
:- use_module(library(uri)).

request_header(_, authorization(bearer(Token))):-session(Token).
request_header(_, user_agent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15')).
request_header(_, json_object(dict)).
request_header(_, value_string_as(atom)).
% and some more

request_headers(Subject, Headers):- setof(H, request_header(Subject, H), Headers).

my_request:-
% Setup Url, then
request_headers(my_subject, Headers),
http_get(Url, Response, [Headers])
...

In this case Response holds a json object such as “json([‘SUCCESS’= @(false), ‘MESSAGE’=‘OAuth verification failed’])“

If I replace http_get with the following:

http_get(Url, Response, [ reply_header(ReplyHeaders) |Headers])  

Response will hold a dict with the expected data, and ReplyHeaders holds a list with “administrative data” about the request

Obviously, http_get/3 sends a very different request if the option reply_header is provided.

Question: What is the difference between both calls, and why should this matter?

For debugging info: can use e.g. https://requestcatcher.com/ to see what is being sent (don’t give it e.g. valid authentication tokens, of course).

Could well be the use of the important status_code option, which is a reply header:

status_code(-Code)
    If this option is present and Code unifies with the HTTP status code, do not translate errors (4xx, 5xx) into an exception. Instead, http_open/3 behaves as if 2xx (success) is returned, providing the application to read the error document from the returned stream.

From SWI-Prolog -- The HTTP client libraries

Headers is a list, so you pass [[opt(val), ...]] rather than [opt(val), ...]

It should not. It merely makes header fields of the reply accessible. Note that the docs say this is a backward compatibility option. Note that the option values should be unbound.

If weird things happen, use

 ?- debug(http(_)).

before http_get/3. That will print details on the request sent and response received. Note that recent versions have the libraries compiled in optimised mode, disabling debug/3 statements. To use them anyway, use

 swipl -Dsource ...

Or use this before loading these libraries.

?- set_prolog_flag(source, true).

Oops.

When using “http_get(Url, Response, Headers)” things go well and work as expected!

Thanks a lot.