Did you know ... Search Documentation:
Title for pldoc(dir_index)

SWI-Prolog HTTP support library

This directory provides the SWI-Prolog libraries for accessing and providing HTTP services.

Client library

The main client library is library(http/http_open), which can open both HTTP and HTTPS connections and handle all request methods.

Server library

The main server libraris are

  • library(http/thread_httpd) implements the server
  • library(http/http_dispatch) implements binding locations predicates
  • library(http/http_unix_daemon) implements integration in various Unix server managers and in general provides a suitable entry point for HTTP servers on Unix.
  • library(http/html_write) implements generating HTML
  • library(http/http_json) implements reading and writing JSON documents.

For simplicity, you can use library(http/http_server), which combines the typical HTTP libraries that most servers need. The idea of a common request handling system and three controlling libraries is outdated; the threaded server now being the only sensible controlling library.

Requirements

This library uses functionality from the ssl package to support HTTPS, the sgml package to read XML/HTML and the clib package for various extensions.

Prolog files

ax.pl  -- Attribute Exchange libraryShow source
ax_alias/2True when Alias is an alias name for the AX schema URL.Source
ax_form_attributes/2True if Values is a list Alias(Value) for each exchanged attribute.Source
http_ax_attributes/2True when HTTPAttributes is a list of Name=Value pairs that can be used with an HTTP request to query for the attributes Spec.Source
graphql.pl  -- GraphQL interfaceShow source
graphql/4Quasi-quotation syntax for embedding GraphQL in Prolog text.Source
graphql_auth_token_hook/2Multifile, dynamic hook.Source
graphql_document_to_codes/3Serialize Document, a Prolog term representing a GraphQL document as obtained from graphql_read_document/3 or the graphql/4 quasi-quotation, and unify Codes with the resulting list of character codes.Source
graphql_document_to_string/3Serialize the GraphQL document Document and unify String with the resulting string.Source
graphql_execute_document/4Send GraphQL document Document to be executed by the GraphQL endpoint at URI.Source
graphql_read_document/3True when Document is a term representing the abstract syntax tree obtained from parsing Source as a GraphQL executable document.Source
html_head.pl  -- Automatic inclusion of CSS and scripts linksShow source
html_current_resource/1True when About is a currently known resource.Source
html_insert_resource/3Actually include HTML head resources.Source
html_requires/3Include ResourceOrList and all dependencies derived from it and add them to the HTML head using html_post/2.Source
html_resource/2Register an HTML head resource.Source
mime_include/4Hook called to include a link to an HTML resource of type Mime into the HTML head.Source
html_quasiquotations.pl  -- HTML quasi quotationsShow source
html/4The predicate html/4 implements HTML quasi quotations.Source
html_write.pl  -- Write HTML textShow source
html/3Generate HTML from Content.Source
html_begin/3For html_begin//1, Env is a term Env(Attributes); for html_end//1 it is the plain environment name.Source
html_current_option/1True if Option is an active option for the HTML generator.Source
html_end/3For html_begin//1, Env is a term Env(Attributes); for html_end//1 it is the plain environment name.Source
html_header_hook/1This multifile hook is called just before the Content-type header is emitted.Source
html_meta/1This directive can be used to declare that an HTML rendering rule takes HTML content as argument.Source
html_post/4Reposition HTML to the receiving Id.Source
html_print_length/2Determine the content length of a token list produced using html//1.Source
html_quoted/3Quote the value for normal (CDATA) text.Source
html_quoted_attribute/3Quote the value according to the rules for tag-attributes included in double-quotes.Source
html_receive/3Receive posted HTML tokens.Source
html_receive/4This extended version of html_receive//1 causes Handler to be called to process all messages posted to the channal at the time output is generated.Source
html_root_attribute/4Add an attribute to the HTML root element of the page.Source
html_set_options/1Set options for the HTML output.Source
layout/3Define required newlines before and after tags.Source
page/3Generate a page including the HTML <!DOCTYPE> header.Source
page/4Generate a page including the HTML <!DOCTYPE> header.Source
print_html/1Print list of atoms and layout instructions.Source
print_html/2Print list of atoms and layout instructions.Source
reply_html_page/2Provide the complete reply as required by http_wrapper.pl for a page constructed from Head and Body.Source
reply_html_page/3Provide the complete reply as required by http_wrapper.pl for a page constructed from Head and Body.Source
reply_html_partial/1Reply with partial HTML document.Source
xhtml_ns/4Demand an xmlns:id=Value in the outer html tag.Source
htmx.pl  -- Support htmx.orgShow source
reply_htmx/1Reply a plain HTML element as opposed to a complete HTML page as created using reply_html_page/2,3.Source
reply_htmx/2Reply a plain HTML element as opposed to a complete HTML page as created using reply_html_page/2,3.Source
http_authenticate.pl  -- Authenticate HTTP connections using 401 headersShow source
http_authenticate/3True if Request contains the information to continue according to Type.Source
http_authorization_data/2Decode the HTTP Authorization header.Source
http_current_user/3True when User is present in the htpasswd file File and Fields provides the additional fields.Source
http_read_passwd_file/2Read a password file.Source
http_write_passwd_file/2Write password data Data to File.Source
authenticate/3Plugin for library(http_dispatch) to perform basic HTTP authentication.Source
http_client.pl  -- HTTP client libraryShow source
post_data_hook/3Hook to extend the datatypes supported by the post(Data) option of http_open/3.Source
http_convert_data/4Multi-file hook to convert a HTTP payload according to the Content-Type header.Source
http_delete/3Execute a DELETE method on the server.Source
http_disconnect/1Close down some connections.Source
http_get/3Get data from a URL server and convert it to a suitable Prolog representation based on the Content-Type header and plugins.Source
http_patch/4Issue an HTTP PATCH request.Source
http_post/4Issue an HTTP POST request.Source
http_put/4Issue an HTTP PUT request.Source
http_read_data/3Read data from an HTTP connection and convert it according to the supplied to(Format) option or based on the Content-type in the Request.Source
http_cookie.pl  -- HTTP client cookie handlingShow source
update_cookies/3Update the client cookie database.Source
write_cookies/3Emit a cookie header for the current request.Source
cookie_remove_all_clients/0Simply logout all clients.Source
cookie_remove_client/1Fake user quitting a browser.Source
http_cors.pl  -- Enable CORS: Cross-Origin Resource SharingShow source
cors_enable/0Emit the HTTP header Access-Control-Allow-Origin using domains from the setting http:cors.Source
cors_enable/2CORS reply to a Preflight OPTIONS request.Source
http_digest.pl  -- HTTP Digest authenticationShow source
authenticate/3Plugin for library(http_dispatch) to perform basic HTTP authentication.Source
authenticate_client/2This hooks is called by http_open/3 with the following Action value:.Source
http_digest_challenge/4Generate the content for a 401 WWW-Authenticate: Digest header field.Source
http_digest_password_hash/4Compute the password hash for the HTTP password file.Source
http_digest_response/5Formulate a reply to a digest authentication request.Source
http_parse_digest_challenge/2Parse the value of an HTTP WWW-Authenticate header into a list of Name(Value) terms.Source
http_dirindex.pl  -- HTTP directory listingsShow source
mime_type_icon/2Multi-file hook predicate that can be used to associate icons to files listed by http_reply_dirindex/3.Source
directory_index/4Show index for a directory.Source
http_reply_dirindex/3Provide a directory listing for Request, assuming it is an index for the physical directrory Dir.Source
http_dispatch.pl  -- Dispatch requests in the HTTP serverShow source
http_404/2Reply using an "HTTP 404 not found" page.Source
http_current_handler/2True if Location is handled by Closure.Source
http_current_handler/3Resolve the current handler and options to execute it.Source
http_delete_handler/1Delete handler for Spec.Source
http_dispatch/1Dispatch a Request using http_handler/3 registrations.Source
http_handler/3Register Closure as a handler for HTTP requests.Source
http_link_to_id/3HREF is a link on the local server to a handler with given ID, passing the given Parameters.Source
http_location_by_id/2True when Location represents the HTTP path to which the handler with identifier ID is bound.Source
http_redirect/3Redirect to a new location.Source
http_reload_with_parameters/3Create a request on the current handler with replaced search parameters.Source
http_reply_file/3Options is a list of.Source
http_request_expansion/2Register Goal for expanding the HTTP request handler.Source
http_safe_file/2True if FileSpec is considered safe.Source
http_switch_protocol/2Send an "HTTP 101 Switching Protocols" reply.Source
http_dyn_workers.pl  -- Dynamically schedule HTTP workers.Show source
schedule_workers/1Called if there is no immediately free worker to handle the incomming request.Source
http_error.pl  -- Decorate uncaught HTTP exceptions with stack-traceShow source
http_exception.pl  -- Map Prolog exceptions to HTTP errorsShow source
bad_request_error/2If an exception of the term error(Formal, context(Stack, Context)) is caught and subsumes_term(ContextTemplate, Context) is true, translate the exception into an HTTP 400 exception.
in_or_exclude_backtrace/2Remove the stacktrace from the exception, unless setting http:client_backtrace is true.Source
map_exception_to_http_status/4Map certain exceptions to HTTP status codes.Source
http_files.pl  -- Serve plain files from a hierarchyShow source
http_reply_from_files/3HTTP handler that serves files from the directory Dir.Source
http_header.pl  -- Handling HTTP headersShow source
http_hook.pl  -- HTTP library hooksShow source
convert_parameter/3Hook to execute a step in the HTTP parameter conversion process.
http_connection_over_proxy/6Try to connect to the host Endpoint via Proxy for the purposes of retrieving the resource identified by URLParts.Source
http_host.pl  -- Obtain public server locationShow source
http_current_host/4Source
http_public_host/4Current global host and port of the HTTP server.Source
http_public_host_url/2True when URL is the public URL at which this server can be contacted.Source
http_public_url/2True when URL is an absolute URL for the current request.Source
http_json.pl  -- HTTP JSON Plugin moduleShow source
post_data_hook/3Hook implementation that allows http_post_data/3 posting JSON objects using one of the forms below.Source
http_convert_data/4Hook implementation that supports reading JSON documents.Source
http_read_json/2Extract JSON data posted to this HTTP request.Source
http_read_json/3Extract JSON data posted to this HTTP request.Source
http_read_json_dict/2Similar to http_read_json/2,3, but by default uses the version 7 extended datatypes.Source
http_read_json_dict/3Similar to http_read_json/2,3, but by default uses the version 7 extended datatypes.Source
is_json_content_type/1True if ContentType is a header value (either parsed or as atom/string) that denotes a JSON value.Source
json_type/1True if MediaType is a JSON media type.Source
reply_json/1Formulate a JSON HTTP reply.Source
reply_json/2Formulate a JSON HTTP reply.Source
reply_json_dict/1As reply_json/1 and reply_json/2, but assumes the new dict based data representation.Source
reply_json_dict/2As reply_json/1 and reply_json/2, but assumes the new dict based data representation.Source
http_load.pl  -- Load Prolog code from a web serverShow source
prolog_load_file/2Hook into load_files/2 that loads http:// and https:// resources directly from the web.Source
http_log.plShow source
http_log/2Write message from Format and Args to log-stream.Source
http_log_close/1If there is a currently open HTTP logfile, close it after adding a term server(Reason, Time).Source
http_log_stream/1True when Stream is a stream to the opened HTTP log file.Source
http_logrotate/1Rotate the available log files.Source
http_schedule_logrotate/2Schedule log rotation based on maintenance broadcasts.Source
nolog/1Multifile predicate that can be defined to hide request parameters from the request logfile.Source
nolog_post_content_type/1Multifile hook called with the Content-type header.Source
password_field/1Multifile predicate that can be defined to hide passwords from the logfile.Source
post_data_encoded/2Encode the POST body for inclusion into the HTTP log file.Source
http_multipart_plugin.pl  -- Multipart form-data pluginShow source
http_convert_data/4Convert multipart/form-data messages for http_read_data/3.Source
http_open.pl  -- HTTP client libraryShow source
disable_encoding_filter/1Do not use the Content-encoding as Transfer-encoding encoding for specific values of ContentType.Source
http_close_keep_alive/1Close all keep-alive connections matching Address.Source
http_open/3Open the data at the HTTP server as a Prolog stream.Source
http_set_authorization/2Set user/password to supply with URLs that have URL as prefix.Source
keep_alive/4Callback when closing the range stream used to process the content of the reply.Source
map_method/2Support additional METHOD keywords.Source
open_hook/6Hook implementation that makes open_any/5 support http and https URLs for Mode == read.Source
http_openid.pl  -- OpenID consumer and server libraryShow source
openid_associate/3Calls openid_associate/4 as.Source
openid_associate/4Associate with an open-id server.Source
openid_authenticate/4Succeeds if Request comes from the OpenID server and confirms that User is a verified OpenID user.Source
openid_current_host/3Find current location of the server.Source
openid_current_url/2Find the public URL for Request that we can make available to our identity provider.Source
openid_grant/1Handle the reply from checkid_setup_server/3.Source
openid_hook/1Call hook on the OpenID management library.Source
openid_logged_in/1True if session is associated with OpenID.Source
openid_login/1Associate the current HTTP session with OpenID.Source
openid_login_form/4Create the OpenID form.Source
openid_logout/1Remove the association of the current session with any OpenID.Source
openid_server/2Realise the OpenID server.Source
openid_server/3True if OpenIDLogin is the typed id for OpenID verified by Server.Source
openid_user/3True if OpenID is a validated OpenID associated with the current session.Source
openid_verify/2Handle the initial login form presented to the user by the relying party (consumer).Source
ssl_verify/5Accept all certificates.Source
http_parameters.pl  -- Extract parameters (GET and POST) from HTTP requestsShow source
http_convert_parameter/4Conversion of an HTTP form value.Source
http_convert_parameters/2Implements the parameter translation of http_parameters/2 or http_parameters/3.Source
http_convert_parameters/3Implements the parameter translation of http_parameters/2 or http_parameters/3.Source
http_parameters/2Get HTTP GET or POST form-data, applying type validation, default values, etc.Source
http_parameters/3Get HTTP GET or POST form-data, applying type validation, default values, etc.Source
http_path.pl  -- Abstract specification of HTTP server locationsShow source
location/3Multifile hook used to specify new HTTP locations.Source
http_absolute_location/3Path is the HTTP location for the abstract specification Spec.Source
http_absolute_uri/2URI is the absolute (i.e., starting with http://) URI for the abstract specification Spec.Source
http_clean_location_cache/0HTTP locations resolved through http_absolute_location/3 are cached.Source
http_proxy.pl  -- Use HTTP network proxiesShow source
http_pwp.pl  -- Serve PWP pages through the HTTP serverShow source
pwp_handler/2Handle PWP files.Source
reply_pwp_page/3Reply a PWP file.Source
http_redis_plugin.pl  -- Hook session management to use RedisShow source
http_server.pl  -- HTTP server libraryShow source
http_server/1Create an HTTP server using http_dispatch/1 for handling requests.Source
http_server_files.pl  -- Serve files needed by modules from the serverShow source
serve_files_in_directory/2Serve files from the directory Alias from the path-info from Request.Source
http_server_health.pl  -- HTTP Server health statisticsShow source
health/2Multifile extensible.Source
hide/1Multifile hook.Source
server_health/1HTTP handler that replies with the overall health of the server.Source
http_session.pl  -- HTTP Session managementShow source
http_close_session/1Closes an HTTP session.Source
http_current_session/2Enumerate the current sessions and associated data.Source
http_in_session/1True if SessionId is an identifier for the current session.Source
http_open_session/2Establish a new session.Source
http_session_assert/1Versions of assert/1, retract/1 and retractall/1 that associate data with the current HTTP session.Source
http_session_assert/2Versions of assert/1, retract/1 and retractall/1 that associate data with an explicit HTTP session.Source
http_session_asserta/1Versions of assert/1, retract/1 and retractall/1 that associate data with the current HTTP session.Source
http_session_asserta/2Versions of assert/1, retract/1 and retractall/1 that associate data with an explicit HTTP session.Source
http_session_cookie/1Generate a random cookie that can be used by a browser to identify the current session.Source
http_session_data/1True if Data is associated using http_session_assert/1 to the current HTTP session.Source
http_session_data/2Versions of assert/1, retract/1 and retractall/1 that associate data with an explicit HTTP session.Source
http_session_id/1True if SessionId is an identifier for the current session.Source
http_session_option/1True if Option is a current option of the session system.Source
http_session_retract/1Versions of assert/1, retract/1 and retractall/1 that associate data with the current HTTP session.Source
http_session_retract/2Versions of assert/1, retract/1 and retractall/1 that associate data with an explicit HTTP session.Source
http_session_retractall/1Versions of assert/1, retract/1 and retractall/1 that associate data with the current HTTP session.Source
http_session_retractall/2Versions of assert/1, retract/1 and retractall/1 that associate data with an explicit HTTP session.Source
http_set_session/1Overrule a setting for the current or specified session.Source
http_set_session/2Overrule a setting for the current or specified session.Source
http_set_session_options/1Set options for the session library.Source
session_setting/2Find setting for SessionID.Source
http_sgml_plugin.pl  -- Parse of HTML and XML documents for the HTTP client libsShow source
http_stream.pl  -- HTTP StreamsShow source
current_transfer_encoding/1True if Encoding is supported.Source
encoding_filter/3Install a filter to deal with chunked encoded messages.Source
cgi_discard/1Discard content produced sofar.Source
cgi_open/4Process CGI output.Source
cgi_property/2Inquire the status of the CGI stream.Source
cgi_set/2Change one of the properies.Source
cgi_statistics/1Return statistics on the CGI stream subsystem.Source
http_chunked_add_trailer/3Add a trailer key/value to DataStream.Source
http_chunked_flush/2Emits the next chunk flush_output/1 on DataStream, but in addition adds extension parameters to the chunk.Source
http_chunked_open/3Create a stream to realise HTTP chunked encoding or decoding.Source
http_is_chunked/1True if DataStream is created using http_chunked_open/3.Source
is_cgi_stream/1True if Stream is a CGI stream created using cgi_open/4.Source
multipart_open/3DataStream is a stream that signals end_of_file if the multipart boundary is encountered.Source
multipart_open_next/1Prepare DataStream to read the next part from the multipart input data.Source
stream_range_open/3DataStream is a stream whose size is defined by the option size(ContentLength).Source
http_unix_daemon.pl  -- Run SWI-Prolog HTTP server as a Unix system daemonShow source
sni_options/2Hook to provide Server Name Indication (SNI) for TLS servers.
http_certificate_hook/3Hook called before starting the server if the --https option is used.Source
http_daemon/0Start the HTTP server as a daemon process.Source
http_daemon/1Start the HTTP server as a daemon process.Source
http_opt_help/2Allow reusing http option processing.Source
http_opt_meta/2Allow reusing http option processing.Source
http_opt_type/3Allow reusing http option processing.Source
http_server_hook/1Hook that is called to start the HTTP server.Source
http_wrapper.pl  -- Server processing of an HTTP requestShow source
cgi_hook/2Hook called from the CGI processing stream.Source
http_current_request/1Returns the HTTP request currently being processed.Source
http_peer/2True when PeerIP is the IP address of the connection peer.Source
http_relative_path/2Convert an absolute path (without host, fragment or search) into a path relative to the current page.Source
http_send_header/1This API provides an alternative for writing the header field as a CGI header.Source
http_spawned/1Internal use only.Source
http_wrap_spawned/3Internal use only.Source
http_wrapper/5Simple wrapper to read and decode an HTTP header from `In', call :Goal while watching for exceptions and send the result to the stream `Out'.Source
hub.pl  -- Manage a hub for websocketsShow source
current_hub/2True when there exists a hub Hub with Name.Source
hub_add/3Add a WebSocket to the hub.Source
hub_broadcast/2Send Message to all websockets associated with Hub for which call(Condition, Id) succeeds.Source
hub_broadcast/3Send Message to all websockets associated with Hub for which call(Condition, Id) succeeds.Source
hub_create/3Create a new hub.Source
hub_member/2True when Id is a member of the hub HubName.Source
hub_send/2Send message to the indicated ClientId.Source
js_grammar.pl  -- JavaScript grammarShow source
js_token/3Matches and classifies the next JavaScript token.Source
js_write.pl  -- Utilities for including JavaScriptShow source
javascript/4Quasi quotation parser for JavaScript that allows for embedding Prolog variables to substitude identifiers in the JavaScript snippet.Source
js_arg/3Same as js_expression//1, but fails if Expression is invalid, where js_expression//1 raises an error.Source
js_arg_list/3Write javascript (function) arguments.Source
js_call/3Emit a call to a Javascript function.Source
js_expression/3Emit a single JSON argument.Source
js_new/4Emit a call to a Javascript object declaration.Source
js_script/3Generate a JavaScript script element with the given content.Source
json.pl  -- Reading and writing JSON serializationShow source
atom_json_dict/3Convert between textual representation and a JSON term represented as a dict.Source
atom_json_term/3Convert between textual representation and a JSON term.Source
is_json_term/1True if Term is a json term.Source
is_json_term/2True if Term is a json term.Source
json_dict_pairs/2This hook may be used to order the keys of an object.Source
json_read/2Read next JSON value from Stream into a Prolog term.Source
json_read/3Read next JSON value from Stream into a Prolog term.Source
json_read_dict/2Read a JSON object, returning objects as a dicts.Source
json_read_dict/3Read a JSON object, returning objects as a dicts.Source
json_write/2Write a JSON term to Stream.Source
json_write/3Write a JSON term to Stream.Source
json_write_dict/2Write a JSON term, represented using dicts.Source
json_write_dict/3Write a JSON term, represented using dicts.Source
json_write_hook/4Hook that can be used to emit a JSON representation for Term to Stream.Source
json_convert.pl  -- Convert between JSON terms and Prolog application termsShow source
current_json_object/3Multifile predicate computed from the json_object/1 declarations.Source
json_object/1Declare a JSON object.Source
json_to_prolog/2Translate a JSON term into an application term.Source
prolog_bool_to_json/2JSON is the JSON boolean for Prolog.Source
prolog_to_json/2Translate a Prolog application Term into a JSON object term.Source
mimepack.pl  -- Create a MIME messageShow source
mime_pack/3Pack a number of inputs into a MIME package using a specified or generated boundary.Source
mimetype.pl  -- Determine mime-type for a fileShow source
charset/3Hook that determines the Charset for File that has media type MediaType.
mime_extension/2Hook that is called by file_mime_type/2 before the default table is examined.
file_content_type/2True if File should be served using ContentType: ContentType.Source
file_content_type/3True if File should be served using ContentType: ContentType.Source
file_mime_type/2True when MimeType is the mime-type to be used for sending FileName.Source
term_html.pl  -- Represent Prolog terms as HTMLShow source
term/4Render a Prolog term as a structured HTML tree.Source
thread_httpd.pl  -- Threaded HTTP serverShow source
schedule_workers/1Hook called if a new connection or a keep-alive connection cannot be scheduled immediately to a worker.Source
http_add_worker/2Add a new worker to the HTTP server for port Port.Source
http_close_connection/1Close connection associated to Request.Source
http_current_server/2True if Goal is the goal of a server at Port.Source
http_current_worker/2True if ThreadID is the identifier of a Prolog thread serving Port.Source
http_enough_workers/3Check that we have enough workers in our queue.Source
http_requeue/1Re-queue a connection to the worker pool.Source
http_server/2Create a server at Port that calls Goal for each parsed request.Source
http_server_property/2True if Property is a property of the HTTP server running at Port.Source
http_spawn/2Continue this connection on a new thread.Source
http_stop_server/2Stop the indicated HTTP server gracefully.Source
http_workers/2Query or set the number of workers for the server at this port.Source
message_level/2Determine the message stream used for exceptions that may occur during server_loop/5.Source
websocket.pl  -- WebSocket supportShow source
http_open_websocket/3Establish a client websocket connection.Source
http_upgrade_to_websocket/3Create a websocket connection running call(Goal, WebSocket), where WebSocket is a socket-pair.Source
ws_close/3Close a WebSocket connection by sending a close message if this was not already sent and wait for the close reply.Source
ws_mask/1Produce a good random number of the mask of a client message.Source
ws_open/3Turn a raw TCP/IP (or any other binary stream) into a websocket stream.Source
ws_property/2True if Property is a property WebSocket.Source
ws_receive/2Receive the next message from WebSocket.Source
ws_receive/3Receive the next message from WebSocket.Source
ws_send/2Send a message over a websocket.Source
yadis.pl  -- Yadis discoveryShow source
ssl_verify/5Accept all certificates.Source
xrds_dom/2True when XRDS_DOM is a parsed XML document for the given resource.Source
xrds_location/2Discover the location of the XRDS document from the given Id.Source