Barracuda HTTP protocol stack

For advanced use of Barracuda

Please see the HttpResMgr example and the HttpResMgr.c source file for an example of using HttpAsynchReq, MultipartUpload, and HttpAsynchResp.

The Barracuda Embedded Web-Server can be used as a general purpose HTTP protocol stack. A resource such as an HttpDir or HttpPage can be constructed to receive and transmit data via the HTTP protocol.

Barracuda comes with 6 classes for receiving and transmitting data by using the HTTP protocol.

HttpAsynchReq

An instance of the HttpAsynchReq class is created in a resource such as an HttpDir or HttpPage when the Web-Server delegates a client request to the resource.

You provide a buffer and an OnData callback function to an instance of a HttpAsynchReq class. The callback function is called N times where N is data size/buffer size. If buffer size >= data size, i.e. greater or equal to the data being received, then the OnData function is called once.

An instance of the HttpAsynchReq class is typically used when receiving large objects such as a file.

An instance of the HttpAsynchReq class cannot send a response message, thus a HttpAsynchReq object is typically used together with a HttpAsynchResp object.

A resource must always respond to a request and a HttpAsynchReq object must therefore use a HttpAsynchResp object when responding to a request. It is therefore suggested that you use a HttpAsynchReqResp object, which implements HttpAsynchReq and HttpAsynchResp, instead of first creating a HttpAsynchReq object and then later create a HttpAsynchResp object.

HttpAsynchResp

An instance of the HttpAsynchResp class is used as a lightweight method for sending response data to a client, thus it can be used as a replacement for the HttpCmdThreadPool.

An instance of the HttpAsynchResp class is also used in combination with an instance of the HttpAsynchReq class. An HttpAsynchReq object cannot send a response object, thus an HttpAsynchResp is needed for the response message.

The HttpAsynchResp class is designed such that it moves the active HttpConnection object (the socket connection) from either a HttpRequest object or from a HttpAsynchReq object, thus an instance of the HttpAsynchResp class is normally created in a resource service function such as a HttpPage or a HttpDir or in the HttpAsynchReq OnData event method.

The HttpAsynchResp can be used directly from within the HttpAsynchReq OnData event method, but you should not do any lengthy operations in the OnData event method as this method runs in the context of the thread running the SoDisp object.

HttpAsynchResp can assist you in streaming audio or video to a client.

The HttpAsynchResp is designed such that an active instance can be moved to a thread outside of the Barracuda environment. The HttpAsynchResp class has a number of methods you can use from within the thread when sending a response message, thus an external thread can therefore use the HttpAsynchResp object to respond to lengthy calculations or when streaming content to a client.

The HttpAsynchResp class is designed such that it initially sends a HTTP response header before the content body is sent. It is however possible to send response data to a client without sending a HTTP response header by directly using the HttpConnection object. It is unlikely that you would send a response message without using a HTTP header, but it is possible. These features are currently not documented in the reference manual. You must study the information found in the header files.

HttpConnection_moveConDetach and move active web-server connection object.
HttpConnection_sendChunkDataSend HTTP 1.1 persistent connection data.
HttpConnection_sendDataSend data with Content-Length or send HTTP 1.0 data.
HttpServer_addCon2ConnectedListMove an active and valid HTTP 1.1 persistent connection back to the web-server such that the web-server can recycle the connection object.
HttpConnection_destructorTerminate and close an active connection object.