:- use_module(library(lists)). :- use_module(library(sockets)). :- use_module(library(format)). :- use_module(library(charsio)). stream(Stream, HeaderLines) :- socket_client_open('github.com':443, Stream, [tls(true)]), format(Stream, "\ GET ~s HTTP/1.1\r\n\ Host: ~s\r\n\ User-Agent: Scryer Prolog\r\n\ Connection: close\r\n\r\n\ ", ["/mthom/scryer-prolog","github.com"]), read_line_to_chars(Stream, StatusLine, []), append("HTTP/1.1 ", ['2'|_], StatusLine), read_header_lines(Stream, HeaderLines). read_header_lines(Stream, Hs) :- read_line_to_chars(Stream, Cs, []), ( Cs == "" -> Hs = [] ; Cs == "\r\n" -> Hs = [] ; Hs = [Cs|Rest], read_header_lines(Stream, Rest) ). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?- stream(S, _), length(Ls, 20), maplist(get_char(S), Ls). %@ S = '$stream'(0x7fa2e6f11db0), Ls = "008000\r\n\n\n\n\n\n