|
NAMEhttp_server —
threaded server for HTTP and HTTPS
LIBRARYPDEL Library (libpdel, -lpdel)SYNOPSIS#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <openssl/ssl.h>
#include <pdel/http/http_defs.h>
#include
<pdel/http/http_server.h>
struct http_server *
void
int
void
void
DESCRIPTIONThese functions implement a threaded HTTP server supporting SSL and user-definable "servlets".
struct http_server_ssl { const char *cert_path; /* path to certificate file */ const char *pkey_path; /* path to private key file */ const char *pkey_password; /* private key password, if needed */ }; ctx is a pevent(3) event context with which the server registers to accept incoming connections. New connections are allocated individual threads in which to execute. The server enforces a hard limit of at most 1024 simultaneous connections, refusing to accept any new connections until one or more existing connections terminate. The server_name string is used for the "Server:" HTTP header and typically includes the name and version number of the software, e.g., “MyServer/1.0”. The logger, if not
typedef void http_logger_t(int sev, const char *fmt, ...); Here sev is a syslog(3) severity level.
Invoking ServletsFor anything interesting to happen, one or more servlets must be registered (see http_servlet(3)). Servlets are registered by invokinghttp_server_register_servlet ().
The vhost parameter may be used for virtual
hosting. If vhost is not The servlet will be invoked for queries matching urlpat, which is an extended regular expression (see re_format(7)). The request URI is URL-decoded before matching begins and only the relative part is matched. For example, a servlet registered to match the regular expression "^/foo bar$" would match "http://server/foo%20bar" and "http://server/foo%20bar?field=value" but not "http://server/foo%20bar/". If two or more servlets match the same request, the servlet that was registered with the lowest order is chosen. If two servlets match and have the same order, the last one registered is chosen. The order in which servlets are registered is important, especially with authorization servlets, because incoming requests may arrive at any time. I.e., authorization servlets should be registered before the servlet(s) that they protect.
Proxy supportPrimitive proxy support is provided byhttp_server_set_proxy_handler (). The
handler is a pointer to a function of this type:
typedef void http_proxy_t(void *arg, struct http_request *req, struct http_response *resp); The handler is invoked with the same
arg whenever an HTTP proxy request is received. To
disable proxy support, invoke
RETURN VALUESUpon error,http_server_start () and
http_server_register_servlet () return
NULL or -1, respectively, and set
errno to an appropriate value.
SEE ALSOhttp_client(3), http_mime(3), http_request(3), http_response(3), http_servlet(3), http_xml(3), libpdel(3), pevent(3), syslog(3), re_format(7)R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee, Hypertext Transfer Protocol -- HTTP/1.1, RFC 2616. HISTORYThe PDEL library was developed at Packet Design, LLC.http://www.packetdesign.com/
AUTHORSArchie Cobbs ⟨archie@freebsd.org⟩BUGSCreating a new thread for each request is somewhat expensive. The server should keep a pool of idle threads for faster dispatch of incoming connections.The maximum number of connections should be configurable. The server is probably not fully compliant to the HTTP specification.
Visit the GSP FreeBSD Man Page Interface. |