Convert Figma logo to code with AI

civetweb logocivetweb

Embedded C/C++ web server

2,807
951
2,807
172

Top Related Projects

10,940

Embedded Web Server

http request/response parser for c

Simple, secure & standards compliant web server for the most demanding of applications

A C++ header-only HTTP/HTTPS server and client library

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

Quick Overview

CivetWeb is a lightweight, embeddable web server and CGI framework written in C. It is designed to be easily integrated into existing applications, providing HTTP(S) server capabilities with minimal overhead. CivetWeb is a fork of the Mongoose project and is actively maintained with a focus on security and performance.

Pros

  • Lightweight and easy to embed in existing applications
  • Cross-platform support (Windows, Linux, macOS, and more)
  • Supports both IPv4 and IPv6
  • Extensive documentation and active community support

Cons

  • Limited built-in features compared to full-fledged web servers
  • May require additional libraries for certain functionalities (e.g., SSL support)
  • Performance may not be suitable for extremely high-traffic scenarios
  • Learning curve for developers unfamiliar with C programming

Code Examples

  1. Basic HTTP server setup:
#include "civetweb.h"

int main(void) {
    struct mg_context *ctx;
    const char *options[] = {
        "document_root", ".",
        "listening_ports", "8080",
        NULL
    };

    ctx = mg_start(NULL, NULL, options);
    getchar();  // Wait for user input
    mg_stop(ctx);

    return 0;
}
  1. Handling a specific URI:
#include "civetweb.h"

static int hello_world(struct mg_connection *conn, void *cbdata) {
    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n");
    mg_printf(conn, "Hello, World!");
    return 200;
}

int main(void) {
    struct mg_context *ctx;
    const char *options[] = {"listening_ports", "8080", NULL};

    ctx = mg_start(NULL, NULL, options);
    mg_set_request_handler(ctx, "/hello", hello_world, NULL);
    getchar();
    mg_stop(ctx);

    return 0;
}
  1. Serving static files:
#include "civetweb.h"

int main(void) {
    struct mg_context *ctx;
    const char *options[] = {
        "document_root", "./public",
        "listening_ports", "8080",
        NULL
    };

    ctx = mg_start(NULL, NULL, options);
    getchar();
    mg_stop(ctx);

    return 0;
}

Getting Started

  1. Clone the CivetWeb repository:

    git clone https://github.com/civetweb/civetweb.git
    
  2. Build the library:

    cd civetweb
    make
    
  3. Include the civetweb.h header in your C project and link against the built library.

  4. Use the code examples above as a starting point for your application.

  5. Compile your application, linking it with the CivetWeb library:

    gcc -o myapp myapp.c -lcivetweb -lpthread
    
  6. Run your application and access it through a web browser at http://localhost:8080.

Competitor Comparisons

10,940

Embedded Web Server

Pros of Mongoose

  • More feature-rich, including support for WebSockets, MQTT, and CoAP protocols
  • Better documentation and examples for various use cases
  • Active development with frequent updates and improvements

Cons of Mongoose

  • Dual-licensed: free for open-source projects, but requires a commercial license for closed-source applications
  • Larger codebase and potentially higher resource usage
  • Steeper learning curve due to more advanced features

Code Comparison

Mongoose:

struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://0.0.0.0:8000", fn, NULL);
for (;;) mg_mgr_poll(&mgr, 1000);

CivetWeb:

struct mg_context *ctx;
const char *options[] = {"listening_ports", "8080", NULL};
ctx = mg_start(NULL, NULL, options);
getchar();  // Wait for user input
mg_stop(ctx);

Both libraries offer simple APIs for creating HTTP servers, but Mongoose's API is more modern and flexible. CivetWeb's approach is simpler and may be easier for beginners to understand. Mongoose's code demonstrates its event-driven nature, while CivetWeb uses a more traditional blocking approach.

http request/response parser for c

Pros of http-parser

  • Lightweight and focused solely on HTTP parsing
  • Widely used and battle-tested in Node.js ecosystem
  • Designed for high performance and low memory footprint

Cons of http-parser

  • Limited to HTTP parsing, lacks full web server functionality
  • Requires additional components for a complete web server solution
  • Less feature-rich compared to CivetWeb's all-in-one approach

Code Comparison

CivetWeb example:

struct mg_context *ctx;
struct mg_callbacks callbacks;
const char *options[] = {"listening_ports", "8080", NULL};

memset(&callbacks, 0, sizeof(callbacks));
ctx = mg_start(&callbacks, NULL, options);

http-parser example:

http_parser_settings settings;
http_parser *parser = malloc(sizeof(http_parser));
http_parser_init(parser, HTTP_REQUEST);
parser->data = NULL;
http_parser_execute(parser, &settings, buf, len);

Summary

CivetWeb is a full-featured embedded web server library, while http-parser focuses solely on HTTP parsing. CivetWeb offers a more comprehensive solution out-of-the-box, including SSL support and WebSocket functionality. http-parser, on the other hand, provides a lightweight and efficient HTTP parsing solution, ideal for integration into larger projects or custom server implementations. The choice between the two depends on the specific requirements of your project and the level of control you need over the HTTP parsing and server functionality.

Simple, secure & standards compliant web server for the most demanding of applications

Pros of uWebSockets

  • Higher performance and scalability, especially for WebSocket connections
  • Lower memory footprint and CPU usage
  • Better suited for high-concurrency scenarios

Cons of uWebSockets

  • Less mature and potentially less stable than Civetweb
  • Narrower focus on WebSockets, while Civetweb offers a more general-purpose HTTP server
  • Steeper learning curve and potentially more complex implementation

Code Comparison

uWebSockets:

uWS::App().get("/hello", [](auto *res, auto *req) {
    res->end("Hello World!");
}).listen(3000, [](auto *token) {
    if (token) {
        std::cout << "Server started on port 3000" << std::endl;
    }
});

Civetweb:

mg_init_library(0);
struct mg_context *ctx = mg_start(NULL, NULL, options);
mg_set_request_handler(ctx, "/hello", hello_handler, NULL);
while (1) {
    mg_poll_server(ctx, 1000);
}

Both libraries offer efficient ways to create web servers, but uWebSockets focuses on high-performance WebSocket handling, while Civetweb provides a more traditional HTTP server approach. The choice between them depends on specific project requirements and performance needs.

A C++ header-only HTTP/HTTPS server and client library

Pros of cpp-httplib

  • Header-only library, making it easy to integrate into projects
  • Modern C++ design with support for C++11 and later
  • Simple and intuitive API for both client and server implementations

Cons of cpp-httplib

  • Less feature-rich compared to Civetweb, focusing primarily on HTTP functionality
  • May have lower performance for high-concurrency scenarios
  • Limited built-in SSL/TLS support, requiring external libraries for HTTPS

Code Comparison

cpp-httplib:

#include <httplib.h>

int main() {
    httplib::Server svr;
    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
        res.set_content("Hello, World!", "text/plain");
    });
    svr.listen("localhost", 8080);
}

Civetweb:

#include "civetweb.h"

int main() {
    struct mg_context *ctx;
    const char *options[] = {"listening_ports", "8080", NULL};
    ctx = mg_start(NULL, NULL, options);
    mg_set_request_handler(ctx, "/", hello, NULL);
    getchar();
    mg_stop(ctx);
    return 0;
}

The code comparison shows that cpp-httplib offers a more modern, C++-style API with lambda functions and built-in routing, while Civetweb uses a C-style API with function pointers and separate routing configuration.

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

Pros of cpprestsdk

  • More comprehensive and feature-rich library for modern C++ development
  • Better support for asynchronous programming and concurrency
  • Stronger integration with Microsoft technologies and Azure services

Cons of cpprestsdk

  • Larger and more complex codebase, potentially steeper learning curve
  • Heavier dependency on Boost libraries
  • May be overkill for simple web server applications

Code Comparison

cpprestsdk example (HTTP client):

#include <cpprest/http_client.h>

using namespace web::http::client;

http_client client(U("http://example.com"));
client.request(methods::GET, U("/api/data")).then([](http_response response) {
    // Handle response
});

Civetweb example (HTTP server):

#include "civetweb.h"

static int handler(struct mg_connection *conn, void *cbdata) {
    mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello, World!");
    return 200;
}

mg_start(&mg_callbacks, NULL, options);
mg_set_request_handler(ctx, "/", handler, NULL);

The code examples highlight the different focus areas of the libraries, with cpprestsdk emphasizing modern C++ features and asynchronous programming, while Civetweb provides a simpler C-style API for embedded web server functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CivetWeb CivetWeb

The official home of CivetWeb is on GitHub https://github.com/civetweb/civetweb

License GitHub contributors Stargazers Forks Latest Release

Continuous integration for Linux and macOS (Travis CI):

Travis Build Status

Continuous integration for Windows (AppVeyor):

Appveyor Build Status

Test coverage check (coveralls, codecov) (using different tools/settings):

Coveralls Coverage Status codecov

Static source code analysis (Coverity): Coverity Scan Build Status

CodeQL semantic code analysis: CodeQL

Project Mission

Project mission is to provide easy to use, powerful, C (C/C++) embeddable web server with optional CGI, SSL and Lua support. CivetWeb has a MIT license so you can innovate without restrictions.

CivetWeb can be used by developers as a library, to add web server functionality to an existing application.

It can also be used by end users as a stand-alone web server running on a Windows or Linux PC. It is available as single executable, no installation is required.

Where to find the official version?

End users can download CivetWeb binaries / releases from here on GitHub https://github.com/civetweb/civetweb/releases or SourceForge https://sourceforge.net/projects/civetweb/

Developers can contribute to CivetWeb via GitHub https://github.com/civetweb/civetweb

Due to a bug in Git for Windows V2.24 CivetWeb must be used with an earlier or later version (see also here).

Bugs and requests should be filed on GitHub https://github.com/civetweb/civetweb/issues

New releases are announced on Google Groups https://groups.google.com/d/forum/civetweb

Formerly some support question and discussion threads have been at Google groups. Recent questions and discussions use GitHub issues.

Source releases can be found on GitHub https://github.com/civetweb/civetweb/releases

A very brief overview can be found on GitHub Pages https://civetweb.github.io/civetweb/

Quick start documentation

Overview

CivetWeb keeps the balance between functionality and simplicity by a carefully selected list of features:

  • Forked from Mongoose in 2013, before it changed the licence from MIT to commercial + GPL. A lot of enhancements have been added since then, see RELEASE_NOTES.md.
  • Maintains the liberal, permissive, commercial-friendly, MIT license
  • Project is free from copy-left licenses, like GPL, because you should innovate without restrictions.
  • Works on Windows, Mac, Linux, UNIX, IOS, Android, Buildroot, and many other platforms.
  • Scripting and database support (CGI, Lua Server Pages, Server side Lua scripts, Lua SQLite database, Server side JavaScript). This provides a ready to go, powerful web development platform in a one single-click executable with no dependencies. 0
  • Support for CGI, SSI, HTTP digest (MD5) authorization, WebSocket, WebDAV.
  • Experimental HTTP/2 support.
  • HTTPS (SSL/TLS) support using OpenSSL.
  • Optional support for authentication using client side X.509 certificates.
  • Resumed download, URL rewrite, file blacklist, IP-based ACL.
  • Can run as a Windows service or systemd service.
  • Download speed limit based on client subnet or URI pattern.
  • Simple and clean embedding API.
  • The source is in single file for drop in compilation.
  • Embedding examples included.
  • HTTP client capable of sending arbitrary HTTP/HTTPS requests.
  • Websocket client functionality available (WS/WSS).

Optionally included software

Lua LuaFileSystem LuaSQLite3 Sqlite3 LuaXML Duktape

Optional dependencies

zlib

OpenSSL

Mbed TLS

Support

This project is very easy to install and use. Please read the documentation and have a look at the examples.

Recent questions and discussions usually use GitHub issues. Some old information may be found on the mailing list, but this information may be outdated.

Feel free to create a GitHub issue for bugs, feature requests, questions, suggestions or if you want to share tips and tricks. When creating an issues for a bug, add enough description to reproduce the issue - at least add CivetWeb version and operating system. Please see also the guidelines for Contributions and the Security Policy

Note: We do not take any liability or warranty for any linked contents. Visit these pages and try the community support suggestions at your own risk. Any link provided in this project (including source and documentation) is provided in the hope that this information will be helpful. However, we cannot accept any responsibility for any content on an external page.

Contributions

Contributions are welcome provided all contributions carry the MIT license.

DO NOT APPLY fixes copied from Mongoose to this project to prevent GPL tainting. Since 2013, CivetWeb and Mongoose have been developed independently. By now the code base differs, so patches cannot be safely transferred in either direction.

Some guidelines can be found in docs/Contribution.md.

Authors

CivetWeb was forked from the last MIT version of Mongoose in August 2013. Since then, CivetWeb has seen many improvements from various authors (Copyright (c) 2013-2021 the CivetWeb developers, MIT license).

A list of authors can be found in CREDITS.md.

CivetWeb is based on the Mongoose project. The original author of Mongoose was Sergey Lyubka(2004-2013) who released it under the MIT license. However, on August 16, 2013, Mongoose was relicensed to a dual GPL V2 + commercial license and CiwetWeb was created by Thomas Davis (sunsetbrew) as "the MIT fork of mongoose". The license change and CivetWeb fork was mentioned on the Mongoose Wikipedia page as well, but it's getting deleted (and added again) there every now and then.

Using the CivetWeb project ensures the MIT licenses terms are applied and GPL cannot be imposed on any of this code, as long as it is sourced from here. This code will remain free with the MIT license protection.