Library(http/http_log) saves wrong status

I’m using: SWI-Prolog 64 bits, version 8.1.10-56

I want the code to: I have added use_module(library(http/http_log)). It is writing requests/responses to httpd.log file, but it is writing wrong status codes, it seems like all status codes are 200. When prolog is responding to a requests, it is explicitly setting status code in reply_json. The response should look something like this completed(8, 0.0014660000000000003, 139, 400, bad).

But what I’m getting is: Last line of httpd.log is: completed(8, 0.0014660000000000003, 139, 200, ok).

My code looks like this:

reply_json(ErrorOut, [status(400)])

My suspicion is that it is because I am explicitly setting status codes. Because in reality the code executes properly.

Anyone has any ideas?

I had a look. Status codes set using the Status: code header were not forwarded. I’ve pushed a fix.

P.s. Please include a complete program. That is quicker to process so you get your answer sooner. In this case I constructed this:

:- use_module(library(http/http_server)).
:- use_module(library(http/http_json)).
:- use_module(library(http/http_log)).

:- http_handler(root(.), reply, []).

reply(_Request) :-
    reply_json(_{hello:world}, [status(400)]).
1 Like

Thank you, Jan!

Sorry, but we’ve quite complex structure, so I wont be able to share full program, but next time I will try to create a reproducible snippet.

So I can try to build the latest version from source?

Yes (from swipl-devel.git), but be aware the the recent rational changes are quite massive and may cause some regression. Should be ok for development purposes but for deployment it may be better to cherry-pick the changes into a version that works for you.

1 Like