http_server.c File Reference

HTTP server (HyperText Transfer Protocol) More...

#include <stdlib.h>
#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...
 
WebSockethttpUpgradeToWebSocket (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
Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

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]connectionStructure representing an HTTP connection
Returns
TRUE if the WebSocket handshake is valid, else FALSE

Definition at line 1247 of file http_server.c.

◆ httpCloseStream()

error_t httpCloseStream ( HttpConnection connection)

Close output stream.

Parameters
[in]connectionStructure representing an HTTP connection
Returns
Error code

Definition at line 883 of file http_server.c.

◆ httpConnectionTask()

void httpConnectionTask ( void *  param)

Task that services requests from an active connection.

Parameters
[in]paramStructure representing an HTTP connection with a client

Definition at line 363 of file http_server.c.

◆ httpListenerTask()

void httpListenerTask ( void *  param)

HTTP server listener task.

Parameters
[in]paramPointer to the HTTP server context

Definition at line 282 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]connectionStructure representing an HTTP connection
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 712 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]connectionStructure representing an HTTP connection
[in]statusCodeHTTP status code
[in]messageUser message
Returns
Error code

Definition at line 1116 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]connectionStructure representing an HTTP connection
[in]statusCodeHTTP status code (301 for permanent redirects)
[in]uriNULL-terminated string containing the redirect URI
Returns
Error code

Definition at line 1182 of file http_server.c.

◆ httpSendResponse()

error_t httpSendResponse ( HttpConnection connection,
const char_t uri 
)

Send HTTP response.

Parameters
[in]connectionStructure representing an HTTP connection
[in]uriNULL-terminated string containing the file to be sent in response
Returns
Error code

Definition at line 911 of file http_server.c.

◆ httpServerGetDefaultSettings()

void httpServerGetDefaultSettings ( HttpServerSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains HTTP server settings

Definition at line 63 of file http_server.c.

◆ httpServerInit()

error_t httpServerInit ( HttpServerContext context,
const HttpServerSettings settings 
)

HTTP server initialization.

Parameters
[in]contextPointer to the HTTP server context
[in]settingsHTTP server specific settings
Returns
Error code

Definition at line 128 of file http_server.c.

◆ httpServerStart()

error_t httpServerStart ( HttpServerContext context)

Start HTTP server.

Parameters
[in]contextPointer to the HTTP server context
Returns
Error code

Definition at line 237 of file http_server.c.

◆ httpUpgradeToWebSocket()

WebSocket* httpUpgradeToWebSocket ( HttpConnection connection)

Upgrade an existing HTTP connection to a WebSocket.

Parameters
[in]connectionStructure representing an HTTP connection
Returns
Handle referencing the new WebSocket

Definition at line 1296 of file http_server.c.

◆ httpWriteHeader()

error_t httpWriteHeader ( HttpConnection connection)

Send HTTP response header.

Parameters
[in]connectionStructure representing an HTTP connection
Returns
Error code

Definition at line 673 of file http_server.c.

◆ httpWriteStream()

error_t httpWriteStream ( HttpConnection connection,
const void *  data,
size_t  length 
)

Write data to the client.

Parameters
[in]connectionStructure representing an HTTP connection
[in]dataBuffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
Returns
Error code

Definition at line 818 of file http_server.c.