### Install Package Configuration Files Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt Installs the pkg-config file, CMake targets file, and package configuration files if either shared or static libraries are being built. ```cmake if(TARGET llhttp_shared OR TARGET llhttp_static) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) install(EXPORT llhttp FILE llhttp-targets.cmake NAMESPACE llhttp:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp ) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/llhttpConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/llhttpConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/llhttpConfigVersion.cmake COMPATIBILITY AnyNewerVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/llhttpConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/llhttpConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp ) endif() ``` -------------------------------- ### Firefox GET Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md An example GET request simulating a Firefox browser, featuring a comprehensive set of headers including User-Agent, Accept, Accept-Language, and Keep-Alive. The log output details the parsing of each header. ```http GET /favicon.ico HTTP/1.1 Host: 0.0.0.0=5000 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=12 span[url]="/favicon.ico" off=17 url complete off=17 len=4 span[protocol]="HTTP" off=21 protocol complete off=22 len=3 span[version]="1.1" off=25 version complete off=27 len=4 span[header_field]="Host" off=32 header_field complete off=33 len=12 span[header_value]="0.0.0.0=5000" off=47 header_value complete off=47 len=10 span[header_field]="User-Agent" off=58 header_field complete off=59 len=76 span[header_value]="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0" off=137 header_value complete off=137 len=6 span[header_field]="Accept" off=144 header_field complete off=145 len=63 span[header_value]="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" off=210 header_value complete off=210 len=15 span[header_field]="Accept-Language" off=226 header_field complete off=227 len=14 span[header_value]="en-us,en;q=0.5" off=243 header_value complete off=243 len=15 span[header_field]="Accept-Encoding" off=259 header_field complete off=260 len=12 span[header_value]="gzip,deflate" off=274 header_value complete off=274 len=14 span[header_field]="Accept-Charset" off=289 header_field complete off=290 len=30 span[header_value]="ISO-8859-1,utf-8;q=0.7,*;q=0.7" off=322 header_value complete off=322 len=10 span[header_field]="Keep-Alive" off=333 header_field complete off=334 len=3 span[header_value]="300" off=339 header_value complete off=339 len=10 span[header_field]="Connection" off=350 header_field complete off=351 len=10 span[header_value]="keep-alive" off=363 header_value complete off=365 headers complete method=1 v=1/1 flags=1 content_length=0 off=365 message complete ``` -------------------------------- ### SOURCE Request Example Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Displays a SOURCE request with a Host header and its parsed log output. ```http SOURCE /music/sweet/music HTTP/1.1 Host: example.com ``` ```log off=0 message begin off=0 len=6 span[method]="SOURCE" off=6 method complete off=7 len=18 span[url]="/music/sweet/music" off=26 url complete off=26 len=4 span[protocol]="HTTP" off=30 protocol complete off=31 len=3 span[version]="1.1" off=34 version complete off=36 len=4 span[header_field]="Host" off=41 header_field complete off=42 len=11 span[header_value]="example.com" off=55 header_value complete off=57 headers complete method=33 v=1/1 flags=0 content_length=0 off=57 message complete ``` -------------------------------- ### LINK Request Example Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Shows a LINK request with multiple Link headers and its detailed log output. ```http LINK /images/my_dog.jpg HTTP/1.1 Host: example.com Link: ; rel="tag" Link: ; rel="tag" ``` ```log off=0 message begin off=0 len=4 span[method]="LINK" off=4 method complete off=5 len=18 span[url]="/images/my_dog.jpg" off=24 url complete off=24 len=4 span[protocol]="HTTP" off=28 protocol complete off=29 len=3 span[version]="1.1" off=32 version complete off=34 len=4 span[header_field]="Host" off=39 header_field complete off=40 len=11 span[header_value]="example.com" off=53 header_value complete off=53 len=4 span[header_field]="Link" off=58 header_field complete off=59 len=44 span[header_value]="; rel="tag"" off=105 header_value complete off=105 len=4 span[header_field]="Link" off=110 header_field complete off=111 len=46 span[header_value]="; rel="tag"" off=159 header_value complete off=161 headers complete method=31 v=1/1 flags=0 content_length=0 off=161 message complete ``` -------------------------------- ### SEARCH Request Example Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Illustrates a SEARCH request with a Host header and its parsed log output. ```http SEARCH / HTTP/1.1 Host: www.example.com ``` ```log off=0 message begin off=0 len=6 span[method]="SEARCH" off=6 method complete off=7 len=1 span[url]="/" off=9 url complete off=9 len=4 span[protocol]="HTTP" off=13 protocol complete off=14 len=3 span[version]="1.1" off=17 version complete off=19 len=4 span[header_field]="Host" off=24 header_field complete off=25 len=15 span[header_value]="www.example.com" off=42 header_value complete off=44 headers complete method=14 v=1/1 flags=0 content_length=0 off=44 message complete ``` -------------------------------- ### Handle Invalid Response Start Source: https://github.com/nodejs/llhttp/blob/main/test/response/sample.md Illustrates error handling when a response does not start with 'HTTP/'. The log output shows the error code and reason. ```http HTTPER/1.1 200 OK ``` ```log off=0 message begin off=0 len=4 span[protocol]="HTTP" off=4 protocol complete off=4 error code=8 reason="Expected HTTP/, RTSP/ or ICE/" ``` -------------------------------- ### PURGE Request Example Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Demonstrates a PURGE request with basic headers and its corresponding log output. ```http PURGE /file.txt HTTP/1.1 Host: www.example.com ``` ```log off=0 message begin off=0 len=5 span[method]="PURGE" off=5 method complete off=6 len=9 span[url]="/file.txt" off=16 url complete off=16 len=4 span[protocol]="HTTP" off=20 protocol complete off=21 len=3 span[version]="1.1" off=24 version complete off=26 len=4 span[header_field]="Host" off=31 header_field complete off=32 len=15 span[header_value]="www.example.com" off=49 header_value complete off=51 headers complete method=29 v=1/1 flags=0 content_length=0 off=51 message complete ``` -------------------------------- ### Build llhttp with npm and make Source: https://github.com/nodejs/llhttp/blob/main/README.md Standard build instructions for the llhttp project using npm and make. Ensure Node.js, npm, and npx are installed. ```sh npm ci make ``` -------------------------------- ### Print Project Configure Summary Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt Outputs a summary of the project's configuration settings to the console, including build type, install prefix, and library build options. ```cmake # Print project configure summary message(STATUS "") message(STATUS "") message(STATUS "Project configure summary:") message(STATUS "") message(STATUS " CMake build type .................: ${CMAKE_BUILD_TYPE}") message(STATUS " Install prefix ...................: ${CMAKE_INSTALL_PREFIX}") message(STATUS " Build shared library .............: ${LLHTTP_BUILD_SHARED_LIBS}") message(STATUS " Build static library .............: ${LLHTTP_BUILD_STATIC_LIBS}") message(STATUS "") ``` -------------------------------- ### HTTP Request with CRLF and Implicit Keep-Alive Source: https://github.com/nodejs/llhttp/blob/main/test/request/connection.md Example of an HTTP POST request followed by a GET request, separated by a CRLF, demonstrating implicit 'keep-alive' behavior. ```http POST / HTTP/1.1 Host: www.example.com Content-Type: application/x-www-form-urlencoded Content-Length: 4 q=42 GET / HTTP/1.1 ``` -------------------------------- ### Project and Include Directories Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt Defines the project name and version, and includes necessary CMake modules for installation and package configuration. ```cmake project(llhttp VERSION _RELEASE_) include(GNUInstallDirs) include(CMakePackageConfigHelpers) ``` -------------------------------- ### Reject Space After Start Line (Relaxed Mode) Source: https://github.com/nodejs/llhttp/blob/main/test/request/lenient-header-value-relaxed.md Confirms that a space character immediately following the start line is rejected, even when relaxed header value parsing is enabled, as this is not permitted. ```http GET /url HTTP/1.1 Header1: value ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=4 span[url]="/url" off=9 url complete off=9 len=4 span[protocol]="HTTP" off=13 protocol complete off=14 len=3 span[version]="1.1" off=17 version complete off=20 error code=30 reason="Unexpected space after start line" ``` -------------------------------- ### curl GET Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md A sample GET request as typically sent by curl, including User-Agent, Host, and Accept headers. The log details the parsing of all these components. ```http GET /test HTTP/1.1 User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1 Host: 0.0.0.0=5000 Accept: */* ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=5 span[url]="/test" off=10 url complete off=10 len=4 span[protocol]="HTTP" off=14 protocol complete off=15 len=3 span[version]="1.1" off=18 version complete off=20 len=10 span[header_field]="User-Agent" off=31 header_field complete off=32 len=85 span[header_value]="curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1" off=119 header_value complete off=119 len=4 span[header_field]="Host" off=124 header_field complete off=125 len=12 span[header_value]="0.0.0.0=5000" off=139 header_value complete off=139 len=6 span[header_field]="Accept" off=146 header_field complete off=147 len=3 span[header_value]="*/*" off=152 header_value complete off=154 headers complete method=1 v=1/1 flags=0 content_length=0 off=154 message complete ``` -------------------------------- ### HTTP Response with Content-Length-X and Transfer-Encoding Source: https://github.com/nodejs/llhttp/blob/main/test/response/content-length.md This example demonstrates that headers starting with 'Content-Length*' are not treated as the standard Content-Length header. Here, 'Content-Length-X' is present alongside 'Transfer-Encoding: chunked'. ```http HTTP/1.1 200 OK Content-Length-X: 0 Transfer-Encoding: chunked 2 OK 0 ``` -------------------------------- ### Upgrade GET Request with WebSocket Headers Source: https://github.com/nodejs/llhttp/blob/main/test/request/connection.md Demonstrates an HTTP GET request that includes headers specific to a WebSocket upgrade, such as 'Sec-WebSocket-Key1', 'Sec-WebSocket-Key2', and 'Sec-WebSocket-Protocol'. llhttp correctly parses these headers and flags the request for upgrade. ```http GET /demo HTTP/1.1 Host: example.com Connection: Upgrade Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 Sec-WebSocket-Protocol: sample Upgrade: WebSocket Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 Origin: http://example.com Hot diggity dogg ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=5 span[url]="/demo" off=10 url complete off=10 len=4 span[protocol]="HTTP" off=14 protocol complete off=15 len=3 span[version]="1.1" off=18 version complete off=20 len=4 span[header_field]="Host" off=25 header_field complete off=26 len=11 span[header_value]="example.com" off=39 header_value complete off=39 len=10 span[header_field]="Connection" off=50 header_field complete off=51 len=7 span[header_value]="Upgrade" off=60 header_value complete off=60 len=18 span[header_field]="Sec-WebSocket-Key2" off=79 header_field complete off=80 len=18 span[header_value]="12998 5 Y3 1 .P00" off=100 header_value complete off=100 len=22 span[header_field]="Sec-WebSocket-Protocol" off=123 header_field complete off=124 len=6 span[header_value]="sample" off=132 header_value complete off=132 len=7 span[header_field]="Upgrade" off=140 header_field complete off=141 len=9 span[header_value]="WebSocket" off=152 header_value complete off=152 len=18 span[header_field]="Sec-WebSocket-Key1" off=171 header_field complete off=172 len=20 span[header_value]="4 @1 46546xW%0l 1 5" off=194 header_value complete off=194 len=6 span[header_field]="Origin" off=201 header_field complete off=202 len=18 span[header_value]="http://example.com" off=222 header_value complete off=224 headers complete method=1 v=1/1 flags=14 content_length=0 off=224 message complete off=224 error code=22 reason="Pause on CONNECT/Upgrade" ``` -------------------------------- ### Apache Bench GET Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Parses a GET request as generated by ApacheBench, including Host and User-Agent headers. ```http GET /test HTTP/1.0 Host: 0.0.0.0:5000 User-Agent: ApacheBench/2.3 Accept: */* ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=5 span[url]="/test" off=10 url complete off=10 len=4 span[protocol]="HTTP" off=14 protocol complete off=15 len=3 span[version]="1.0" off=18 version complete off=20 len=4 span[header_field]="Host" off=25 header_field complete off=26 len=12 span[header_value]="0.0.0.0:5000" off=40 header_value complete off=40 len=10 span[header_field]="User-Agent" off=51 header_field complete off=52 len=15 span[header_value]="ApacheBench/2.3" off=69 header_value complete off=69 len=6 span[header_field]="Accept" off=76 header_field complete off=77 len=3 span[header_value]="*/*" off=82 header_value complete off=84 headers complete method=1 v=1/0 flags=0 content_length=0 off=84 message complete ``` -------------------------------- ### Function to Configure Library Target Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt A function to set up library targets, including sources, include directories, properties, and installation rules. ```cmake function(config_library target) target_sources(${target} PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS}) target_include_directories(${target} PUBLIC $ $ ) set_target_properties(${target} PROPERTIES OUTPUT_NAME llhttp VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} PUBLIC_HEADER ${LLHTTP_HEADERS} ) install(TARGETS ${target} EXPORT llhttp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) endfunction(config_library target) ``` -------------------------------- ### PATCH Request Example Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Shows a PATCH request with a Content-Type and Content-Length, followed by its parsed log output. ```http PATCH /file.txt HTTP/1.1 Host: www.example.com Content-Type: application/example If-Match: "e0023aa4e" Content-Length: 10 cccccccccc ``` ```log off=0 message begin off=0 len=5 span[method]="PATCH" off=5 method complete off=6 len=9 span[url]="/file.txt" off=16 url complete off=16 len=4 span[protocol]="HTTP" off=20 protocol complete off=21 len=3 span[version]="1.1" off=24 version complete off=26 len=4 span[header_field]="Host" off=31 header_field complete off=32 len=15 span[header_value]="www.example.com" off=49 header_value complete off=49 len=12 span[header_field]="Content-Type" off=62 header_field complete off=63 len=19 span[header_value]="application/example" off=84 header_value complete off=84 len=8 span[header_field]="If-Match" off=93 header_field complete off=94 len=11 span[header_value]=""e0023aa4e"" off=107 header_value complete off=107 len=14 span[header_field]="Content-Length" off=122 header_field complete off=123 len=2 span[header_value]="10" off=127 header_value complete off=129 headers complete method=28 v=1/1 flags=20 content_length=10 off=129 len=10 span[body]="cccccccccc" off=139 message complete ``` -------------------------------- ### OPTIONS Request with RTSP Protocol Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Shows an OPTIONS request using the RTSP protocol. This example includes the HTTP request and its detailed log parsing. ```http OPTIONS /music/sweet/music RTSP/1.0 Host: example.com ``` ```log off=0 message begin off=0 len=7 span[method]="OPTIONS" off=7 method complete off=8 len=18 span[url]="/music/sweet/music" off=27 url complete off=27 len=4 span[protocol]="RTSP" off=31 protocol complete off=32 len=3 span[version]="1.0" off=35 version complete off=37 len=4 span[header_field]="Host" off=42 header_field complete off=43 len=11 span[header_value]="example.com" off=56 header_value complete off=58 headers complete method=6 v=1/0 flags=0 content_length=0 off=58 message complete ``` -------------------------------- ### HTTP POST Request with Connection Upgrade Source: https://github.com/nodejs/llhttp/blob/main/test/request/connection.md This snippet shows an example HTTP POST request that includes headers for upgrading the connection. It specifies 'Connection: Upgrade' and 'Upgrade: HTTP/2.0'. ```http POST /demo HTTP/1.1 Host: example.com Connection: Upgrade Upgrade: HTTP/2.0 Content-Length: 15 sweet post body Hot diggity dogg ``` -------------------------------- ### Pause on Message Begin Source: https://github.com/nodejs/llhttp/blob/main/test/request/pausing.md Demonstrates pausing the HTTP parser immediately after the message begins. This is useful for pre-processing or validating the start of a message. ```http POST / HTTP/1.1 Content-Length: 3 abc ``` ```log off=0 message begin off=0 pause off=0 len=4 span[method]="POST" off=4 method complete off=5 len=1 span[url]="/" off=7 url complete off=7 len=4 span[protocol]="HTTP" off=11 protocol complete off=12 len=3 span[version]="1.1" off=15 version complete off=17 len=14 span[header_field]="Content-Length" off=32 header_field complete off=33 len=1 span[header_value]="3" off=36 header_value complete off=38 headers complete method=3 v=1/1 flags=20 content_length=3 off=38 len=3 span[body]="abc" off=41 message complete ``` -------------------------------- ### Dumbpack Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Parses a simple GET request with custom headers. ```http GET /dumbpack HTTP/1.1 ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=9 span[url]="/dumbpack" off=14 url complete off=14 len=4 span[protocol]="HTTP" off=18 protocol complete off=19 len=3 span[version]="1.1" off=22 version complete off=24 len=13 span[header_field]="aaaaaaaaaaaaa" off=38 header_field complete off=38 len=10 span[header_value]="++++++++++" off=50 header_value complete off=52 headers complete method=1 v=1/1 flags=0 content_length=0 off=52 message complete ``` -------------------------------- ### Integrate llhttp as a Shared Library with CMake Source: https://github.com/nodejs/llhttp/blob/main/README.md Example CMake snippet for integrating llhttp as a shared library using FetchContent. Ensure you have the correct URL for the llhttp archive. ```cmake FetchContent_Declare(llhttp URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz") FetchContent_MakeAvailable(llhttp) ``` -------------------------------- ### HTTP Response with Tab in Content-Length Source: https://github.com/nodejs/llhttp/blob/main/test/response/content-length.md An example HTTP response demonstrating a Content-Length header with a tab character. ```http HTTP/1.1 200 OK Content-Length: 42 ``` -------------------------------- ### HTTP Request with HTTP/1.0 (No Keep-Alive) Source: https://github.com/nodejs/llhttp/blob/main/test/request/connection.md Example of an HTTP/1.0 request followed by an HTTP/1.1 request, demonstrating that 'keep-alive' is off for HTTP/1.0 and results in an error for subsequent data. ```http PUT /url HTTP/1.0 PUT /url HTTP/1.1 ``` -------------------------------- ### Pause on Message Begin Source: https://github.com/nodejs/llhttp/blob/main/test/response/pausing.md Pauses parsing immediately after the message begins. This is useful for initial validation or setup before any other part of the message is processed. ```log off=0 message begin off=0 pause off=0 len=4 span[protocol]="HTTP" off=4 protocol complete off=5 len=3 span[version]="1.1" off=8 version complete off=13 len=2 span[status]="OK" off=17 status complete off=17 len=14 span[header_field]="Content-Length" off=32 header_field complete off=33 len=1 span[header_value]="3" off=36 header_value complete off=38 headers complete status=200 v=1/1 flags=20 content_length=3 off=38 len=3 span[body]="abc" off=41 message complete ``` -------------------------------- ### HTTP Request with Quoted URI Components Source: https://github.com/nodejs/llhttp/blob/main/test/request/uri.md Demonstrates a GET request with quoted characters in the URI path and query string. The parser correctly identifies these components. ```http GET /with_"lovely"_quotes?foo=\"bar\" HTTP/1.1 ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=33 span[url]="/with_"lovely"_quotes?foo=\"bar\"" off=38 url complete off=38 len=4 span[protocol]="HTTP" off=42 protocol complete off=43 len=3 span[version]="1.1" off=46 version complete off=50 headers complete method=1 v=1/1 flags=0 content_length=0 off=50 message complete ``` -------------------------------- ### Chunk Header Not Terminated by CRLF (Lenient) Source: https://github.com/nodejs/llhttp/blob/main/test/request/transfer-encoding.md This example shows a lenient HTTP GET request where a chunk header (size '6') is followed by CRLF, but the subsequent data line starts with a CR. llhttp processes this leniently, parsing the chunk and subsequent message. ```http GET / HTTP/1.1 Host: a Connection: close Transfer-Encoding: chunked 6 ;ABCD 33 E 0 GET / HTTP/1.1 Host: a Content-Length: 5 0 ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=1 span[url]="/" off=6 url complete off=6 len=4 span[protocol]="HTTP" off=10 protocol complete off=11 len=3 span[version]="1.1" off=14 version complete off=16 len=4 span[header_field]="Host" off=21 header_field complete off=22 len=1 span[header_value]="a" off=25 header_value complete off=25 len=10 span[header_field]="Connection" off=36 header_field complete off=37 len=6 span[header_value]="close " off=45 header_value complete off=45 len=17 span[header_field]="Transfer-Encoding" off=63 header_field complete off=64 len=8 span[header_value]="chunked " off=74 header_value complete off=76 headers complete method=1 v=1/1 flags=20a content_length=0 off=78 chunk header len=6 off=78 len=1 span[body]=cr off=79 len=5 span[body]=";ABCD" off=86 chunk complete off=90 chunk header len=51 off=90 len=1 span[body]="E" off=91 len=1 span[body]=cr off=92 len=1 span[body]=lf off=93 len=1 span[body]="0" off=94 len=1 span[body]=cr off=95 len=1 span[body]=lf off=96 len=1 span[body]=cr off=97 len=1 span[body]=lf off=98 len=15 span[body]="GET / HTTP/1.1 " off=113 len=1 span[body]=cr off=114 len=1 span[body]=lf off=115 len=7 span[body]="Host: a" off=122 len=1 span[body]=cr off=123 len=1 span[body]=lf off=124 len=17 span[body]="Content-Length: 5" off=143 chunk complete off=146 chunk header len=0 off=148 chunk complete off=148 message complete ``` -------------------------------- ### Basic HTTP Parsing with llhttp Source: https://github.com/nodejs/llhttp/blob/main/README.md Demonstrates how to initialize the llhttp parser, set a callback for message completion, and execute a simple HTTP request. Ensure llhttp is properly included and initialized before use. ```C #include "stdio.h" #include "llhttp.h" #include "string.h" int handle_on_message_complete(llhttp_t* parser) { fprintf(stdout, "Message completed!\n"); return 0; } int main() { llhttp_t parser; llhttp_settings_t settings; /*Initialize user callbacks and settings */ llhttp_settings_init(&settings); /*Set user callback */ settings.on_message_complete = handle_on_message_complete; /*Initialize the parser in HTTP_BOTH mode, meaning that it will select between *HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first *input. */ llhttp_init(&parser, HTTP_BOTH, &settings); /*Parse request! */ const char* request = "GET / HTTP/1.1\r\n\r\n"; int request_len = strlen(request); enum llhttp_errno err = llhttp_execute(&parser, request, request_len); if (err == HPE_OK) { fprintf(stdout, "Successfully parsed!\n"); } else { fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err), llhttp_get_error_reason(&parser)); } } ``` -------------------------------- ### CR Before Response and Tab After HTTP Version Source: https://github.com/nodejs/llhttp/blob/main/test/response/invalid.md This example demonstrates an invalid response starting with a carriage return (CR) before the protocol and a tab after the HTTP version. ```http \rHTTP/1.1\t200 OK ``` ```log off=1 message begin off=1 len=4 span[protocol]="HTTP" off=5 protocol complete off=6 len=3 span[version]="1.1" off=9 version complete off=9 error code=9 reason="Expected space after version" ``` -------------------------------- ### HTTP Request with LWS in Connection Header Source: https://github.com/nodejs/llhttp/blob/main/test/request/connection.md Shows a GET request where the 'Connection' header uses linear whitespace (LWS) between tokens. This example is parsed successfully, demonstrating handling of standard LWS. ```http GET /demo HTTP/1.1 Connection: keep-alive, upgrade Upgrade: WebSocket Hot diggity dogg ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=5 span[url]="/demo" off=10 url complete off=10 len=4 span[protocol]="HTTP" off=14 protocol complete off=15 len=3 span[version]="1.1" off=18 version complete off=20 len=10 span[header_field]="Connection" off=31 header_field complete off=32 len=19 span[header_value]="keep-alive, upgrade" off=53 header_value complete off=53 len=7 span[header_field]="Upgrade" off=61 header_field complete off=62 len=9 span[header_value]="WebSocket" off=73 header_value complete off=75 headers complete method=1 v=1/1 flags=15 content_length=0 off=75 message complete off=75 error code=22 reason="Pause on CONNECT/Upgrade" ``` -------------------------------- ### Simple HTTP OPTIONS Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Demonstrates a basic HTTP OPTIONS request with two headers. The log output shows the parsing of the method, URL, protocol, version, and headers. ```http OPTIONS /url HTTP/1.1 Header1: Value1 Header2: Value2 ``` ```log off=0 message begin off=0 len=7 span[method]="OPTIONS" off=7 method complete off=8 len=4 span[url]="/url" off=13 url complete off=13 len=4 span[protocol]="HTTP" off=17 protocol complete off=18 len=3 span[version]="1.1" off=21 version complete off=23 len=7 span[header_field]="Header1" off=31 header_field complete off=32 len=6 span[header_value]="Value1" off=40 header_value complete off=40 len=7 span[header_field]="Header2" off=48 header_field complete off=50 len=6 span[header_value]="Value2" off=58 header_value complete off=60 headers complete method=6 v=1/1 flags=0 content_length=0 off=60 message complete ``` -------------------------------- ### GET Request with No HTTP Version Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Parses a GET request where the HTTP version is omitted. ```http GET / ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=1 span[url]="/" off=7 url complete off=9 headers complete method=1 v=0/9 flags=0 content_length=0 off=9 message complete ``` -------------------------------- ### GET Request with No Headers or Body Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Parses a GET request that explicitly has no headers or body. ```http GET /get_no_headers_no_body/world HTTP/1.1 ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=29 span[url]="/get_no_headers_no_body/world" off=34 url complete off=34 len=4 span[protocol]="HTTP" off=38 protocol complete off=39 len=3 span[version]="1.1" off=42 version complete off=46 headers complete method=1 v=1/1 flags=0 content_length=0 off=46 message complete ``` -------------------------------- ### GET Request with One Header and No Body Source: https://github.com/nodejs/llhttp/blob/main/test/request/sample.md Parses a GET request with a single header and no body. ```http GET /get_one_header_no_body HTTP/1.1 Accept: */* ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=23 span[url]="/get_one_header_no_body" off=28 url complete off=28 len=4 span[protocol]="HTTP" off=32 protocol complete off=33 len=3 span[version]="1.1" off=36 version complete off=38 len=6 span[header_field]="Accept" off=45 header_field complete off=46 len=3 span[header_value]="*/*" off=51 header_value complete off=53 headers complete method=1 v=1/1 flags=0 content_length=0 off=53 message complete ``` -------------------------------- ### Run Local Checks Source: https://github.com/nodejs/llhttp/blob/main/docs/releasing.md Before releasing, lint the code, build the project, and run the test suite locally to ensure everything is in order. ```bash npm run lint npm run build npm run test ``` -------------------------------- ### Invalid Space After Start Line Source: https://github.com/nodejs/llhttp/blob/main/test/response/invalid.md An unexpected space character after the HTTP start line (version and status code) is flagged as an error. ```http HTTP/1.1 200 OK Host: foo ``` ```log off=0 message begin off=0 len=4 span[protocol]="HTTP" off=4 protocol complete off=5 len=3 span[version]="1.1" off=8 version complete off=13 len=2 span[status]="OK" off=17 status complete off=18 error code=30 reason="Unexpected space after start line" ``` -------------------------------- ### llhttp_init Source: https://github.com/nodejs/llhttp/blob/main/README.md Initializes the HTTP parser with a specified type and user-defined settings. This is the first step before any parsing can occur. ```APIDOC ## llhttp_init ### Description Initialize the parser with specific type and user settings. ### Signature `void llhttp_init(llhttp_t* parser, llhttp_type_t type, const llhttp_settings_t* settings)` ``` -------------------------------- ### Define Source and Header Files Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt Lists the source files and header files for the llhttp library. ```cmake # Source code set(LLHTTP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/llhttp.c ${CMAKE_CURRENT_SOURCE_DIR}/src/http.c ${CMAKE_CURRENT_SOURCE_DIR}/src/api.c ) set(LLHTTP_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/llhttp.h ) ``` -------------------------------- ### llhttp Log for Response Starting with CRLF Source: https://github.com/nodejs/llhttp/blob/main/test/response/sample.md This log shows the parsing of an HTTP response that starts with CRLF, including the identification of headers and a Content-Length of 0. ```log off=2 message begin off=2 len=4 span[protocol]="HTTP" off=6 protocol complete off=7 len=3 span[version]="1.1" off=10 version complete off=15 len=2 span[status]="OK" off=19 status complete off=19 len=7 span[header_field]="Header1" off=27 header_field complete off=28 len=6 span[header_value]="Value1" off=36 header_value complete off=36 len=7 span[header_field]="Header2" off=44 header_field complete off=46 len=6 span[header_value]="Value2" off=54 header_value complete off=54 len=14 span[header_field]="Content-Length" off=69 header_field complete off=70 len=1 span[header_value]="0" off=73 header_value complete off=75 headers complete status=200 v=1/1 flags=20 content_length=0 off=75 message complete ``` -------------------------------- ### HTTP Request with Invalid Space After Start Line Source: https://github.com/nodejs/llhttp/blob/main/test/request/invalid.md This snippet shows an HTTP request with an unexpected space after the start line, causing a parsing error. ```http GET / HTTP/1.1 Host: foo ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=1 span[url]="/" off=6 url complete off=6 len=4 span[protocol]="HTTP" off=10 protocol complete off=11 len=3 span[version]="1.1" off=14 version complete off=17 error code=30 reason="Unexpected space after start line" ``` -------------------------------- ### Create GitHub Release with CLI Source: https://github.com/nodejs/llhttp/blob/main/docs/releasing.md Use the GitHub CLI to automate the creation of a draft release on GitHub. The command will open the draft in your browser for review and publishing. ```bash npm run github-release ``` -------------------------------- ### llhttp_settings_init Source: https://github.com/nodejs/llhttp/blob/main/README.md Initializes the llhttp_settings_t structure, preparing it to hold callback functions for parser events. ```APIDOC ## llhttp_settings_init ### Description Initialize the settings object. ### Signature `void llhttp_settings_init(llhttp_settings_t* settings)` ``` -------------------------------- ### Safe to Finish after GET Request Source: https://github.com/nodejs/llhttp/blob/main/test/request/finish.md Demonstrates that calling llhttp_finish() is safe after a complete GET request has been processed. The logs show the successful parsing and completion of the request. ```http GET / HTTP/1.1 ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=1 span[url]="/" off=6 url complete off=6 len=4 span[protocol]="HTTP" off=10 protocol complete off=11 len=3 span[version]="1.1" off=14 version complete off=18 headers complete method=1 v=1/1 flags=0 content_length=0 off=18 message complete off=NULL finish=0 ``` -------------------------------- ### QUERY Request with HTTP/1.1 and Body Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Demonstrates a QUERY request with HTTP/1.1, including headers and a request body. The log output details the parsing of each component. ```http QUERY /contacts HTTP/1.1 Host: example.org Content-Type: example/query Accept: text/csv Content-Length: 41 select surname, givenname, email limit 10 ``` ```log off=0 message begin off=0 len=5 span[method]="QUERY" off=5 method complete off=6 len=9 span[url]="/contacts" off=16 url complete off=16 len=4 span[protocol]="HTTP" off=20 protocol complete off=21 len=3 span[version]="1.1" off=24 version complete off=26 len=4 span[header_field]="Host" off=31 header_field complete off=32 len=11 span[header_value]="example.org" off=45 header_value complete off=45 len=12 span[header_field]="Content-Type" off=58 header_field complete off=59 len=13 span[header_value]="example/query" off=74 header_value complete off=74 len=6 span[header_field]="Accept" off=81 header_field complete off=82 len=8 span[header_value]="text/csv" off=92 header_value complete off=92 len=14 span[header_field]="Content-Length" off=107 header_field complete off=108 len=2 span[header_value]="41" off=112 header_value complete off=114 headers complete method=46 v=1/1 flags=20 content_length=41 off=114 len=41 span[body]="select surname, givenname, email limit 10" off=155 message complete ``` -------------------------------- ### Link llhttp Static Library with C++ Executable on Windows Source: https://github.com/nodejs/llhttp/blob/main/README.md This command shows how to compile a C++ source file and link it with the llhttp static library on Windows. Ensure the build directory is included in the include path. ```shell clang++ -Os -g3 -Wall -Wextra -Wno-unused-parameter -I/path/to/llhttp/build main.cpp /path/to/llhttp/build/libllhttp.a -o main.exe ``` -------------------------------- ### PRI Request with HTTP/2 Source: https://github.com/nodejs/llhttp/blob/main/test/request/method.md Shows a PRI request, often used in HTTP/2 for connection preface. This example includes the request and its log output, noting a 'Pause on PRI/Upgrade' error. ```http PRI * HTTP/1.1 SM ``` ```log off=0 message begin off=0 len=3 span[method]="PRI" off=3 method complete off=4 len=1 span[url]="*" off=6 url complete off=6 len=4 span[protocol]="HTTP" off=10 protocol complete off=11 len=3 span[version]="1.1" off=14 version complete off=24 error code=23 reason="Pause on PRI/Upgrade" ``` -------------------------------- ### ICE Protocol with GET Method Source: https://github.com/nodejs/llhttp/blob/main/test/request/invalid.md This snippet shows an invalid request using the GET method with the ICE protocol. The parser expects a SOURCE method for ICE/x.x requests. ```http GET /music/sweet/music ICE/1.0 Host: example.com ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=18 span[url]="/music/sweet/music" off=23 url complete off=23 len=3 span[protocol]="ICE" off=26 protocol complete off=26 error code=8 reason="Expected SOURCE method for ICE/x.x request" ``` -------------------------------- ### Fetch and Build llhttp as a Static Library in CMake Source: https://github.com/nodejs/llhttp/blob/main/README.md This snippet demonstrates fetching llhttp using FetchContent, configuring it to build as a static library, and then linking the static target. Note that options like LLHTTP_BUILD_SHARED_LIBS were previously named BUILD_SHARED_LIBS. ```cmake FetchContent_Declare(llhttp URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz") set(LLHTTP_BUILD_SHARED_LIBS OFF CACHE INTERNAL "") set(LLHTTP_BUILD_STATIC_LIBS ON CACHE INTERNAL "") FetchContent_MakeAvailable(llhttp) # Link with the llhttp_static target target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_static ${PROJECT_NAME}) ``` -------------------------------- ### HTTP GET Request with Corrupted Header Name Source: https://github.com/nodejs/llhttp/blob/main/test/request/invalid.md This snippet illustrates an HTTP GET request with a corrupted header name containing non-standard characters. The parser reports an 'Invalid header token' error. ```http GET / HTTP/1.1 Host: www.example.com X-Some-Header\r\033\065\325eep-Alive Accept-Encoding: gzip ``` ```log off=0 message begin off=0 len=3 span[method]="GET" off=3 method complete off=4 len=1 span[url]="/" off=6 url complete off=6 len=4 span[protocol]="HTTP" off=10 protocol complete off=11 len=3 span[version]="1.1" off=14 version complete off=16 len=4 span[header_field]="Host" off=21 header_field complete off=22 len=15 span[header_value]="www.example.com" off=39 header_value complete off=52 error code=10 reason="Invalid header token" ``` -------------------------------- ### Configure Package Information File Source: https://github.com/nodejs/llhttp/blob/main/CMakeLists.txt Generates a .pc file for pkg-config, which is used to provide library information to other projects. ```cmake configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc @ONLY ) ```