-
Notifications
You must be signed in to change notification settings - Fork 1k
Environment variables
WebSocket server programs often need additional data about the connection, beyond just the raw stream of messages - such as remote host, which web-page they're on, URL query parameters, cookies, etc.
To expose these to programs, they are set as environment variables for each request.
The variables conform to the Common Gateway Interface (CGI) 1.1 Specification.
You can read these environment variables directly, or use a programming language specific CGI library that can make them easier to work with (e.g. Perl, Python, Ruby).
Empty. Not supported in WebSockets.
Empty. Not supported in WebSockets.
Empty. Not supported in WebSockets.
The string websocketd-CGI/0.1
.
Future enhancements may change the version.
Example:
GATEWAY_INTERFACE=websocketd-CGI/0.1
HTTP Cookies, if present.
Example:
HTTP_COOKIE=session=1234; prefs=foo`
The base URL of the origin site that initiated the WebSocket.
Example:
HTTP_ORIGIN=https://github.com/
TODO
TODO
Everything after the ?
in the URL.
Example: If the requested WebSocket URL is ws://localhost:1234/somedir/myscript.py?name=me&msg=hello%20world
, then:
QUERY_STRING=name=me&msg=hello%20world
IP address of remote WebSocket client.
Example:
REMOTE_ADDR=123.123.123.123
Reverse DNS lookup of remote WebSocket client.
Example:
REMOTE_HOST=somemachine.someisp.com
If the reverse DNS lookup fails, or if --reverselookup=false
is specified on the websocketd
command line, this value will fallback to the same value of REMOTE_ADDR
.
Empty. Not supported in WebSockets.
Source port of remote WebSocket client.
Example:
REMOTE_PORT=52696
(Non standard)
Empty. Not supported in WebSockets.
The HTTP request method. For WebSockets, this is always GET
.
Example:
REQUEST_METHOD=GET
The original request URI, as sent by the WebSocket client. This does not include scheme, host or port.
Example: If the requested WebSocket URL is ws://localhost:1234/somedir/myscript.py?name=me&msg=hello%20world
, then:
REQUEST_URI=/somedir/myscript.py?name=me&msg=hello%20world
(Non standard)
TODO
The hostname of the server, as specified in the URL.
Example:
SERVER_NAME=www.example.com
The listening port of the server.
Example:
SERVER_PORT=8080
The HTTP protocol, as specified by the client.
Example:
SERVER_PROTOCOL=HTTP/1.1
The string websocketd/x.x.x.x
, where x.x.x.x
is the version of the websocketd
program.
Example:
SERVER_SOFTWARE=websocketd/1.0.0.0
A unique string associated with each WebSocket connection. It can be used for logging and debugging purposes.
The ID should be treated as an opaque payload. It must be treated as a string, not a number. The implementation may change over time.
The ID is only guaranteed to unique within a single websocketd
process.
Example:
UNIQUE_ID=45462465645449101442
(Non standard)
Per the CGI specification, all HTTP headers will be set as environment variables. The header name will be transformed:
- String converted to upper-case
- Dashes
-
converted to underscores_
- Prefixed with
HTTP_
Example: If the HTTP header Sec-WebSocket-Version: 13
is present, then:
HTTP_SEC_WEBSOCKET_VERSION=13
The websocketd user guide is a publicly editable wiki. Please contribute!
Getting Started
Reference
Language specific
Advanced: Internals
Spanish Websocket Wiki
Primeros pasos
Referencia
Lenguajes
Avanzado