3.2 library(http/http_dispatch): Dispatch requests in the HTTP server
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog HTTP support
        • The HTTP server libraries
          • library(http/http_dispatch): Dispatch requests in the HTTP server
            • http_handler/3
            • http_delete_handler/1
            • http_dispatch/1
            • http_request_expansion/2
            • http_current_handler/2
            • http_current_handler/3
            • http_location_by_id/2
            • http_link_to_id/3
            • http_reload_with_parameters/3
            • http_reply_file/3
            • http_safe_file/2
            • http_redirect/3
            • http_404/2
            • http_switch_protocol/2
Availability::- use_module(library(http/http_dispatch)).
Sourcehttp_switch_protocol(:Goal, +Options)
Send an "HTTP 101 Switching Protocols" reply. After sending the reply, the HTTP library calls call(Goal, InStream, OutStream), where InStream and OutStream are the raw streams to the HTTP client. This allows the communication to continue using an an alternative protocol.

If Goal fails or throws an exception, the streams are closed by the server. Otherwise Goal is responsible for closing the streams. Note that Goal runs in the HTTP handler thread. Typically, the handler should be registered using the spawn option if http_handler/3 or Goal must call thread_create/3 to allow the HTTP worker to return to the worker pool.

The streams use binary (octet) encoding and have their I/O timeout set to the server timeout (default 60 seconds). The predicate set_stream/2 can be used to change the encoding, change or cancel the timeout.

This predicate interacts with the server library by throwing an exception.

The following options are supported:

header(+Headers)
Backward compatible. Use headers(+Headers).
headers(+Headers)
Additional headers send with the reply. Each header takes the form Name(Value).