libwebsockets
Lightweight C library for HTML5 websockets
HTTP File transfer

Functions

LWS_VISIBLE LWS_EXTERN const char * lws_get_mimetype (const char *file, const struct lws_http_mount *m)
 
LWS_VISIBLE LWS_EXTERN int lws_serve_http_file (struct lws *wsi, const char *file, const char *content_type, const char *other_headers, int other_headers_len)
 
LWS_VISIBLE LWS_EXTERN int lws_serve_http_file_fragment (struct lws *wsi)
 

Detailed Description

APIs for sending local files in response to HTTP requests

Function Documentation

◆ lws_get_mimetype()

LWS_VISIBLE LWS_EXTERN const char* lws_get_mimetype ( const char *  file,
const struct lws_http_mount m 
)

#include <include/libwebsockets/lws-http.h>

lws_get_mimetype() - Determine mimetype to use from filename

Parameters
filefilename
mNULL, or mount context

This uses a canned list of known filetypes first, if no match and m is non-NULL, then tries a list of per-mount file suffix to mimtype mappings.

Returns either NULL or a pointer to the mimetype matching the file.

◆ lws_serve_http_file()

LWS_VISIBLE LWS_EXTERN int lws_serve_http_file ( struct lws *  wsi,
const char *  file,
const char *  content_type,
const char *  other_headers,
int  other_headers_len 
)

#include <include/libwebsockets/lws-http.h>

lws_serve_http_file() - Send a file back to the client using http

Parameters
wsiWebsocket instance (available from user callback)
fileThe file to issue over http
content_typeThe http content type, eg, text/html
other_headersNULL or pointer to header string
other_headers_lenlength of the other headers if non-NULL
 This function is intended to be called from the callback in response
 to http requests from the client.  It allows the callback to issue
 local files down the http link in a single step.

 Returning <0 indicates error and the wsi should be closed.  Returning
 >0 indicates the file was completely sent and
 lws_http_transaction_completed() called on the wsi (and close if != 0)
 ==0 indicates the file transfer is started and needs more service later,
 the wsi should be left alone.