Namespace: dmWebServer
Language: C++
Type: Defold C++
File: webserver.h
Source: engine/dlib/src/dmsdk/dlib/webserver.h
Include: dmsdk/dlib/webserver.h
Simple high-level single-threaded Web server based on dmHttpServer The web-server has a handler concept similar to servlets in Java
Type: FUNCTION Requests use the handler with the longest matching prefix, regardless of registration order. A handler registered at “/” serves as a fallback. Equivalent to calling the four-argument overload with openapi_json set to 0.
Parameters
server (HServer) - Server handleprefix (const char*) - Location prefix for which locations this handler should handlehandler_params (HandlerParams) - Handler parametersReturns
return (Result) - RESULT_OK on successType: FUNCTION Requests use the handler with the longest matching prefix, regardless of registration order. A handler registered at “/” serves as a fallback. Pass 0 to register without documenting the handler. Otherwise, the OpenAPI JSON is a non-empty Paths Object describing the paths and methods served by this handler. Each path must start with the handler’s prefix and must not already be documented by another handler. Schemas should be inline or use references to paths in the resulting document. The server retains the JSON pointer without copying it. Keep the string unchanged and valid until the handler is removed or the server is deleted; a static const char array is recommended.
Parameters
server (HServer) - Server handleprefix (const char*) - Location prefix for which locations this handler should handlehandler_params (HandlerParams) - Handler parametersopenapi_json (const char*) - OpenAPI 3.0.3 Paths Object encoded as a JSON string, or 0 to omit metadataReturns
return (Result) - RESULT_OK on success, RESULT_ERROR_INVAL for invalid or conflicting metadataType: FUNCTION Get http header value for key, ignoring ASCII case in the header name
Parameters
request (Request*) - Requestname (const char*) - Header keyReturns
return (const char*) - Header value. NULL if the key doesn’t existsType: TYPEDEF Web request handler callback
Parameters
user_data (void*) - User datarequest (Request*) - RequestReturns
return (void)Type: STRUCT handler parameters
Members
m_UserData (void*) - The user datam_Handler (Handler) - The callbackType: TYPEDEF web server handle
Type: FUNCTION Receive data
Parameters
request (Request*) - Requestbuffer (void*) - Data buffer to receive tobuffer_size (uint32_t) - Buffer sizereceived_bytes (uint32_t*) - Number of bytes receivedReturns
return (Result) - RESULT_OK on successType: FUNCTION Remove handle
Parameters
server (HServer) - Server handleprefix (const char*) - Prefix for handle to removeReturns
return (Result) - RESULT_OK on successType: STRUCT web server request
Members
m_Method (const char*) - Request methodm_Method (const char*) - Request resourcem_Method (const char*) - Content-Length headerm_Method (const char*) - Internal dataType: ENUM result codes
Members
RESULT_OKRESULT_SOCKET_ERRORRESULT_INVALID_REQUESTRESULT_ERROR_INVALRESULT_HANDLER_ALREADY_REGISTREDRESULT_HANDLER_NOT_REGISTREDRESULT_TRY_AGAINRESULT_INTERNAL_ERRORRESULT_UNKNOWNType: FUNCTION Copies data into an owned response sent asynchronously after the handler returns. Socket errors are handled by the server; RESULT_OK means the data was queued.
Parameters
request (Request) - Request handledata (void*) - Data to senddata_length (uint32_t) - Data-lenght to sendReturns
return (Result) - RESULT_OK on successType: FUNCTION Sends a header attribute
Parameters
request (Request*) - Requestkey (const char*) - the header namevalue (const char*) - the header valueReturns
return (Result) - RESULT_OK on successType: FUNCTION Set response status code.
Notes
Parameters
request (Request*) - Requeststatus_code (int) - Status code to setReturns
return (Result) - RESULT_OK on successType: CONSTANT Name used when registering the web server with the engine context registry.