All Projects → nekipelov → httpparser

nekipelov / httpparser

Licence: MIT license
HTTP request, response and urls parser

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to httpparser

libvcs
⚙️ Lite, typed, pythonic utilities for git, svn, mercurial, etc.
Stars: ✭ 43 (-37.68%)
Mutual labels:  url-parser
uri
A type to represent, query, and manipulate a Uniform Resource Identifier.
Stars: ✭ 16 (-76.81%)
Mutual labels:  url-parser
urldedupe
Pass in a list of URLs with query strings, get back a unique list of URLs and query string combinations
Stars: ✭ 208 (+201.45%)
Mutual labels:  url-parser
thhp
Very Fast HTTP Parser
Stars: ✭ 14 (-79.71%)
Mutual labels:  http-parser
url
A C++ library that implements the URL WhatWG specification
Stars: ✭ 35 (-49.28%)
Mutual labels:  url-parser
mofuparser
mofuparser is hyper minimal ultra fast http parser.
Stars: ✭ 17 (-75.36%)
Mutual labels:  http-parser
nodenative
C++14 port for the Node.js: native performance and modern simplicity
Stars: ✭ 15 (-78.26%)
Mutual labels:  http-parser
Uri.js
Javascript URL mutation library
Stars: ✭ 6,119 (+8768.12%)
Mutual labels:  url-parser
galer
A fast tool to fetch URLs from HTML attributes by crawl-in.
Stars: ✭ 138 (+100%)
Mutual labels:  url-parser
unew
A tool for append URLs, skipping duplicates/paths & combine parameters.
Stars: ✭ 103 (+49.28%)
Mutual labels:  url-parser

httpparser

Simple and fast HTTP request, response and urls parser written in C++.

Examples

#include <iostream>

#include <httpparser/request.h>
#include <httpparser/httprequestparser.h>

using namespace httpparser;

int main(int, char**)
{
    const char text[] = "GET /uri.cgi HTTP/1.1\r\n"
                        "User-Agent: Mozilla/5.0\r\n"
                        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
                        "Host: 127.0.0.1\r\n"
                        "\r\n";

    Request request;
    HttpRequestParser parser;

    HttpRequestParser::ParseResult res = parser.parse(request, text, text + strlen(text));

    if( res == HttpRequestParser::ParsingCompleted )
    {
        std::cout << request.inspect() << std::endl;
        return EXIT_SUCCESS;
    }
    else
    {
        std::cerr << "Parsing failed" << std::endl;
        return EXIT_FAILURE;
    }
}


#include <iostream>

#include <httpparser/response.h>
#include <httpparser/httpresponseparser.h>

using namespace httpparser;

int main(int, char**)
{
    const char text[] =
            "HTTP/1.1 200 OK\r\n"
            "Server: nginx/1.2.1\r\n"
            "Content-Type: text/html\r\n"
            "Content-Length: 8\r\n"
            "Connection: keep-alive\r\n"
            "\r\n"
            "<html />";

    Response response;
    HttpResponseParser parser;

    HttpResponseParser::ParseResult res = parser.parse(response, text, text + strlen(text));

    if( res == HttpResponseParser::ParsingCompleted )
    {
        std::cout << response.inspect() << std::endl;
        return EXIT_SUCCESS;
    }
    else
    {
        std::cerr << "Parsing failed" << std::endl;
        return EXIT_FAILURE;
    }
}


#include <iostream>
#include <httpparser/urlparser.h>

using namespace httpparser;

int main(int, char**)
{
    UrlParser parser;

    {
        const char url[] = "git+ssh://example.com/path/file";

        if( parser.parse(url) )
            std::cout << parser.scheme() << "://" << parser.hostname() << std::endl;
        else
            std::cerr << "Can't parse url: " << url << std::endl;
    }

    {
        const char url[] = "https://example.com/path/file";

        if( parser.parse(url) )
            std::cout << parser.scheme() << "://" << parser.hostname() << std::endl;
        else
            std::cerr << "Can't parse url: " << url << std::endl;
    }

    return EXIT_SUCCESS;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].