Prolog "web"

Admin User, erstellt 06. Apr. 2025
         
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
runner_file(common, web, 'XLOG 2.6 http client').
/****************************************************************/
/* HTTP Client without stream */
/****************************************************************/
/* file_property(X, Y) */
runner_pred(http_file_property, 2, common, web, 'XLOG 2.6.1').
runner_case(http_file_property, 2, common, web, 'XLOG 2.6.1, XLOG 1') :-
file_property('http://www.xlog.ch', last_modified(T)),
T == 1740681429000.
runner_case(http_file_property, 2, common, web, 'XLOG 2.6.1, XLOG 2') :-
file_property('http://www.xlog.ch', absolute_path(A)),
A == 'https://www.xlog.ch/'.
runner_case(http_file_property, 2, common, web, 'XLOG 2.6.1, XLOG 3') :-
file_property('http://www.xlog.ch', type(T)),
T == regular.
runner_case(http_file_property, 2, common, web, 'XLOG 2.6.1, XLOG 4') :-
catch(file_property('http://www.xlog.ch/foo.html', _), error(E,_), true),
E == existence_error(source_sink, 'http://www.xlog.ch/foo.html').
/* open(X, Y, Z, T) results */
runner_pred(http_open_results, 4, common, web, 'XLOG 2.6.2').
runner_case(http_open_results, 4, common, web, 'XLOG 2.6.2, XLOG 1') :-
open('http://www.xlog.ch/', read, Stream, [uri(Uri)]),
close(Stream),
Uri == 'https://www.xlog.ch/'.
runner_case(http_open_results, 4, common, web, 'XLOG 2.6.2, XLOG 2') :-
open('http://www.xlog.ch/', read, Stream, [status(Status)]),
close(Stream),
Status == 200.
runner_case(http_open_results, 4, common, web, 'XLOG 2.6.2, XLOG 3') :-
open('http://www.xlog.ch/', read, Stream, [fields(Fields)]),
close(Stream),
member('last-modified'-Date, Fields),
Date == 'Thu, 27 Feb 2025 18:37:09 GMT'.
runner_case(http_open_results, 4, common, web, 'XLOG 2.6.2, XLOG 4') :-
open('http://www.xlog.ch', read, Stream),
get_code(Stream, Code),
close(Stream),
Code == 60.
runner_case(http_open_results, 4, common, web, 'XLOG 2.6.2, XLOG 5') :-
open('http://www.xlog.ch', read, Stream, [method('HEAD')]),
get_code(Stream, Code),
close(Stream),
Code == -1.
/****************************************************************/
/* HTTP Client with stream */
/****************************************************************/
/* open(X, Y, Z) */
runner_pred(http_open, 3, common, web, 'XLOG 2.6.3').
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 1') :-
open('https://www.xlog.ch/index.html', read, S),
get_atom(S,A,[stop(-1)]), atom_length(A,L), close(S),
L == 4274.
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 2') :-
open('https://www.xlog.ch/index.html', read, S),
get_atom(S,A,[stop(-1)]), sub_atom(A,1165,13,_,T), close(S),
T == ' width: 12.5e'.
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 3') :-
open('https://www.xlog.ch/binary/file/foo.txt', read, S, [type(binary)]),
get_atom(S,A,[stop(-1),compress(false)]), atom_length(A,L), close(S),
L == 256.
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 4') :-
open('https://www.xlog.ch/binary/file/foo.txt', read, S, [type(binary)]),
get_atom(S,A,[stop(-1),compress(false)]), sub_atom(A,165,13,_,T), close(S),
T == '¥¦§¨©ª«¬\255\®¯°±'.
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 5') :-
catch(open('http://locahost/foo.html', read, _), error(E,_), true),
E == resource_error(unknown_host).
runner_case(http_open, 3, common, web, 'XLOG 2.6.3, XLOG 6') :-
catch(open('http://localhost:9999/foo.html', read, _), error(E,_), true),
E == resource_error(connect_failed).
/* open(X, Y, Z, T) options */
runner_pred(http_options, 4, common, web, 'XLOG 2.6.4').
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 1') :-
open('https://www.xlog.ch/echo/get?foo1=bar1&foo2=bar2', read, Stream),
read_json(Stream, Response),
close(Stream),
Response == {method:'GET', uri:'/echo/get',
args:{foo1:bar1, foo2:bar2}}.
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 2') :-
json_atom({foo:123, bar:baz}, Request),
open('https://www.xlog.ch/echo/post', read, Stream, [
headers(['Content-Type'-'application/json;charset=utf-8']),
body(Request)]),
read_json(Stream, Response),
close(Stream),
Response == {method:'POST', uri:'/echo/post',
args:{}, body:{foo:123, bar:baz}}.
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 3') :-
open('https://www.xlog.ch/echo/delete?foo1=bar1&foo2=bar2', read,
Stream, [method('DELETE')]),
read_json(Stream, Response),
close(Stream),
Response == {method:'DELETE', uri:'/echo/delete',
args:{foo1:bar1, foo2:bar2}}.
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 4') :-
catch(open('https://www.xlog.ch/echo/get?foo1=bar1&foo2=bar2', read,
_, [method('DELETE')]), error(E,_), true),
E == resource_error(illegal_method).
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 5') :-
json_atom({foo:123, bar:baz}, Request),
open('https://www.xlog.ch/echo/put', read,
Stream, [method('PUT'),
headers(['Content-Type'-'application/json;charset=utf-8']),
body(Request)]),
read_json(Stream, Response),
close(Stream),
Response == {method:'PUT', uri:'/echo/put',
args:{}, body:{foo:123, bar:baz}}.
runner_case(http_options, 4, common, web, 'XLOG 2.6.4, XLOG 6') :-
open('https://www.xlog.ch/echo/raw', read, Stream, [
headers(['Content-Type'-'text/plain;charset=iso-8859-1']),
body('Hello World! øùúûüý', [type(binary)])]),
read_json(Stream, Response),
close(Stream),
Response == {method:'POST', uri:'/echo/raw',
args:{}, body:'Hello World! øùúûüý'}.