HTTP server (HyperText Transfer Protocol) More...
#include "core/net.h"
#include "http/http_server.h"
#include "http/http_server_auth.h"
#include "http/http_server_misc.h"
#include "http/mime.h"
#include "http/ssi.h"
#include "debug.h"
Go to the source code of this file.
Macros | |
#define | TRACE_LEVEL HTTP_TRACE_LEVEL |
Functions | |
void | httpServerGetDefaultSettings (HttpServerSettings *settings) |
Initialize settings with default values. More... | |
error_t | httpServerInit (HttpServerContext *context, const HttpServerSettings *settings) |
HTTP server initialization. More... | |
error_t | httpServerStart (HttpServerContext *context) |
Start HTTP server. More... | |
void | httpListenerTask (void *param) |
HTTP server listener task. More... | |
void | httpConnectionTask (void *param) |
Task that services requests from an active connection. More... | |
error_t | httpWriteHeader (HttpConnection *connection) |
Send HTTP response header. More... | |
error_t | httpReadStream (HttpConnection *connection, void *data, size_t size, size_t *received, uint_t flags) |
Read data from client request. More... | |
error_t | httpWriteStream (HttpConnection *connection, const void *data, size_t length) |
Write data to the client. More... | |
error_t | httpCloseStream (HttpConnection *connection) |
Close output stream. More... | |
error_t | httpSendResponse (HttpConnection *connection, const char_t *uri) |
Send HTTP response. More... | |
error_t | httpSendErrorResponse (HttpConnection *connection, uint_t statusCode, const char_t *message) |
Send error response to the client. More... | |
error_t | httpSendRedirectResponse (HttpConnection *connection, uint_t statusCode, const char_t *uri) |
Send redirect response to the client. More... | |
bool_t | httpCheckWebSocketHandshake (HttpConnection *connection) |
Check whether the client's handshake is valid. More... | |
WebSocket * | httpUpgradeToWebSocket (HttpConnection *connection) |
Upgrade an existing HTTP connection to a WebSocket. More... | |
Detailed Description
HTTP server (HyperText Transfer Protocol)
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Description
Using the HyperText Transfer Protocol, the HTTP server delivers web pages to browsers as well as other data files to web-based applications. Refers to the following RFCs for complete details:
- RFC 1945: Hypertext Transfer Protocol - HTTP/1.0
- RFC 2616: Hypertext Transfer Protocol - HTTP/1.1
- RFC 2617: HTTP Authentication: Basic and Digest Access Authentication
- RFC 2818: HTTP Over TLS
- Version
- 2.4.4
Definition in file http_server.c.
Macro Definition Documentation
◆ TRACE_LEVEL
#define TRACE_LEVEL HTTP_TRACE_LEVEL |
Definition at line 42 of file http_server.c.
Function Documentation
◆ httpCheckWebSocketHandshake()
bool_t httpCheckWebSocketHandshake | ( | HttpConnection * | connection | ) |
Check whether the client's handshake is valid.
- Parameters
-
[in] connection Structure representing an HTTP connection
- Returns
- TRUE if the WebSocket handshake is valid, else FALSE
Definition at line 1246 of file http_server.c.
◆ httpCloseStream()
error_t httpCloseStream | ( | HttpConnection * | connection | ) |
Close output stream.
- Parameters
-
[in] connection Structure representing an HTTP connection
- Returns
- Error code
Definition at line 882 of file http_server.c.
◆ httpConnectionTask()
void httpConnectionTask | ( | void * | param | ) |
Task that services requests from an active connection.
- Parameters
-
[in] param Structure representing an HTTP connection with a client
Definition at line 362 of file http_server.c.
◆ httpListenerTask()
void httpListenerTask | ( | void * | param | ) |
HTTP server listener task.
- Parameters
-
[in] param Pointer to the HTTP server context
Definition at line 281 of file http_server.c.
◆ httpReadStream()
error_t httpReadStream | ( | HttpConnection * | connection, |
void * | data, | ||
size_t | size, | ||
size_t * | received, | ||
uint_t | flags | ||
) |
Read data from client request.
- Parameters
-
[in] connection Structure representing an HTTP connection [out] data Buffer where to store the incoming data [in] size Maximum number of bytes that can be received [out] received Number of bytes that have been received [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
Definition at line 711 of file http_server.c.
◆ httpSendErrorResponse()
error_t httpSendErrorResponse | ( | HttpConnection * | connection, |
uint_t | statusCode, | ||
const char_t * | message | ||
) |
Send error response to the client.
- Parameters
-
[in] connection Structure representing an HTTP connection [in] statusCode HTTP status code [in] message User message
- Returns
- Error code
Definition at line 1115 of file http_server.c.
◆ httpSendRedirectResponse()
error_t httpSendRedirectResponse | ( | HttpConnection * | connection, |
uint_t | statusCode, | ||
const char_t * | uri | ||
) |
Send redirect response to the client.
- Parameters
-
[in] connection Structure representing an HTTP connection [in] statusCode HTTP status code (301 for permanent redirects) [in] uri NULL-terminated string containing the redirect URI
- Returns
- Error code
Definition at line 1181 of file http_server.c.
◆ httpSendResponse()
error_t httpSendResponse | ( | HttpConnection * | connection, |
const char_t * | uri | ||
) |
Send HTTP response.
- Parameters
-
[in] connection Structure representing an HTTP connection [in] uri NULL-terminated string containing the file to be sent in response
- Returns
- Error code
Definition at line 910 of file http_server.c.
◆ httpServerGetDefaultSettings()
void httpServerGetDefaultSettings | ( | HttpServerSettings * | settings | ) |
Initialize settings with default values.
- Parameters
-
[out] settings Structure that contains HTTP server settings
Definition at line 62 of file http_server.c.
◆ httpServerInit()
error_t httpServerInit | ( | HttpServerContext * | context, |
const HttpServerSettings * | settings | ||
) |
HTTP server initialization.
- Parameters
-
[in] context Pointer to the HTTP server context [in] settings HTTP server specific settings
- Returns
- Error code
Definition at line 127 of file http_server.c.
◆ httpServerStart()
error_t httpServerStart | ( | HttpServerContext * | context | ) |
Start HTTP server.
- Parameters
-
[in] context Pointer to the HTTP server context
- Returns
- Error code
Definition at line 236 of file http_server.c.
◆ httpUpgradeToWebSocket()
WebSocket* httpUpgradeToWebSocket | ( | HttpConnection * | connection | ) |
Upgrade an existing HTTP connection to a WebSocket.
- Parameters
-
[in] connection Structure representing an HTTP connection
- Returns
- Handle referencing the new WebSocket
Definition at line 1295 of file http_server.c.
◆ httpWriteHeader()
error_t httpWriteHeader | ( | HttpConnection * | connection | ) |
Send HTTP response header.
- Parameters
-
[in] connection Structure representing an HTTP connection
- Returns
- Error code
Definition at line 672 of file http_server.c.
◆ httpWriteStream()
error_t httpWriteStream | ( | HttpConnection * | connection, |
const void * | data, | ||
size_t | length | ||
) |
Write data to the client.
- Parameters
-
[in] connection Structure representing an HTTP connection [in] data Buffer containing the data to be transmitted [in] length Number of bytes to be transmitted
- Returns
- Error code
Definition at line 817 of file http_server.c.