Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 3.17 KB

httpserver.md

File metadata and controls

65 lines (52 loc) · 3.17 KB

httpserver module

This module allows Yate server to process HTTP and HTTPS requests from web browsers and other HTTP-enabled software. Incoming request is decoded and transformed into a serie of Yate's messages. Other modules (like webserver or websocket) can then process this messages and procuce some response data.

Configuration

Module has it's own configuration file httpserver.conf. See comments inside for more info.

Operation

Upon receiving of HTTP request, module issues several messages, and depending on results produces response.

First of all, after parsin of request headers, http.route message is dispatched with the following parameters:

Parameter Description
server name of listener (section of httpserver.conf) serving request
address remote address of client connection in form of ip:port
local local address of client connection
keepalive boolean value, indicating that connection will not be closed after processiong of this request
reqbody boolean value, indicating that request body is expected in this request
version HTTP version
method HTTP request method
uri request uri string
hdr_Xxxxx incoming request headers

If this http.route message is handled, it's return value is added to subsequent messages as handler parameter. All other paramters are passed to all subsequent messages unchanged.

If connection upgrade is offered, http.upgrade message is dispatched. If it is handled, "101 Switching protocols" response is produced and then run() method of Runnable object, extracted from response's userData, is called. When it returns, connection is closed. Handling module should store reference to Socket object, taken from http.upgrade message and replace userData with it's Runnable reference. Example can be found in websocket module.

Then http.preserve message is dispatched, allowing handlers to process request body. See example in webserver module. If that message is not handled, temporal request body buffer is created. Then request body is read from network.

Finally, http.serve message is dispatched. If temp. request buffer was used, it's content is added as content paramter. It that message is not handled, "404 Not found" error response is produced and client connection is closed.

Handled http.serve message is used to construct HTTP response. Status code is taken from status parameter and response headers are build trom ohdr* parameters.

If http.serve message's retValue is not empty, it is used as HTTP response body. Otherwise, userData of response is queried for Stream and RefObject objects, that will be used to produce response body.