I don't fully understand how SWI Prolog handles http. I have the following code which mostly works apart from the get_header/1
. I need to be able to reader the header file of the http request to get a value. How do I do that? Do I use http_read_header/2
? If so how?
:- http_handler(root(handle), myhandle,[]).
myhandle(Request):-
get_header(H),
http_read_json_dict(Request,DictIn),
handle_dict(DictIn,DictOut),
reply_json(DictOut).
get_header(H):-
http_read_header(current_input, H),
something(H).
First, when posting a question about the HTTP libraries, please include the full code.
This means the server and client that you use to post the request.
From just your question, nobody has any idea what you are doing. This is typical for questions about HTTP libraries, and I hope becomes less common in the future.
Second, the Request
is already a list of Name(Value)
elements.
Any header field that was sent by the client is included in this list. It is simply a matter of looking up the value in this list, using typical predicates that reason over lists, such as member/2
and option/3
.
For example, if the client has submitted the header The-Field: x
, then
member(the_field(Value), Request), ...
will yield Value = x
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With