:- use_module(library(http)).
handle(C, "GET", "/", Ver, Hdrs) :-
format(C, "HTTP/~w 200 Ok\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n", [Ver]),
format(C, "
Home
~w
\n", [Hdrs]).
handle(C, _, _, Ver, _) :-
format(C, "HTTP/~w 500 Server Error\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n", [Ver]),
bwrite(C, "500 Server Error
\n").
main :-
fork,
server(":8080", S, []),
accept(S, C),
fork,
http_request(C, Method, Path, Ver, Hdrs),
writeq([Method, Path, Ver, Hdrs]), nl,
handle(C, Method, Path, Ver, Hdrs),
close(C),
!.
main :-
wait.