The uwsgi Protocol

The uwsgi (lowercase!) protocol is the native protocol used by the uWSGI server.

It is a binary protocol that can carry any type of data. The first 4 bytes of a uwsgi packet describe the type of the data contained by the packet.

Every uwsgi request generates a response in the uwsgi format.

Even the web server handlers obey this rule, as an HTTP response is a valid uwsgi packet (look at the modifier1 = 72).

The protocol works mainly via TCP but the master process can bind to a UDP Unicast/Multicast for The embedded SNMP server or cluster management/messaging requests.

SCTP support is being worked on.

uwsgi packet header

  1. struct uwsgi_packet_header {
  2. uint8_t modifier1;
  3. uint16_t datasize;
  4. uint8_t modifier2;
  5. };

Unless otherwise specified the datasize value contains the size (16-bit little endian) of the packet body.

Packet descriptions

modifier1datasizemodifier2packet type
0size of WSGI block vars (HTTP request body excluded)0Standard WSGI request followed by the HTTP request body
1reserved for UNBIT
2reserved for UNBIT
3reserved for UNBIT
5size of PSGI block vars (HTTP request body excluded)0Standard PSGI request followed by the HTTP request body
6size of LUA WSAPI block vars (HTTP request body excluded)0Standard LUA/WSAPI request followed by the HTTP request body
7size of RACK block vars (HTTP request body excluded)0Standard RACK request followed by the HTTP request body
8size of JWSGI/Ring block vars (HTTP request body excluded)0Standard JVM request for The JWSGI interface and The Clojure/Ring JVM request handler followed by the HTTP request body
9size of CGI block vars (HTTP request body excluded)0Standard Running CGI scripts on uWSGI request followed by the HTTP request body
10size of block vars0- 255Management interface request: setup flag specified by modifier2. For a list of management flag look at ManagementFlag
14size of CGI block vars (HTTP request body excluded)0Standard Running PHP scripts in uWSGI request followed by the HTTP request body
15size of Mono ASP.NET block vars (HTTP request body excluded)0Standard The Mono ASP.NET plugin request followed by the HTTP request body
17size of Spooler block vars0- 255The uWSGI Spooler request, the block vars is converted to a dictionary/hash/table and passed to the spooler callable. The second modifier is currently ignored.
18size of CGI block vars0-255direct call to c-like symbols
22size of code string0- 255Raw Code evaluation. The interpreter is chosen by the modifier2. 0 is Python, 5 is Perl.It does not return a valid uwsgi response, but a raw string (that may be an HTTP response)
23size of CGI vars0- 255invoke the The XSLT plugin
24size of CGI vars0- 255invoke the uWSGI V8 support
25size of CGI vars0- 255invoke the The GridFS plugin
26size of CGI vars0- 255invoke the The GlusterFS plugin
2700- 255call the FastFuncs specified by the modifier2 field
2800- 255invoke the The RADOS plugin
30size of WSGI block vars (HTTP request body excluded)0 (if defined the size of the block vars is 24bit le, for now none of the webserver handlers support this feature)Standard WSGI request followed by the HTTP request body. The PATH_INFO is automatically modified, removing the SCRIPT_NAME from it
31size of block vars0- 255Generic message passing (reserved)
32size of char array0- 255array of char passing (reserved)
33size of marshal object0- 255marshalled/serialzed object passing (reserved)
48snmp specificsnmp specificidentify a SNMP request/response (mainly via UDP)
72chr(TT)chr(P)Corresponds to the ‘HTTP’ string and signals that this is a raw HTTP response.
73announce message size (for sanity check)announce type (0 = hostname)announce message
74multicast message size (for sanity check)0array of chars; a custom multicast message managed by uwsgi.multicast_manager
95cluster membership dict sizeactionadd/remove/enable/disable node from a cluster. Action may be 0 = add, 1 = remove, 2 = enable, 3 = disable. Add action requires a dict of at least 3 keys: hostname, address and workers
96log message size0Remote logging (clustering/multicast/unicast)
9700, 1brutal reload request (0 request - 1 confirmation)
9800, 1graceful reload request (0 request - 1 confirmation)
99size of options dictionary (if response)0, 1request configuration data from a uwsgi node (even via multicast)
10000, 1PING- PONG if modifier2 is 0 it is a PING request otherwise it is a PONG (a response). Useful for cluster health- check
101size of packet0ECHO service
109size of clean payload0 to 255legion msg (UDP, the body is encrypted)
110size of payload0 to 255uwsgi_signal framework (payload is optional), modifier2 is the signal num
111size of packet0, 1, 2, 3Cache operations. 0: read, 1: write, 2: delete, 3: dict_based
123size of packet-special modifier for signaling corerouters about special conditions
173size of packet0, 1RPC. The packet is an uwsgi array where the first item is the name of the function and the following are the args (if modifier2 is 1 the RPC will be ‘raw’ and all of the response will be returned to the app, uwsgi header included, if available.
20000Close mark for persistent connections
224size of packet0Subscription packet. see SubscriptionServer
25500- 255Generic response. Request dependent. For example a spooler response set 0 for a failed spool or 1 for a successful one

The uwsgi vars

The uwsgi block vars represent a dictionary/hash. Every key-value is encoded in this way:

  1. struct uwsgi_var {
  2. uint16_t key_size;
  3. uint8_t key[key_size];
  4. uint16_t val_size;
  5. uint8_t val[val_size];
  6. }