├── .codecov.yml ├── .drone.star ├── .drone ├── drone.bat └── drone.sh ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.adoc ├── build └── Jamfile ├── cmake └── toolchains │ ├── clang.cmake │ ├── common.cmake │ ├── gcc.cmake │ └── msvc.cmake ├── doc ├── .gitignore ├── antora.yml ├── build_antora.bat ├── build_antora.sh ├── images │ └── repo-logo.png ├── local-playbook.yml ├── modules │ └── ROOT │ │ ├── images │ │ ├── ClassHierarchy.odg │ │ ├── ClassHierarchy.svg │ │ └── doc-logo.png │ │ ├── nav.adoc │ │ └── pages │ │ ├── Message.adoc │ │ ├── design_requirements │ │ ├── parser.adoc │ │ └── serializer.adoc │ │ ├── header_containers.adoc │ │ ├── http_protocol_basics.adoc │ │ ├── index.adoc │ │ ├── message_bodies.adoc │ │ └── sans_io_philosophy.adoc ├── mrdocs.yml ├── package-lock.json └── package.json ├── include └── boost │ ├── http_proto.hpp │ └── http_proto │ ├── context.hpp │ ├── deflate.hpp │ ├── detail │ ├── align_up.hpp │ ├── array_of_buffers.hpp │ ├── config.hpp │ ├── except.hpp │ ├── header.hpp │ ├── impl │ │ ├── array_of_buffers.hpp │ │ └── workspace.hpp │ ├── sv.hpp │ ├── type_index.hpp │ ├── type_traits.hpp │ └── workspace.hpp │ ├── error.hpp │ ├── field.hpp │ ├── fields.hpp │ ├── fields_base.hpp │ ├── fields_view.hpp │ ├── fields_view_base.hpp │ ├── file.hpp │ ├── file_base.hpp │ ├── file_body.hpp │ ├── file_posix.hpp │ ├── file_stdio.hpp │ ├── file_win32.hpp │ ├── header_limits.hpp │ ├── http_proto.natvis │ ├── impl │ ├── context.hpp │ ├── error.hpp │ ├── fields_view_base.hpp │ ├── parser.hpp │ ├── sink.hpp │ └── source.hpp │ ├── message_base.hpp │ ├── message_view_base.hpp │ ├── metadata.hpp │ ├── method.hpp │ ├── parser.hpp │ ├── request.hpp │ ├── request_base.hpp │ ├── request_parser.hpp │ ├── request_view.hpp │ ├── response.hpp │ ├── response_base.hpp │ ├── response_parser.hpp │ ├── response_view.hpp │ ├── rfc │ ├── combine_field_values.hpp │ ├── detail │ │ └── rules.hpp │ ├── impl │ │ └── list_rule.hpp │ ├── list_rule.hpp │ ├── media_type.hpp │ ├── parameter.hpp │ ├── quoted_token_rule.hpp │ ├── quoted_token_view.hpp │ ├── token_rule.hpp │ └── upgrade_rule.hpp │ ├── serializer.hpp │ ├── service │ ├── deflate_service.hpp │ ├── impl │ │ └── zlib_service.hpp │ ├── inflate_service.hpp │ ├── service.hpp │ └── zlib_service.hpp │ ├── sink.hpp │ ├── source.hpp │ ├── static_fields.hpp │ ├── static_request.hpp │ ├── static_response.hpp │ ├── status.hpp │ ├── string_body.hpp │ └── version.hpp ├── index.html ├── meta ├── explicit-failures-markup.xml └── libraries.json ├── src ├── context.cpp ├── detail │ ├── except.cpp │ ├── filter.hpp │ ├── header.cpp │ ├── impl │ │ └── filter.hpp │ ├── move_chars.hpp │ ├── number_string.hpp │ ├── win32_unicode_path.hpp │ └── workspace.cpp ├── error.cpp ├── field.cpp ├── fields.cpp ├── fields_base.cpp ├── fields_view_base.cpp ├── file_body.cpp ├── file_posix.cpp ├── file_stdio.cpp ├── file_win32.cpp ├── header_limits.cpp ├── message_base.cpp ├── message_view_base.cpp ├── method.cpp ├── parser.cpp ├── request.cpp ├── request_base.cpp ├── request_parser.cpp ├── response.cpp ├── response_base.cpp ├── response_parser.cpp ├── rfc │ ├── combine_field_values.cpp │ ├── detail │ │ ├── rules.cpp │ │ └── rules.hpp │ ├── parameter.cpp │ ├── quoted_token_rule.cpp │ ├── transfer_encoding_rule.cpp │ ├── transfer_encoding_rule.hpp │ └── upgrade_rule.cpp ├── serializer.cpp ├── service │ ├── service.cpp │ └── zlib_service.cpp ├── sink.cpp ├── source.cpp ├── status.cpp └── version.cpp ├── src_brotli └── src_brotli.cpp ├── src_zlib └── service │ ├── deflate_service.cpp │ ├── inflate_service.cpp │ ├── stream_cast.hpp │ └── zlib_service.cpp └── test ├── CMakeLists.txt ├── Jamfile ├── cmake_test ├── CMakeLists.txt └── main.cpp ├── limits ├── CMakeLists.txt ├── Jamfile └── limits.cpp └── unit ├── CMakeLists.txt ├── Jamfile ├── context.cpp ├── error.cpp ├── field.cpp ├── fields.cpp ├── fields_base.cpp ├── fields_view.cpp ├── fields_view_base.cpp ├── file.cpp ├── file_base.cpp ├── file_body.cpp ├── file_posix.cpp ├── file_stdio.cpp ├── file_test.hpp ├── file_win32.cpp ├── header_limits.cpp ├── http_proto.cpp ├── message_base.cpp ├── message_view_base.cpp ├── metadata.cpp ├── method.cpp ├── natvis.cpp ├── parser.cpp ├── request.cpp ├── request_parser.cpp ├── request_view.cpp ├── response.cpp ├── response_parser.cpp ├── response_view.cpp ├── rfc ├── chunk_ext_rule.cpp ├── combine_field_values.cpp ├── detail │ └── rules.cpp ├── list_rule.cpp ├── parameter.cpp ├── quoted_token_rule.cpp ├── quoted_token_view.cpp ├── token_rule.cpp ├── transfer_encoding_rule.cpp └── upgrade_rule.cpp ├── sandbox.cpp ├── serializer.cpp ├── service ├── service.cpp ├── virtual_service.cpp └── zlib_service.cpp ├── sink.cpp ├── source.cpp ├── static_fields.cpp ├── static_request.cpp ├── static_response.cpp ├── status.cpp ├── string_body.cpp ├── test_helpers.cpp ├── test_helpers.hpp ├── test_rule.hpp ├── version.cpp └── zlib.cpp /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 - 2021 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | # 5 | # Sample codecov configuration file. Edit as required 6 | 7 | codecov: 8 | max_report_age: off 9 | require_ci_to_pass: yes 10 | notify: 11 | # Increase this if you have multiple coverage collection jobs 12 | after_n_builds: 1 13 | wait_for_ci: yes 14 | 15 | # Change how pull request comments look 16 | comment: 17 | layout: "reach,diff,flags,files,footer" 18 | 19 | # Ignore specific files or folders. Glob patterns are supported. 20 | # See https://docs.codecov.com/docs/ignoring-paths 21 | ignore: 22 | - extra/* 23 | - extra/**/* 24 | - test/* 25 | - test/**/* 26 | -------------------------------------------------------------------------------- /.drone.star: -------------------------------------------------------------------------------- 1 | # Use, modification, and distribution are 2 | # subject to the Boost Software License, Version 1.0. (See accompanying 3 | # file LICENSE.txt) 4 | # 5 | # Copyright Rene Rivera 2020. 6 | # Copyright Alan de Freitas 2022. 7 | 8 | # For Drone CI we use the Starlark scripting language to reduce duplication. 9 | # As the yaml syntax for Drone CI is rather limited. 10 | # 11 | # 12 | 13 | def main(ctx): 14 | return generate( 15 | # Compilers 16 | [ 17 | 'gcc >=5.0', 18 | 'clang >=3.8', 19 | 'msvc >=14.1', 20 | 'arm64-gcc latest', 21 | 's390x-gcc latest', 22 | # 'freebsd-gcc latest', 23 | 'apple-clang *', 24 | 'arm64-clang latest', 25 | 's390x-clang latest', 26 | # 'x86-msvc latest' 27 | ], 28 | # Standards 29 | '>=11', 30 | packages=['zlib1g', 'zlib1g-dev']) 31 | 32 | # from https://github.com/cppalliance/ci-automation 33 | load("@ci_automation//ci/drone/:functions.star", "linux_cxx", "windows_cxx", "osx_cxx", "freebsd_cxx", "generate") 34 | -------------------------------------------------------------------------------- /.drone/drone.bat: -------------------------------------------------------------------------------- 1 | 2 | @ECHO ON 3 | setlocal enabledelayedexpansion 4 | 5 | set TRAVIS_OS_NAME=windows 6 | 7 | IF "!DRONE_BRANCH!" == "" ( 8 | for /F %%i in ("!GITHUB_REF!") do @set TRAVIS_BRANCH=%%~nxi 9 | ) else ( 10 | SET TRAVIS_BRANCH=!DRONE_BRANCH! 11 | ) 12 | 13 | if "%DRONE_JOB_BUILDTYPE%" == "boost" ( 14 | 15 | echo "Running boost job" 16 | echo '==================================> INSTALL' 17 | REM there seems to be some problem with b2 bootstrap on Windows 18 | REM when CXX env variable is set 19 | SET "CXX=" 20 | 21 | git clone https://github.com/boostorg/boost-ci.git boost-ci-cloned --depth 1 22 | cp -prf boost-ci-cloned/ci . 23 | rm -rf boost-ci-cloned 24 | REM source ci/travis/install.sh 25 | REM The contents of install.sh below: 26 | 27 | for /F %%i in ("%DRONE_REPO%") do @set SELF=%%~nxi 28 | SET BOOST_CI_TARGET_BRANCH=!TRAVIS_BRANCH! 29 | SET BOOST_CI_SRC_FOLDER=%cd% 30 | if "%BOOST_BRANCH%" == "" ( 31 | SET BOOST_BRANCH=develop 32 | if "%BOOST_CI_TARGET_BRANCH%" == "master" set BOOST_BRANCH=master 33 | ) 34 | 35 | call ci\common_install.bat 36 | 37 | echo '==================================> ZLIB' 38 | git clone --branch v1.2.13 https://github.com/madler/zlib.git !BOOST_ROOT!\zlib-src --depth 1 39 | set ZLIB_SOURCE=!BOOST_ROOT!\zlib-src 40 | 41 | echo using zlib : : : ^off ^; >> !BOOST_ROOT!\project-config.jam 42 | 43 | REM Customizations 44 | cd 45 | pushd !BOOST_ROOT!\libs 46 | git clone https://github.com/CPPAlliance/buffers -b !BOOST_BRANCH! 47 | popd 48 | 49 | echo '==================================> COMPILE' 50 | 51 | REM set B2_TARGETS=libs/!SELF!/test libs/!SELF!/example 52 | set B2_TARGETS=libs/!SELF!/test 53 | call !BOOST_ROOT!\libs\!SELF!\ci\build.bat 54 | 55 | ) 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /bin64 3 | /_build* 4 | temp 5 | 6 | # Emacs 7 | *# 8 | 9 | # Vim 10 | *~ 11 | 12 | # Visual Studio 13 | /.vs 14 | /out 15 | 16 | # Visual Studio Code 17 | /.vscode 18 | 19 | # clangd 20 | /.cache 21 | /.clangd 22 | /compile_commands.json 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /build/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/vinniefalco/http_proto 8 | # 9 | 10 | import ac ; 11 | import ../../config/checks/config : requires ; 12 | 13 | using zlib ; 14 | 15 | constant c11-requires : 16 | [ requires 17 | cxx11_constexpr 18 | cxx11_decltype 19 | cxx11_hdr_tuple 20 | cxx11_template_aliases 21 | cxx11_variadic_templates 22 | ] 23 | ; 24 | 25 | path-constant HTTP_PROTO_ROOT : .. ; 26 | 27 | project boost/http_proto 28 | : requirements 29 | $(c11-requires) 30 | shared:BOOST_HTTP_PROTO_DYN_LINK=1 31 | static:BOOST_HTTP_PROTO_STATIC_LINK=1 32 | : usage-requirements 33 | shared:BOOST_HTTP_PROTO_DYN_LINK=1 34 | static:BOOST_HTTP_PROTO_STATIC_LINK=1 35 | : source-location $(HTTP_PROTO_ROOT) 36 | ; 37 | 38 | alias http_proto_sources : [ glob-tree-ex ./src : *.cpp ] ; 39 | 40 | explicit http_proto_sources ; 41 | 42 | lib boost_http_proto 43 | : http_proto_sources 44 | : requirements 45 | /boost//buffers 46 | /boost//url 47 | ../ 48 | BOOST_HTTP_PROTO_SOURCE 49 | : usage-requirements 50 | /boost//buffers 51 | /boost//url 52 | ; 53 | 54 | alias http_proto_zlib_sources : [ glob-tree-ex ./src_zlib : *.cpp ] ; 55 | 56 | explicit http_proto_zlib_sources ; 57 | 58 | lib boost_http_proto_zlib 59 | : http_proto_zlib_sources 60 | : requirements 61 | /boost/http_proto//boost_http_proto 62 | [ ac.check-library /zlib//zlib : /zlib//zlib : no ] 63 | ../ 64 | BOOST_HTTP_PROTO_ZLIB_SOURCE 65 | : usage-requirements 66 | /zlib//zlib 67 | BOOST_HTTP_PROTO_HAS_ZLIB 68 | ; 69 | 70 | boost-install boost_http_proto boost_http_proto_zlib ; 71 | -------------------------------------------------------------------------------- /cmake/toolchains/clang.cmake: -------------------------------------------------------------------------------- 1 | # Include gcc options. 2 | include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake) 3 | 4 | # Compiler options. 5 | add_compile_options(-Wrange-loop-analysis) 6 | -------------------------------------------------------------------------------- /cmake/toolchains/common.cmake: -------------------------------------------------------------------------------- 1 | # C++ standard. 2 | set(CMAKE_CXX_EXTENSIONS OFF CACHE STRING "") 3 | 4 | # Static library linkage. 5 | set(BUILD_SHARED_LIBS OFF CACHE STRING "") 6 | add_definitions(-DBOOST_ALL_STATIC_LINK=1) 7 | 8 | # Interprocedural optimization. 9 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON CACHE STRING "") 10 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON CACHE STRING "") 11 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON CACHE STRING "") 12 | 13 | # Compiler definitions. 14 | if(WIN32) 15 | add_definitions(-D_WIN32_WINNT=0x0601 -D_CRT_SECURE_NO_WARNINGS) 16 | endif() 17 | 18 | # Project options. 19 | set(BOOST_JSON_BUILD_BENCHMARKS ON CACHE STRING "") 20 | 21 | # Detect Boost tree. 22 | if(NOT DEFINED BOOST_JSON_IN_BOOST_TREE AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../../Jamroot") 23 | set(BOOST_JSON_IN_BOOST_TREE ON CACHE STRING "") 24 | endif() 25 | -------------------------------------------------------------------------------- /cmake/toolchains/gcc.cmake: -------------------------------------------------------------------------------- 1 | # Include common options. 2 | include(${CMAKE_CURRENT_LIST_DIR}/common.cmake) 3 | 4 | # Compiler options. 5 | add_compile_options(-Wall -Wextra -Wpedantic) 6 | -------------------------------------------------------------------------------- /cmake/toolchains/msvc.cmake: -------------------------------------------------------------------------------- 1 | # Include common options. 2 | include(${CMAKE_CURRENT_LIST_DIR}/common.cmake) 3 | 4 | # Static runtime linkage. 5 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "") 6 | 7 | # Compiler options. 8 | add_compile_options( 9 | /permissive- # strict C++ 10 | /W4 # enable all warnings 11 | /MP # multi-processor compilation 12 | ) 13 | if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32") # 32-bit 14 | add_compile_options( 15 | /arch:SSE2 16 | ) 17 | endif() 18 | 19 | # Linker options. 20 | add_link_options( 21 | ) 22 | 23 | # Disable logos. 24 | foreach(lang C CXX ASM_MASM RC) 25 | set(CMAKE_${lang}_FLAGS_INIT "/nologo") 26 | endforeach() 27 | foreach(type EXE SHARED MODULE) 28 | set(CMAKE_${type}_LINKER_FLAGS_INIT "/nologo") 29 | endforeach() 30 | 31 | # Silence Visual Studio CMake integration warnings. 32 | set(SILENCE_VS_DEFINITIONS ${CMAKE_TOOLCHAIN_FILE} ${CMAKE_C_COMPILER}) 33 | set(SILENCE_VS_DEFINITIONS) 34 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | -------------------------------------------------------------------------------- /doc/antora.yml: -------------------------------------------------------------------------------- 1 | name: http_proto 2 | version: ~ 3 | title: Boost.HTTP.Proto 4 | start_page: index.adoc 5 | asciidoc: 6 | attributes: 7 | source-language: asciidoc@ 8 | table-caption: false 9 | nav: 10 | - modules/ROOT/nav.adoc 11 | ext: 12 | cpp-reference: 13 | config: doc/mrdocs.yml 14 | -------------------------------------------------------------------------------- /doc/build_antora.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | if "%~1"=="" ( 5 | echo No playbook supplied, using default playbook 6 | set "PLAYBOOK=local-playbook.yml" 7 | ) else ( 8 | set "PLAYBOOK=%~1" 9 | ) 10 | 11 | echo Building documentation with Antora... 12 | echo Installing npm dependencies... 13 | call npm ci 14 | 15 | echo Building docs in custom dir... 16 | call "C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 17 | call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 18 | set "PATH=%PATH%;C:\Program Files\7-Zip" 19 | set "PATH=%PATH%;%CD%\node_modules\.bin" 20 | call npx antora --clean --fetch "%PLAYBOOK%" 21 | echo Done 22 | -------------------------------------------------------------------------------- /doc/build_antora.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/boostorg/url 8 | # 9 | 10 | set -xe 11 | 12 | if [ $# -eq 0 ] 13 | then 14 | echo "No playbook supplied, using default playbook" 15 | PLAYBOOK="local-playbook.yml" 16 | else 17 | PLAYBOOK=$1 18 | fi 19 | 20 | echo "Building documentation with Antora..." 21 | echo "Installing npm dependencies..." 22 | npm ci 23 | 24 | echo "Building docs in custom dir..." 25 | PATH="$(pwd)/node_modules/.bin:${PATH}" 26 | export PATH 27 | npx antora --clean --fetch "$PLAYBOOK" 28 | echo "Done" 29 | 30 | -------------------------------------------------------------------------------- /doc/images/repo-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppalliance/http_proto/5427839ba0be23a221eacabce7e1cea74e0b6ab0/doc/images/repo-logo.png -------------------------------------------------------------------------------- /doc/local-playbook.yml: -------------------------------------------------------------------------------- 1 | site: 2 | title: Boost.Http.Proto 3 | url: https://antora.cppalliance.org/develop/lib/doc 4 | start_page: http_proto::index.adoc 5 | robots: allow 6 | keys: 7 | repo_url: 'https://github.com/cppalliance/http_proto' 8 | 9 | content: 10 | sources: 11 | - url: .. 12 | start_path: doc 13 | edit_url: 'https://github.com/cppalliance/http_proto/edit/{refname}/{path}' 14 | 15 | ui: 16 | bundle: 17 | url: https://github.com/boostorg/website-v2-docs/releases/download/ui-master/ui-bundle.zip 18 | snapshot: true 19 | 20 | antora: 21 | extensions: 22 | - require: '@antora/lunr-extension' # https://gitlab.com/antora/antora-lunr-extension 23 | index_latest_only: true 24 | - require: '@cppalliance/antora-cpp-tagfiles-extension' 25 | cpp-tagfiles: 26 | using-namespaces: 27 | - 'boost::' 28 | - require: '@cppalliance/antora-cpp-reference-extension' 29 | dependencies: 30 | - name: 'boost' 31 | repo: 'https://github.com/boostorg/boost.git' 32 | tag: 'develop' 33 | variable: 'BOOST_SRC_DIR' 34 | system-env: 'BOOST_SRC_DIR' 35 | 36 | asciidoc: 37 | attributes: 38 | # Enable pagination 39 | page-pagination: '' 40 | extensions: 41 | - '@cppalliance/asciidoctor-boost-links' 42 | - '@asciidoctor/tabs' 43 | -------------------------------------------------------------------------------- /doc/modules/ROOT/images/ClassHierarchy.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppalliance/http_proto/5427839ba0be23a221eacabce7e1cea74e0b6ab0/doc/modules/ROOT/images/ClassHierarchy.odg -------------------------------------------------------------------------------- /doc/modules/ROOT/images/doc-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppalliance/http_proto/5427839ba0be23a221eacabce7e1cea74e0b6ab0/doc/modules/ROOT/images/doc-logo.png -------------------------------------------------------------------------------- /doc/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:sans_io_philosophy.adoc[] 2 | 3 | * xref:http_protocol_basics.adoc[] 4 | 5 | * xref:header_containers.adoc[] 6 | 7 | * xref:message_bodies.adoc[] 8 | 9 | * Serializing 10 | 11 | * Parsing 12 | 13 | * xref:Message.adoc[] 14 | 15 | * Design Requirements 16 | ** xref:design_requirements/serializer.adoc[Serializer] 17 | ** xref:design_requirements/parser.adoc[Parser] 18 | 19 | * Design Choices 20 | 21 | * xref:reference:boost/http_proto.adoc[Reference] 22 | -------------------------------------------------------------------------------- /doc/modules/ROOT/pages/Message.adoc: -------------------------------------------------------------------------------- 1 | = Message 2 | 3 | image::ClassHierarchy.svg[] 4 | -------------------------------------------------------------------------------- /doc/modules/ROOT/pages/header_containers.adoc: -------------------------------------------------------------------------------- 1 | = Header Containers 2 | -------------------------------------------------------------------------------- /doc/modules/ROOT/pages/http_protocol_basics.adoc: -------------------------------------------------------------------------------- 1 | = HTTP Protocol Basics 2 | -------------------------------------------------------------------------------- /doc/modules/ROOT/pages/message_bodies.adoc: -------------------------------------------------------------------------------- 1 | = Message Bodies 2 | -------------------------------------------------------------------------------- /doc/mrdocs.yml: -------------------------------------------------------------------------------- 1 | # Input 2 | source-root: .. 3 | # Directories that contain documented source files 4 | input: 5 | - ../include 6 | # Patterns to filter out the source-files in the directories 7 | file-patterns: 8 | - '*.hpp' 9 | 10 | # Filters 11 | include-symbols: 12 | - 'boost::http_proto::**' 13 | implementation-defined: 14 | - 'boost::http_proto::detail' 15 | - 'boost::http_proto::*::detail' 16 | inaccessible-members: never 17 | inaccessible-bases: never 18 | 19 | # Generator 20 | generate: adoc 21 | base-url: https://www.github.com/cppalliance/http_proto/blob/develop/include/ 22 | 23 | # Style 24 | verbose: true 25 | multipage: true 26 | use-system-libc: true 27 | 28 | cmake: '-DCMAKE_CXX_STANDARD=20 -DBOOST_HTTP_PROTO_BUILD_TESTS=OFF -DBOOST_HTTP_PROTO_BUILD_EXAMPLES=OFF' 29 | -------------------------------------------------------------------------------- /doc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@antora/cli": "3.1.3", 4 | "@antora/site-generator": "3.1.3", 5 | "antora": "3.1.3" 6 | }, 7 | "dependencies": { 8 | "@cppalliance/antora-cpp-reference-extension": "^0.0.6", 9 | "@cppalliance/antora-cpp-tagfiles-extension": "^0.0.4", 10 | "@cppalliance/asciidoctor-boost-links": "^0.0.2", 11 | "@antora/expand-path-helper": "^2.0.0", 12 | "@antora/lunr-extension": "^1.0.0-alpha.8", 13 | "@asciidoctor/tabs": "^1.0.0-beta.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /include/boost/http_proto.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_HPP 11 | #define BOOST_HTTP_PROTO_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #include 57 | #include 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /include/boost/http_proto/deflate.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DEFLATE_HPP 11 | #define BOOST_HTTP_PROTO_DEFLATE_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | #ifdef BOOST_HTTP_PROTO_DOCS 19 | 20 | /** Constant for the deflate decoder 21 | 22 | This value may be passed upon construction 23 | of a @ref serializer or @ref parser. 24 | */ 25 | constexpr __implementation_defined__ deflate_decoder; 26 | 27 | /** Constant for the deflate encoder 28 | 29 | This value may be passed upon construction 30 | of a @ref serializer or @ref parser. 31 | */ 32 | constexpr __implementation_defined__ deflate_encoder; 33 | 34 | #else 35 | 36 | struct deflate_decoder_t {}; 37 | struct deflate_encoder_t {}; 38 | constexpr deflate_decoder_t deflate_decoder{}; 39 | constexpr deflate_encoder_t deflate_encoder{}; 40 | 41 | #endif 42 | 43 | } // http_proto 44 | } // boost 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/align_up.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 Christian Mazakas 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/CPPAlliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | namespace detail { 18 | 19 | constexpr 20 | inline 21 | std::size_t 22 | align_up(std::size_t s, std::size_t A) 23 | { 24 | return A * ( 25 | (s + A - 1) / A); 26 | } 27 | 28 | } // detail 29 | } // http_proto 30 | } // boost 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/array_of_buffers.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_ARRAY_OF_BUFFERS_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_ARRAY_OF_BUFFERS_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | namespace detail { 19 | 20 | template 21 | class array_of_buffers 22 | { 23 | public: 24 | using value_type = typename 25 | std::conditional::type; 28 | using iterator = value_type*; 29 | using const_iterator = iterator; 30 | 31 | array_of_buffers() = default; 32 | array_of_buffers( 33 | array_of_buffers const&) = default; 34 | array_of_buffers& operator=( 35 | array_of_buffers const&) = default; 36 | 37 | array_of_buffers( 38 | value_type* p, 39 | std::size_t n) noexcept; 40 | 41 | bool empty() const noexcept; 42 | value_type* data() const noexcept; 43 | std::size_t size() const noexcept; 44 | std::size_t capacity() const noexcept; 45 | value_type& operator[](std::size_t) const noexcept; 46 | void consume(std::size_t n); 47 | void reset(std::size_t n); 48 | 49 | iterator begin() const noexcept; 50 | iterator end() const noexcept; 51 | 52 | private: 53 | value_type* o_ = nullptr; 54 | value_type* p_ = nullptr; 55 | std::size_t n_ = 0; 56 | std::size_t c_ = 0; 57 | }; 58 | 59 | using array_of_const_buffers = 60 | array_of_buffers; 61 | 62 | using array_of_mutable_buffers = 63 | array_of_buffers; 64 | 65 | } // detail 66 | } // http_proto 67 | } // boost 68 | 69 | #include 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/except.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_EXCEPT_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_EXCEPT_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | namespace detail { 19 | 20 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_bad_alloc( 21 | source_location const& loc = BOOST_CURRENT_LOCATION); 22 | 23 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_invalid_argument( 24 | source_location const& loc = BOOST_CURRENT_LOCATION); 25 | 26 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_invalid_argument( 27 | char const* what, 28 | source_location const& loc = BOOST_CURRENT_LOCATION); 29 | 30 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_length_error( 31 | source_location const& loc = BOOST_CURRENT_LOCATION); 32 | 33 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_length_error( 34 | char const* what, 35 | source_location const& loc = BOOST_CURRENT_LOCATION); 36 | 37 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_logic_error( 38 | source_location const& loc = BOOST_CURRENT_LOCATION); 39 | 40 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_out_of_range( 41 | source_location const& loc = BOOST_CURRENT_LOCATION); 42 | 43 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_runtime_error( 44 | char const* what, 45 | source_location const& loc = BOOST_CURRENT_LOCATION); 46 | 47 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_system_error( 48 | system::error_code const& ec, 49 | source_location const& loc = BOOST_CURRENT_LOCATION); 50 | 51 | BOOST_HTTP_PROTO_DECL void BOOST_NORETURN throw_system_error( 52 | error e, 53 | source_location const& loc = BOOST_CURRENT_LOCATION); 54 | 55 | } // detail 56 | } // http_proto 57 | } // boost 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/impl/array_of_buffers.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | namespace detail { 20 | 21 | template 22 | array_of_buffers:: 23 | array_of_buffers( 24 | value_type* p, 25 | std::size_t n) noexcept 26 | : o_(p) 27 | , p_(p) 28 | , n_(n) 29 | , c_(n) 30 | { 31 | } 32 | 33 | template 34 | bool 35 | array_of_buffers:: 36 | empty() const noexcept 37 | { 38 | return n_ == 0; 39 | } 40 | 41 | template 42 | auto 43 | array_of_buffers:: 44 | data() const noexcept -> 45 | value_type* 46 | { 47 | return p_; 48 | } 49 | 50 | template 51 | std::size_t 52 | array_of_buffers:: 53 | size() const noexcept 54 | { 55 | return n_; 56 | } 57 | 58 | template 59 | std::size_t 60 | array_of_buffers:: 61 | capacity() const noexcept 62 | { 63 | return c_; 64 | } 65 | 66 | template 67 | auto 68 | array_of_buffers:: 69 | begin() const noexcept -> 70 | iterator 71 | { 72 | return p_; 73 | } 74 | 75 | template 76 | auto 77 | array_of_buffers:: 78 | end() const noexcept -> 79 | iterator 80 | { 81 | return p_ + n_; 82 | } 83 | 84 | template 85 | auto 86 | array_of_buffers:: 87 | operator[]( 88 | std::size_t i) const noexcept -> 89 | value_type& 90 | { 91 | BOOST_ASSERT(i < n_); 92 | return p_[i]; 93 | } 94 | 95 | template 96 | void 97 | array_of_buffers:: 98 | consume(std::size_t n) 99 | { 100 | while(n_ > 0) 101 | { 102 | if(n < p_->size()) 103 | { 104 | *p_ = buffers::sans_prefix(*p_, n); 105 | return; 106 | } 107 | n -= p_->size(); 108 | ++p_; 109 | --n_; 110 | if(n == 0) 111 | return; 112 | } 113 | 114 | // n exceeded available size 115 | if(n > 0) 116 | detail::throw_logic_error(); 117 | } 118 | 119 | template 120 | void 121 | array_of_buffers:: 122 | reset(std::size_t n) 123 | { 124 | BOOST_ASSERT(n <= capacity()); 125 | p_ = o_; 126 | n_ = n; 127 | for( auto p = p_; p < p_ + n; ++p ) 128 | *p = value_type(); 129 | } 130 | 131 | } // detail 132 | } // http_proto 133 | } // boost 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/sv.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_SV_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_SV_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | namespace detail { 18 | 19 | // Pulling in the UDL directly breaks in some places on MSVC, 20 | // so introduce a namespace for this purprose. 21 | namespace string_literals { 22 | inline 23 | core::string_view 24 | operator""_sv( 25 | char const* p, 26 | std::size_t n) noexcept 27 | { 28 | return core::string_view(p, n); 29 | } 30 | } // string_literals 31 | 32 | } // detail 33 | } // http_proto 34 | } // boost 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/boost/http_proto/detail/type_traits.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_TYPE_TRAITS_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_TYPE_TRAITS_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | namespace detail { 19 | 20 | template 21 | struct remove_cvref 22 | { 23 | using type = 24 | typename std::remove_cv< 25 | typename std::remove_reference::type>::type; 26 | }; 27 | 28 | template 29 | using remove_cvref_t = typename remove_cvref::type; 30 | 31 | template 32 | struct is_reference_wrapper_impl 33 | : std::false_type 34 | { 35 | }; 36 | 37 | template 38 | struct is_reference_wrapper_impl< 39 | std::reference_wrapper> 40 | : std::true_type 41 | { 42 | }; 43 | 44 | #if !defined(BOOST_NO_CV_SPECIALIZATIONS) 45 | 46 | template 47 | struct is_reference_wrapper_impl< 48 | std::reference_wrapper const> 49 | : std::true_type 50 | { 51 | }; 52 | 53 | template 54 | struct is_reference_wrapper_impl< 55 | std::reference_wrapper volatile> 56 | : std::true_type 57 | { 58 | }; 59 | 60 | template 61 | struct is_reference_wrapper_impl< 62 | std::reference_wrapper const volatile> 63 | : std::true_type 64 | { 65 | }; 66 | 67 | #endif 68 | 69 | template 70 | using is_reference_wrapper = 71 | is_reference_wrapper_impl>; 72 | 73 | } // detail 74 | } // http_proto 75 | } // boost 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/boost/http_proto/fields_view.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_FIELDS_VIEW_HPP 11 | #define BOOST_HTTP_PROTO_FIELDS_VIEW_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** A read-only, forward range of HTTP fields 21 | */ 22 | class fields_view 23 | : public fields_view_base 24 | { 25 | friend class fields; 26 | template 27 | friend class static_fields; 28 | 29 | #ifndef BOOST_HTTP_PROTO_DOCS 30 | protected: 31 | #endif 32 | 33 | explicit 34 | fields_view( 35 | detail::header const* ph) noexcept 36 | : fields_view_base(ph) 37 | { 38 | BOOST_ASSERT(ph_->kind == 39 | detail::kind::fields); 40 | } 41 | 42 | public: 43 | /** Constructor 44 | 45 | Default constructed field views 46 | have a zero size. 47 | */ 48 | fields_view() noexcept 49 | : fields_view_base( 50 | detail::header::get_default( 51 | detail::kind::fields)) 52 | { 53 | } 54 | 55 | /** Constructor 56 | */ 57 | fields_view( 58 | fields_view const&) noexcept = default; 59 | 60 | /** Assignment 61 | */ 62 | fields_view& 63 | operator=( 64 | fields_view const&) noexcept = default; 65 | 66 | //-------------------------------------------- 67 | 68 | /** Swap this with another instance 69 | */ 70 | void 71 | swap(fields_view& other) noexcept 72 | { 73 | auto ph = ph_; 74 | ph_ = other.ph_; 75 | other.ph_ = ph; 76 | } 77 | 78 | /** Swap two instances 79 | */ 80 | friend 81 | void 82 | swap( 83 | fields_view& t0, 84 | fields_view& t1) noexcept 85 | { 86 | t0.swap(t1); 87 | } 88 | }; 89 | 90 | } // http_proto 91 | } // boost 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /include/boost/http_proto/file.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_FILE_HPP 11 | #define BOOST_HTTP_PROTO_FILE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | /** An implementation of File. 23 | 24 | This alias is set to the best available implementation 25 | of File given the platform and build settings. 26 | */ 27 | #if BOOST_HTTP_PROTO_DOCS 28 | struct file : file_stdio 29 | { 30 | }; 31 | #else 32 | #if BOOST_HTTP_PROTO_USE_WIN32_FILE 33 | using file = file_win32; 34 | #elif BOOST_HTTP_PROTO_USE_POSIX_FILE 35 | using file = file_posix; 36 | #else 37 | using file = file_stdio; 38 | #endif 39 | #endif 40 | 41 | } // http_proto 42 | } // boost 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/http_proto/file_body.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_FILE_BODY_HPP 11 | #define BOOST_HTTP_PROTO_FILE_BODY_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | class BOOST_SYMBOL_VISIBLE 23 | file_body 24 | : public source, sink 25 | { 26 | file f_; 27 | std::uint64_t n_; 28 | 29 | public: 30 | file_body() = delete; 31 | file_body( 32 | file_body const&) = delete; 33 | 34 | BOOST_HTTP_PROTO_DECL 35 | file_body( 36 | file_body&&) noexcept; 37 | 38 | BOOST_HTTP_PROTO_DECL 39 | ~file_body(); 40 | 41 | BOOST_HTTP_PROTO_DECL 42 | explicit 43 | file_body( 44 | file&& f, 45 | std::uint64_t size = 46 | std::uint64_t(-1)) noexcept; 47 | 48 | BOOST_HTTP_PROTO_DECL 49 | source::results 50 | on_read( 51 | buffers::mutable_buffer b) override; 52 | 53 | BOOST_HTTP_PROTO_DECL 54 | sink::results 55 | on_write( 56 | buffers::const_buffer b, bool more) override; 57 | }; 58 | 59 | } // http_proto 60 | } // boost 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/boost/http_proto/http_proto.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | [{count}] 6 | {cbuf,[prefix-2]s} [{count}] 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | buf+prefix+ft[-1-i].np, 15 | [ft[-1-i].vp + ft[-1-i].vn - ft[-1-i].np]s 16 | 17 | i++ 18 | 19 | 20 | 21 | 22 | this,! 23 | 24 | 25 | {this->req} 26 | this,! 27 | 28 | 29 | {this->res} 30 | this,! 31 | 32 | 33 | 34 | 35 | 36 | { *ph_ } 37 | 38 | *ph_ 39 | 40 | 41 | 42 | 43 | { h_ } 44 | 45 | h_ 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /include/boost/http_proto/impl/context.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_IMPL_CONTEXT_HPP 11 | #define BOOST_HTTP_PROTO_IMPL_CONTEXT_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | namespace detail { 23 | 24 | template 25 | using get_key_impl = 26 | typename T::key_type; 27 | 28 | template 29 | using get_key_type = 30 | mp11::mp_eval_or; 31 | 32 | } // detail 33 | 34 | //------------------------------------------------ 35 | 36 | template 37 | T& 38 | context:: 39 | make_service( 40 | Args&&... args) 41 | { 42 | static_assert( 43 | std::is_base_of::value, 44 | "Type requirements not met."); 45 | 46 | auto const ti = detail::get_type_index< 47 | detail::get_key_type>(); 48 | auto const ps = find_service_impl(ti); 49 | if(ps) 50 | detail::throw_invalid_argument( 51 | "service exists"); 52 | return detail::downcast( 53 | make_service_impl(ti, 54 | std::unique_ptr( 55 | new T(*this, std::forward< 56 | Args>(args)...)))); 57 | } 58 | 59 | template 60 | T* 61 | context:: 62 | find_service() const noexcept 63 | { 64 | auto const ti = detail::get_type_index< 65 | detail::get_key_type>(); 66 | auto const ps = find_service_impl(ti); 67 | if(! ps) 68 | return nullptr; 69 | return detail::downcast(ps); 70 | } 71 | 72 | template 73 | bool 74 | context:: 75 | has_service() const noexcept 76 | { 77 | return find_service() != nullptr; 78 | } 79 | 80 | template 81 | T& 82 | context:: 83 | get_service() const 84 | { 85 | auto ps = find_service(); 86 | if(! ps) 87 | detail::throw_invalid_argument( 88 | "service not found"); 89 | return *ps; 90 | } 91 | 92 | } // http_proto 93 | } // boost 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /include/boost/http_proto/impl/error.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_IMPL_ERROR_HPP 11 | #define BOOST_HTTP_PROTO_IMPL_ERROR_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | 20 | namespace system { 21 | 22 | template<> 23 | struct is_error_code_enum< 24 | ::boost::http_proto::error> 25 | { 26 | static bool const value = true; 27 | }; 28 | 29 | template<> 30 | struct is_error_condition_enum< 31 | ::boost::http_proto::condition> 32 | { 33 | static bool const value = true; 34 | }; 35 | 36 | } // system 37 | 38 | //----------------------------------------------- 39 | 40 | namespace http_proto { 41 | 42 | namespace detail { 43 | 44 | struct BOOST_SYMBOL_VISIBLE 45 | error_cat_type 46 | : system::error_category 47 | { 48 | BOOST_HTTP_PROTO_DECL const char* name( 49 | ) const noexcept override; 50 | BOOST_HTTP_PROTO_DECL std::string message( 51 | int) const override; 52 | BOOST_HTTP_PROTO_DECL char const* message( 53 | int, char*, std::size_t 54 | ) const noexcept override; 55 | BOOST_SYSTEM_CONSTEXPR error_cat_type() 56 | : error_category(0x3663257e7585fbfd) 57 | { 58 | } 59 | }; 60 | 61 | struct BOOST_SYMBOL_VISIBLE 62 | condition_cat_type 63 | : system::error_category 64 | { 65 | BOOST_HTTP_PROTO_DECL const char* name( 66 | ) const noexcept override; 67 | BOOST_HTTP_PROTO_DECL std::string message( 68 | int) const override; 69 | BOOST_HTTP_PROTO_DECL char const* message( 70 | int, char*, std::size_t 71 | ) const noexcept override; 72 | BOOST_HTTP_PROTO_DECL bool equivalent( 73 | system::error_code const&, int 74 | ) const noexcept override; 75 | BOOST_SYSTEM_CONSTEXPR condition_cat_type() 76 | : error_category(0xa36e10f16c666a7) 77 | { 78 | } 79 | }; 80 | 81 | BOOST_HTTP_PROTO_DECL extern 82 | error_cat_type error_cat; 83 | BOOST_HTTP_PROTO_DECL extern 84 | condition_cat_type condition_cat; 85 | 86 | } // detail 87 | 88 | inline 89 | BOOST_SYSTEM_CONSTEXPR 90 | system::error_code 91 | make_error_code( 92 | error ev) noexcept 93 | { 94 | return system::error_code{ 95 | static_cast::type>(ev), 97 | detail::error_cat}; 98 | } 99 | 100 | inline 101 | BOOST_SYSTEM_CONSTEXPR 102 | system::error_condition 103 | make_error_condition( 104 | condition c) noexcept 105 | { 106 | return system::error_condition{ 107 | static_cast::type>(c), 109 | detail::condition_cat}; 110 | } 111 | 112 | } // http_proto 113 | } // boost 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /include/boost/http_proto/impl/parser.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // we need a pragma once for the circular includes required 11 | // clangd's intellisense 12 | #pragma once 13 | 14 | #ifndef BOOST_HTTP_PROTO_IMPL_PARSER_HPP 15 | #define BOOST_HTTP_PROTO_IMPL_PARSER_HPP 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace http_proto { 23 | 24 | //------------------------------------------------ 25 | 26 | template 27 | typename std::enable_if< 28 | ! detail::is_reference_wrapper< 29 | ElasticBuffer>::value && 30 | ! is_sink::value>::type 31 | parser:: 32 | set_body( 33 | ElasticBuffer&& eb) 34 | { 35 | // If this goes off it means you are trying 36 | // to pass by lvalue reference. Use std::ref 37 | // instead. 38 | static_assert( 39 | ! std::is_reference::value, 40 | "Use std::ref instead of pass-by-reference"); 41 | 42 | // Check ElasticBuffer type requirements 43 | static_assert( 44 | buffers::is_dynamic_buffer::value, 45 | "Type requirements not met."); 46 | 47 | // body must not be set already 48 | if(how_ != how::in_place) 49 | detail::throw_logic_error(); 50 | 51 | // headers must be complete 52 | if(! got_header()) 53 | detail::throw_logic_error(); 54 | 55 | auto& dyn = ws_.emplace< 56 | buffers::any_dynamic_buffer_impl::type, 58 | buffers_N>>(std::forward(eb)); 59 | eb_ = &dyn; 60 | how_ = how::elastic; 61 | on_set_body(); 62 | } 63 | 64 | template 65 | void 66 | parser:: 67 | set_body( 68 | std::reference_wrapper eb) 69 | { 70 | // Check ElasticBuffer type requirements 71 | static_assert( 72 | buffers::is_dynamic_buffer::value, 73 | "Type requirements not met."); 74 | 75 | // body must not be set already 76 | if(how_ != how::in_place) 77 | detail::throw_logic_error(); 78 | 79 | // headers must be complete 80 | if(! got_header()) 81 | detail::throw_logic_error(); 82 | 83 | auto& dyn = ws_.emplace< 84 | buffers::any_dynamic_buffer_impl::type&, 86 | buffers_N>>(eb); 87 | eb_ = &dyn; 88 | how_ = how::elastic; 89 | on_set_body(); 90 | } 91 | 92 | //------------------------------------------------ 93 | 94 | template< 95 | class Sink, 96 | class... Args, 97 | class> 98 | Sink& 99 | parser:: 100 | set_body(Args&&... args) 101 | { 102 | // body must not be set already 103 | if(how_ != how::in_place) 104 | detail::throw_logic_error(); 105 | 106 | // headers must be complete 107 | if(! got_header()) 108 | detail::throw_logic_error(); 109 | 110 | auto& s = ws_.emplace( 111 | std::forward(args)...); 112 | sink_ = &s; 113 | how_ = how::sink; 114 | on_set_body(); 115 | return s; 116 | } 117 | 118 | } // http_proto 119 | } // boost 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /include/boost/http_proto/impl/sink.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_IMPL_SINK_HPP 11 | #define BOOST_HTTP_PROTO_IMPL_SINK_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | inline 22 | auto 23 | sink:: 24 | results:: 25 | operator+=( 26 | results const& rv) noexcept -> 27 | results& 28 | { 29 | BOOST_ASSERT(! ec.failed()); 30 | ec = rv.ec; 31 | bytes += rv.bytes; 32 | return *this; 33 | } 34 | 35 | //------------------------------------------------ 36 | 37 | template 38 | auto 39 | sink:: 40 | write_impl( 41 | T const& bs, 42 | bool more) -> 43 | results 44 | { 45 | results rv; 46 | constexpr int SmallArraySize = 16; 47 | buffers::const_buffer tmp[SmallArraySize]; 48 | auto const tmp_end = tmp + SmallArraySize; 49 | auto it = buffers::begin(bs); 50 | auto const end_ = buffers::end(bs); 51 | while(it != end_) 52 | { 53 | auto p = tmp; 54 | do 55 | { 56 | *p++ = *it++; 57 | } 58 | while( 59 | p != tmp_end && 60 | it != end_); 61 | rv += on_write( 62 | buffers::const_buffer_span( 63 | tmp, p - tmp), 64 | it != end_ || 65 | more); 66 | if(rv.ec.failed()) 67 | return rv; 68 | } 69 | return rv; 70 | } 71 | 72 | } // http_proto 73 | } // boost 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /include/boost/http_proto/impl/source.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/buffers 8 | // 9 | 10 | #ifndef BOOST_BUFFERS_IMPL_SOURCE_HPP 11 | #define BOOST_BUFFERS_IMPL_SOURCE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | inline 22 | auto 23 | source:: 24 | results:: 25 | operator+=( 26 | results const& rv) noexcept -> 27 | results& 28 | { 29 | BOOST_ASSERT(! ec.failed()); 30 | BOOST_ASSERT(! finished); 31 | ec = rv.ec; 32 | bytes += rv.bytes; 33 | finished = rv.finished; 34 | return *this; 35 | } 36 | 37 | //------------------------------------------------ 38 | 39 | template 40 | auto 41 | source:: 42 | read_impl( 43 | T const& bs) -> 44 | results 45 | { 46 | results rv; 47 | constexpr int SmallArraySize = 16; 48 | buffers::mutable_buffer tmp[SmallArraySize]; 49 | auto const tmp_end = 50 | tmp + SmallArraySize; 51 | auto it = buffers::begin(bs); 52 | auto const end_ = buffers::end(bs); 53 | while(it != end_) 54 | { 55 | auto p = tmp; 56 | do 57 | { 58 | *p++ = *it++; 59 | } 60 | while( 61 | p != tmp_end && 62 | it != end_); 63 | rv += on_read( 64 | buffers::mutable_buffer_span( 65 | tmp, p - tmp)); 66 | if(rv.ec.failed()) 67 | return rv; 68 | if(rv.finished) 69 | break; 70 | } 71 | return rv; 72 | } 73 | 74 | } // http_proto 75 | } // boost 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/boost/http_proto/message_view_base.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Christian Mazakas 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // Official repository: https://github.com/cppalliance/http_proto 9 | // 10 | 11 | #ifndef BOOST_HTTP_PROTO_MESSAGE_VIEW_BASE_HPP 12 | #define BOOST_HTTP_PROTO_MESSAGE_VIEW_BASE_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace http_proto { 23 | 24 | /** Provides message metadata for requests and responses 25 | */ 26 | class message_view_base 27 | : public virtual fields_view_base 28 | { 29 | friend class request_view; 30 | friend class response_view; 31 | friend class message_base; 32 | 33 | message_view_base() noexcept 34 | // VFALCO This ctor-init has to be 35 | // here even though it isn't called, 36 | // so nullptr doesn't matter. 37 | : fields_view_base(nullptr) 38 | { 39 | } 40 | 41 | explicit 42 | message_view_base( 43 | detail::header const* ph) noexcept 44 | : fields_view_base(ph) 45 | { 46 | } 47 | 48 | public: 49 | //-------------------------------------------- 50 | // 51 | // Metadata 52 | // 53 | //-------------------------------------------- 54 | 55 | /** Return the type of payload of this message 56 | */ 57 | auto 58 | payload() const noexcept -> 59 | http_proto::payload 60 | { 61 | return ph_->md.payload; 62 | } 63 | 64 | /** Return the payload size 65 | 66 | When @ref payload returns @ref payload::size, 67 | this function returns the number of octets 68 | in the actual message payload. 69 | */ 70 | std::uint64_t 71 | payload_size() const noexcept 72 | { 73 | BOOST_ASSERT( 74 | payload() == payload::size); 75 | return ph_->md.payload_size; 76 | } 77 | 78 | /** Return true if semantics indicate connection persistence 79 | */ 80 | bool 81 | keep_alive() const noexcept 82 | { 83 | return ph_->keep_alive(); 84 | } 85 | 86 | /** Return metadata about the message 87 | */ 88 | auto 89 | metadata() const noexcept -> 90 | http_proto::metadata const& 91 | { 92 | return ph_->md; 93 | } 94 | 95 | /** Return true if the message is using a chunked 96 | transfer encoding. 97 | */ 98 | bool 99 | chunked() const noexcept 100 | { 101 | return ph_->md.transfer_encoding.is_chunked; 102 | } 103 | }; 104 | 105 | } // http_proto 106 | } // boost 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /include/boost/http_proto/request_parser.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_REQUEST_PARSER_HPP 11 | #define BOOST_HTTP_PROTO_REQUEST_PARSER_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace http_proto { 23 | 24 | class request_parser 25 | : public parser 26 | { 27 | public: 28 | /** Configuration settings for parsing requests 29 | */ 30 | struct config : config_base 31 | { 32 | /** Constructor 33 | */ 34 | config() noexcept 35 | { 36 | body_limit = 64 * 1024; 37 | } 38 | }; 39 | 40 | /** Constructor 41 | */ 42 | BOOST_HTTP_PROTO_DECL 43 | explicit 44 | request_parser(context&); 45 | 46 | /** Return a read-only view to the parsed request headers. 47 | 48 | The returned view becomes invalid after calling 49 | @ref start or @ref reset. 50 | 51 | @par Preconditions 52 | This function can be called only after the 53 | header is fully parsed. 54 | 55 | @return A read-only view to the parsed request headers. 56 | */ 57 | BOOST_HTTP_PROTO_DECL 58 | request_view 59 | get() const; 60 | }; 61 | 62 | } // http_proto 63 | } // boost 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/boost/http_proto/request_view.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_REQUEST_VIEW_HPP 11 | #define BOOST_HTTP_PROTO_REQUEST_VIEW_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** A read-only reference to an HTTP request 21 | */ 22 | class request_view 23 | : public message_view_base 24 | { 25 | friend class request_base; 26 | friend class request_parser; 27 | 28 | explicit 29 | request_view( 30 | detail::header const* ph) noexcept 31 | : fields_view_base(ph) 32 | { 33 | BOOST_ASSERT(ph_->kind == 34 | detail::kind::request); 35 | } 36 | 37 | public: 38 | /** Constructor 39 | */ 40 | request_view() noexcept 41 | : fields_view_base( 42 | detail::header::get_default( 43 | detail::kind::request)) 44 | { 45 | } 46 | 47 | /** Constructor 48 | */ 49 | request_view( 50 | request_view const&) noexcept = default; 51 | 52 | /** Assignment 53 | */ 54 | request_view& 55 | operator=( 56 | request_view const&) noexcept = default; 57 | 58 | //-------------------------------------------- 59 | // 60 | // Observers 61 | // 62 | //-------------------------------------------- 63 | 64 | /** Return the method as an integral constant 65 | 66 | If the method returned is equal to 67 | @ref method::unknown, the method may 68 | be obtained as a string instead, by 69 | calling @ref method_text. 70 | */ 71 | http_proto::method 72 | method() const noexcept 73 | { 74 | return ph_->req.method; 75 | }; 76 | 77 | /** Return the method as a string 78 | */ 79 | core::string_view 80 | method_text() const noexcept 81 | { 82 | return core::string_view( 83 | ph_->cbuf, 84 | ph_->req.method_len); 85 | } 86 | 87 | /** Return the request-target string 88 | */ 89 | core::string_view 90 | target() const noexcept 91 | { 92 | return core::string_view( 93 | ph_->cbuf + 94 | ph_->req.method_len + 1, 95 | ph_->req.target_len); 96 | } 97 | 98 | /** Return the HTTP-version 99 | */ 100 | http_proto::version 101 | version() const noexcept 102 | { 103 | return ph_->version; 104 | } 105 | 106 | /** Swap this with another instance 107 | */ 108 | void 109 | swap(request_view& other) noexcept 110 | { 111 | auto ph = ph_; 112 | ph_ = other.ph_; 113 | ph_ = ph; 114 | } 115 | 116 | /** Swap two instances 117 | */ 118 | // hidden friend 119 | friend 120 | void 121 | swap( 122 | request_view& t0, 123 | request_view& t1) noexcept 124 | { 125 | t0.swap(t1); 126 | } 127 | }; 128 | 129 | } // http_proto 130 | } // boost 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /include/boost/http_proto/response_parser.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RESPONSE_PARSER_HPP 11 | #define BOOST_HTTP_PROTO_RESPONSE_PARSER_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | namespace http_proto { 22 | 23 | class response_parser 24 | : public parser 25 | { 26 | public: 27 | /** Configuration settings for parsing requests 28 | */ 29 | struct config : config_base 30 | { 31 | /** Constructor 32 | */ 33 | config() noexcept 34 | { 35 | body_limit = 1024 * 1024; 36 | } 37 | }; 38 | 39 | /** Constructor 40 | */ 41 | BOOST_HTTP_PROTO_DECL 42 | explicit 43 | response_parser(context& ctx); 44 | 45 | /** Prepare for the next message on the stream. 46 | 47 | This informs the parser not to read a 48 | payload for the next message, regardless 49 | of the presence or absence of certain 50 | fields such as Content-Length or a chunked 51 | Transfer-Encoding. Depending on the request, 52 | some responses do not carry a body. For 53 | example, a 200 response to a CONNECT 54 | request from a tunneling proxy, or a 55 | response to a HEAD request. In these 56 | cases, callers may use this function 57 | inform the parser that no body is 58 | expected. The parser will consider the 59 | message complete after the header has 60 | been received. 61 | 62 | @par Preconditions 63 | 64 | This function must called before any calls to parse 65 | the current message. 66 | 67 | @see 68 | https://datatracker.ietf.org/doc/html/rfc7230#section-3.3 69 | */ 70 | void 71 | start_head_response() 72 | { 73 | start_impl(true); 74 | } 75 | 76 | /** Return a read-only view to the parsed response headers. 77 | 78 | The returned view becomes invalid after calling 79 | @ref start or @ref reset. 80 | 81 | @par Preconditions 82 | This function can be called only after the 83 | header is fully parsed. 84 | 85 | @return A read-only view to the parsed response headers. 86 | */ 87 | BOOST_HTTP_PROTO_DECL 88 | response_view 89 | get() const; 90 | }; 91 | 92 | } // http_proto 93 | } // boost 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /include/boost/http_proto/response_view.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RESPONSE_VIEW_HPP 11 | #define BOOST_HTTP_PROTO_RESPONSE_VIEW_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** A reference to an HTTP response header 21 | */ 22 | class response_view 23 | : public message_view_base 24 | { 25 | friend class response_base; 26 | friend class response_parser; 27 | 28 | explicit 29 | response_view( 30 | detail::header const* ph) noexcept 31 | : fields_view_base(ph) 32 | { 33 | BOOST_ASSERT(ph_->kind == 34 | detail::kind::response); 35 | } 36 | 37 | public: 38 | /** Constructor 39 | */ 40 | response_view() noexcept 41 | : fields_view_base( 42 | detail::header::get_default( 43 | detail::kind::response)) 44 | { 45 | } 46 | 47 | /** Constructor 48 | */ 49 | response_view( 50 | response_view const&) noexcept = default; 51 | 52 | /** Assignment 53 | */ 54 | response_view& 55 | operator=( 56 | response_view const&) noexcept = default; 57 | 58 | //-------------------------------------------- 59 | // 60 | // Observers 61 | // 62 | //-------------------------------------------- 63 | 64 | /** Return the reason string 65 | 66 | This field is obsolete in HTTP/1 67 | and should only be used for display 68 | purposes. 69 | */ 70 | core::string_view 71 | reason() const noexcept 72 | { 73 | return core::string_view( 74 | ph_->cbuf + 13, 75 | ph_->prefix - 15); 76 | } 77 | 78 | /** Return the status code 79 | */ 80 | http_proto::status 81 | status() const noexcept 82 | { 83 | return ph_->res.status; 84 | } 85 | 86 | /** Return the status code integer 87 | */ 88 | unsigned short 89 | status_int() const noexcept 90 | { 91 | return ph_->res.status_int; 92 | } 93 | 94 | /** Return the HTTP-version 95 | */ 96 | http_proto::version 97 | version() const noexcept 98 | { 99 | return ph_->version; 100 | } 101 | 102 | /** Swap this with another instance 103 | */ 104 | void 105 | swap(response_view& other) noexcept 106 | { 107 | auto ph = ph_; 108 | ph_ = other.ph_; 109 | ph_ = ph; 110 | } 111 | 112 | /** Swap two instances 113 | */ 114 | // hidden friend 115 | friend 116 | void 117 | swap( 118 | response_view& t0, 119 | response_view& t1) noexcept 120 | { 121 | t0.swap(t1); 122 | } 123 | }; 124 | 125 | } // http_proto 126 | } // boost 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/combine_field_values.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_COMBINE_FIELD_VALUES_HPP 11 | #define BOOST_HTTP_PROTO_RFC_COMBINE_FIELD_VALUES_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | //------------------------------------------------ 23 | 24 | /** Return a comma-separated list of field values 25 | 26 | This function combines a set of zero or 27 | fields with the same name into a single 28 | comma-separated string. The algorithm 29 | sometimes needs temporary storage, which 30 | is obtained if necessary from `temp`. 31 |
32 | Ownership is not transferred; the caller 33 | is responsible for ensuring that the 34 | lifetime of both the character buffer 35 | underlying the fields and the temporary 36 | recycled string extend until the string 37 | returned by this function is no longer 38 | referenced. 39 | 40 | @par Example 41 | This combines any Content-Length fields 42 | present in `h` into a single string. 43 | @code 44 | grammar::recycled_ptr< std::string > temp( nullptr ); 45 | 46 | string_view s = combine_field_values( h.find_all( field::content_length ), temp ); 47 | @endcode 48 | 49 | @param vr The subrange of fields to combine. 50 | 51 | @param temp A temporary recycled string 52 | which may be used if necessary. The pointer 53 | may be empty. 54 | */ 55 | BOOST_HTTP_PROTO_DECL 56 | core::string_view 57 | combine_field_values( 58 | fields_view_base::subrange const& vr, 59 | grammar::recycled_ptr& temp); 60 | 61 | } // http_proto 62 | } // boost 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/list_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_LIST_RULE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_LIST_RULE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | /** Rule for a comma-delimited list of elements 22 | 23 | This rule defines a list containing 24 | at least n and at most m of Element, 25 | each separated by at least one comma 26 | and optional whitespace. 27 | 28 | @par BNF 29 | @code 30 | #element => [ 1#element ] 31 | 1#element => element *( OWS "," OWS element ) 32 | #element => element *( OWS "," OWS element ) 33 | @endcode 34 | 35 | Senders must emit compliant values, but 36 | receivers should accept values generated 37 | with the legacy production rules: 38 | 39 | @par Legacy BNF 40 | @code 41 | #element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ] 42 | 43 | 1#element => *( "," OWS ) element *( OWS "," [ OWS element ] ) 44 | @endcode 45 | 46 | @tparam R The rule to use for elements 47 | @tparam N The minimum number of elements, which may be zero 48 | @tparam M The maximum number of elements. 49 | 50 | @par Specification 51 | @li 5.6.1. Lists (#rule ABNF Extension) (rfc7230) 53 | */ 54 | #ifdef BOOST_HTTP_PROTO_DOCS 55 | template 56 | constexpr 57 | __implementation_defined__ 58 | list_rule( 59 | Rule element, 60 | std::size_t N = 0, 61 | std::size_t M = 62 | std::size_t(-1)) noexcept; 63 | #else 64 | template 65 | struct list_rule_t 66 | : private empty_value 67 | { 68 | using value_type = grammar::range< 69 | typename Rule::value_type>; 70 | 71 | constexpr 72 | list_rule_t( 73 | Rule const& r, 74 | std::size_t n, 75 | std::size_t m) noexcept 76 | : empty_value( 77 | empty_init, r) 78 | , n_(n) 79 | , m_(m) 80 | { 81 | } 82 | 83 | auto 84 | parse( 85 | char const*& it, 86 | char const* end) const -> 87 | system::result; 88 | 89 | private: 90 | struct first_rule; 91 | struct next_rule; 92 | 93 | std::size_t n_; 94 | std::size_t m_; 95 | }; 96 | 97 | template 98 | constexpr 99 | auto 100 | list_rule( 101 | Rule const& r, 102 | std::size_t N = 0, 103 | std::size_t M = 104 | std::size_t(-1)) noexcept -> 105 | list_rule_t 106 | { 107 | return list_rule_t(r, N, M); 108 | } 109 | #endif 110 | 111 | } // http_proto 112 | } // boost 113 | 114 | #include 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/media_type.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_MEDIA_TYPE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_MEDIA_TYPE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** A mime-type 21 | */ 22 | struct mime_type 23 | { 24 | /** The type 25 | */ 26 | string_view type; 27 | 28 | /** The subtype 29 | */ 30 | string_view subtype; 31 | }; 32 | 33 | //------------------------------------------------ 34 | 35 | /** A media-type 36 | */ 37 | struct media_type 38 | { 39 | /** The mime type 40 | */ 41 | mime_type mime; 42 | 43 | /** Parameters 44 | */ 45 | grammar::range< 46 | parameter> params; 47 | }; 48 | 49 | //------------------------------------------------ 50 | 51 | /** Rule matching media-type 52 | 53 | @par BNF 54 | @code 55 | media-type = type "/" subtype *( OWS ";" OWS parameter ) 56 | parameter = token "=" ( token / quoted-string ) 57 | subtype = token 58 | type = token 59 | @endcode 60 | 61 | @par Specification 62 | @li 3.1.1.1. Media Type (rfc7231) 64 | */ 65 | #ifdef BOOST_HTTP_PROTO_DOCS 66 | constexpr __implementation_defined__ media_type_rule; 67 | #else 68 | struct media_type_rule_t 69 | { 70 | using value_type = media_type; 71 | 72 | BOOST_HTTP_PROTO_DECL 73 | auto 74 | parse( 75 | char const*& it, 76 | char const* end) const noexcept -> 77 | result; 78 | }; 79 | 80 | constexpr media_type_rule_t media_type_rule{}; 81 | #endif 82 | 83 | } // http_proto 84 | } // boost 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/parameter.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_PARAMETER_HPP 11 | #define BOOST_HTTP_PROTO_RFC_PARAMETER_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** An HTTP header parameter 21 | 22 | @par BNF 23 | @code 24 | parameter = token "=" ( token / quoted-string ) 25 | @endcode 26 | 27 | @par Specification 28 | @li 3.1.1.1. Media Type (rfc7231) 30 | */ 31 | struct parameter 32 | { 33 | core::string_view name; 34 | quoted_token_view value; 35 | }; 36 | 37 | //------------------------------------------------ 38 | 39 | /** Rule matching parameter 40 | 41 | @par Value Type 42 | @code 43 | using value_type = parameter; 44 | @endcode 45 | 46 | @par Example 47 | @code 48 | @endcode 49 | 50 | @par BNF 51 | @code 52 | parameter = token "=" ( token / quoted-string ) 53 | @endcode 54 | 55 | @par Specification 56 | @li 3.1.1.1. Media Type (rfc7231) 58 | 59 | @see 60 | @ref quoted_token_view 61 | */ 62 | #ifdef BOOST_HTTP_PROTO_DOCS 63 | constexpr __implementation_defined__ parameter_rule; 64 | #else 65 | struct parameter_rule_t 66 | { 67 | using value_type = parameter; 68 | 69 | BOOST_HTTP_PROTO_DECL 70 | auto 71 | parse( 72 | char const*&, 73 | char const*) const noexcept -> 74 | system::result; 75 | }; 76 | 77 | constexpr parameter_rule_t parameter_rule{}; 78 | #endif 79 | 80 | } // http_proto 81 | } // boost 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/quoted_token_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_QUOTED_TOKEN_RULE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_QUOTED_TOKEN_RULE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | /** Rule matching quoted-token 22 | 23 | @par Value Type 24 | @code 25 | using value_type = quoted_token_view; 26 | @endcode 27 | 28 | @par Example 29 | @code 30 | @endcode 31 | 32 | @par BNF 33 | @code 34 | quoted-token = token / quoted-string 35 | 36 | token = 1*tchar 37 | quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE 38 | qdtext = HTAB / SP / 0x21 / 0x23-0x5B / 0x5D-0x7E / obs-text 39 | obs-text = 0x80-0xFF 40 | quoted-pair = "\"" ( HTAB / SP / VCHAR / obs-text ) 41 | @endcode 42 | 43 | @par Specification 44 | @li 3.2.6. Field Value Components (rfc7230) 46 | 47 | @see 48 | @ref quoted_token_view 49 | */ 50 | #ifdef BOOST_HTTP_PROTO_DOCS 51 | constexpr __implementation_defined__ quoted_token_rule; 52 | #else 53 | struct quoted_token_rule_t 54 | { 55 | using value_type = quoted_token_view; 56 | 57 | BOOST_HTTP_PROTO_DECL 58 | auto 59 | parse( 60 | char const*& it, 61 | char const* end) const noexcept -> 62 | system::result; 63 | }; 64 | 65 | constexpr quoted_token_rule_t quoted_token_rule{}; 66 | #endif 67 | 68 | } // http_proto 69 | } // boost 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/quoted_token_view.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_QUOTED_TOKEN_VIEW_HPP 11 | #define BOOST_HTTP_PROTO_RFC_QUOTED_TOKEN_VIEW_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | class quoted_token_view 21 | : public grammar::string_view_base 22 | { 23 | std::size_t n_ = 0; 24 | 25 | friend struct quoted_token_rule_t; 26 | 27 | // unquoted 28 | explicit 29 | quoted_token_view( 30 | core::string_view s) noexcept 31 | : string_view_base(s) 32 | , n_(s.size()) 33 | { 34 | } 35 | 36 | // maybe quoted 37 | quoted_token_view( 38 | core::string_view s, 39 | std::size_t n) noexcept 40 | : string_view_base(s) 41 | , n_(n) 42 | { 43 | BOOST_ASSERT(s.size() >= 2); 44 | BOOST_ASSERT(s.front() == '\"'); 45 | BOOST_ASSERT(s.back() == '\"'); 46 | BOOST_ASSERT(n_ <= s_.size() - 2); 47 | } 48 | 49 | public: 50 | quoted_token_view() = default; 51 | 52 | quoted_token_view( 53 | quoted_token_view const&) noexcept = default; 54 | 55 | quoted_token_view& operator=( 56 | quoted_token_view const&) noexcept = default; 57 | 58 | bool 59 | has_escapes() const noexcept 60 | { 61 | return n_ != s_.size(); 62 | } 63 | 64 | std::size_t 65 | unescaped_size() const noexcept 66 | { 67 | return n_; 68 | } 69 | }; 70 | 71 | } // http_proto 72 | } // boost 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/token_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_TOKEN_RULE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_TOKEN_RULE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** The set of token characters 21 | 22 | @par BNF 23 | @code 24 | tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" 25 | / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" 26 | / DIGIT / ALPHA 27 | ; any VCHAR, except delimiters 28 | 29 | VCHAR = 0x21-0x7E 30 | @endcode 31 | 32 | @par Specification 33 | @li 3.2.3. Whitespace (rfc7230) 35 | @li B.1. Core Rules (rfc5234) 37 | */ 38 | constexpr grammar::lut_chars tchars = 39 | #ifdef BOOST_HTTP_PROTO_DOCS 40 | __see_below__ 41 | #else 42 | "!#$%&'*+-.^_`|~" 43 | "0123456789" 44 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 45 | "abcdefghijklmnopqrstuvwxyz" 46 | #endif 47 | ; 48 | 49 | /** Match a token 50 | 51 | @par Value Type 52 | @code 53 | using value_type = string_view; 54 | @endcode 55 | 56 | @par Example 57 | @code 58 | @endcode 59 | 60 | @par BNF 61 | @code 62 | token = 1*tchar 63 | @endcode 64 | */ 65 | constexpr auto token_rule = grammar::token_rule( tchars ); 66 | 67 | } // http_proto 68 | } // boost 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/boost/http_proto/rfc/upgrade_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_UPGRADE_RULE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_UPGRADE_RULE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | //------------------------------------------------ 21 | 22 | /** An Upgrade protocol 23 | */ 24 | struct upgrade_protocol 25 | { 26 | /** The name of the protocol 27 | */ 28 | core::string_view name; 29 | 30 | /** Optional protocol version 31 | 32 | An empty version indicates a 33 | version is not present. 34 | */ 35 | core::string_view version; 36 | }; 37 | 38 | //------------------------------------------------ 39 | 40 | /** Rule to match Upgrade protocol 41 | 42 | @par Value Type 43 | @code 44 | using value_type = upgrade_protocol; 45 | @endcode 46 | 47 | @par Example 48 | @code 49 | @endcode 50 | 51 | @par BNF 52 | @code 53 | protocol = protocol-name ["/" protocol-version] 54 | protocol-name = token 55 | protocol-version = token 56 | @endcode 57 | 58 | @par Specification 59 | @li 6.7. Upgrade (rfc7230) 61 | 62 | @see 63 | @ref upgrade_protocol. 64 | */ 65 | #ifdef BOOST_HTTP_PROTO_DOCS 66 | constexpr __implementation_defined__ upgrade_protocol_rule; 67 | #else 68 | struct upgrade_protocol_rule_t 69 | { 70 | using value_type = upgrade_protocol; 71 | 72 | BOOST_HTTP_PROTO_DECL 73 | auto 74 | parse( 75 | char const*& it, 76 | char const* end) const noexcept -> 77 | system::result; 78 | }; 79 | 80 | constexpr upgrade_protocol_rule_t upgrade_protocol_rule{}; 81 | #endif 82 | 83 | //------------------------------------------------ 84 | 85 | /** Rule matching the Upgrade field value 86 | 87 | @par Value Type 88 | @code 89 | using value_type = grammar::range< upgrade_protocol >; 90 | @endcode 91 | 92 | @par Example 93 | @code 94 | @endcode 95 | 96 | @par BNF 97 | @code 98 | Upgrade = 1#protocol 99 | 100 | protocol = protocol-name ["/" protocol-version] 101 | protocol-name = token 102 | protocol-version = token 103 | @endcode 104 | 105 | @par Specification 106 | @li 6.7. Upgrade (rfc7230) 108 | 109 | @see 110 | @ref upgrade_protocol. 111 | */ 112 | constexpr auto upgrade_rule = list_rule( upgrade_protocol_rule, 1 ); 113 | 114 | } // http_proto 115 | } // boost 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /include/boost/http_proto/service/deflate_service.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Christian Mazakas 4 | // Copyright (c) 2024 Mohammad Nejati 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // Official repository: https://github.com/cppalliance/http_proto 10 | // 11 | 12 | #ifndef BOOST_HTTP_PROTO_SERVICE_DEFLATE_SERVICE_HPP 13 | #define BOOST_HTTP_PROTO_SERVICE_DEFLATE_SERVICE_HPP 14 | 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | namespace zlib { 21 | 22 | /** Provides the ZLib compression API 23 | */ 24 | struct deflate_service 25 | { 26 | virtual char const* version() const noexcept = 0; 27 | virtual int init(stream_t& st, int level) const = 0; 28 | virtual int init2(stream_t& st, int level, int method, 29 | int windowBits, int memLevel, int strategy) const = 0; 30 | virtual int set_dict(stream_t& st, unsigned char const* dict, unsigned len) const = 0; 31 | virtual int get_dict(stream_t& st, unsigned char* dest, unsigned* len) const = 0; 32 | virtual int dup(stream_t& dest, stream_t& src) const = 0; 33 | virtual int deflate(stream_t& st, int flush) const = 0; 34 | virtual int deflate_end(stream_t& st) const = 0; 35 | virtual int reset(stream_t& st) const = 0; 36 | virtual int params(stream_t& st, int level, int strategy) const = 0; 37 | virtual std::size_t bound(stream_t& st, unsigned long sourceLen) const = 0; 38 | virtual int pending(stream_t& st, unsigned* pending, int* bits) const = 0; 39 | virtual int prime(stream_t& st, int bits, int value) const = 0; 40 | virtual int set_header(stream_t& st, void* header) const = 0; 41 | }; 42 | 43 | BOOST_HTTP_PROTO_ZLIB_DECL 44 | void 45 | install_deflate_service(context& ctx); 46 | 47 | } // zlib 48 | } // http_proto 49 | } // boost 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/http_proto/service/impl/zlib_service.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Mohammad Nejati 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // Official repository: https://github.com/cppalliance/http_proto 9 | // 10 | 11 | #ifndef BOOST_HTTP_PROTO_SERVICE_IMPL_ZLIB_SERVICE_HPP 12 | #define BOOST_HTTP_PROTO_SERVICE_IMPL_ZLIB_SERVICE_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | 18 | namespace system { 19 | template<> 20 | struct is_error_code_enum< 21 | ::boost::http_proto::zlib::error> 22 | { 23 | static bool const value = true; 24 | }; 25 | } // system 26 | 27 | namespace http_proto { 28 | namespace zlib { 29 | 30 | namespace detail { 31 | 32 | struct BOOST_SYMBOL_VISIBLE 33 | error_cat_type 34 | : system::error_category 35 | { 36 | BOOST_HTTP_PROTO_DECL const char* name( 37 | ) const noexcept override; 38 | BOOST_HTTP_PROTO_DECL bool failed( 39 | int) const noexcept override; 40 | BOOST_HTTP_PROTO_DECL std::string message( 41 | int) const override; 42 | BOOST_HTTP_PROTO_DECL char const* message( 43 | int, char*, std::size_t 44 | ) const noexcept override; 45 | BOOST_SYSTEM_CONSTEXPR error_cat_type() 46 | : error_category(0xe6c6d0215d1d6e22) 47 | { 48 | } 49 | }; 50 | 51 | BOOST_HTTP_PROTO_DECL extern 52 | error_cat_type error_cat; 53 | 54 | } // detail 55 | 56 | inline 57 | BOOST_SYSTEM_CONSTEXPR 58 | system::error_code 59 | make_error_code( 60 | error ev) noexcept 61 | { 62 | return system::error_code{ 63 | static_cast::type>(ev), 65 | detail::error_cat}; 66 | } 67 | 68 | } // zip 69 | } // http_proto 70 | } // boost 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/boost/http_proto/service/inflate_service.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_SERVICE_INFLATE_SERVICE_HPP 11 | #define BOOST_HTTP_PROTO_SERVICE_INFLATE_SERVICE_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | namespace zlib { 19 | 20 | /** Provides the ZLib decompression API 21 | */ 22 | struct inflate_service 23 | { 24 | virtual char const* version() const noexcept = 0; 25 | virtual int init(stream_t& st) const = 0; 26 | virtual int init2(stream_t& st, int windowBits) const = 0; 27 | virtual int inflate(stream_t& st, int flush) const = 0; 28 | virtual int inflate_end(stream_t& st) const = 0; 29 | virtual int set_dict(stream_t& st, unsigned char const* dict, unsigned len) const = 0; 30 | virtual int get_dict(stream_t& st, unsigned char* dest, unsigned* len) const = 0; 31 | virtual int sync(stream_t& st) const = 0; 32 | virtual int dup(stream_t& dest, stream_t& src) const = 0; 33 | virtual int reset(stream_t& st) const = 0; 34 | virtual int reset2(stream_t& st, int windowBits) const = 0; 35 | virtual int prime(stream_t& st, int bits, int value) const = 0; 36 | virtual long mark(stream_t& st) const = 0; 37 | virtual int get_header(stream_t& st, void* header) const = 0; 38 | virtual int back_init(stream_t& st, int windowBits, unsigned char* window) const = 0; 39 | virtual int back_end(stream_t& st) const = 0; 40 | virtual unsigned long compile_flags() const = 0; 41 | }; 42 | 43 | BOOST_HTTP_PROTO_ZLIB_DECL 44 | void 45 | install_inflate_service(context& ctx); 46 | 47 | } // zlib 48 | } // http_proto 49 | } // boost 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/http_proto/service/service.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_SERVICE_SERVICE_HPP 11 | #define BOOST_HTTP_PROTO_SERVICE_SERVICE_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | #ifndef BOOST_HTTP_PROTO_DOCS 19 | class services; 20 | #endif 21 | 22 | /** Base class for all context services 23 | */ 24 | struct BOOST_SYMBOL_VISIBLE 25 | service 26 | { 27 | BOOST_HTTP_PROTO_DECL 28 | virtual 29 | ~service() = 0; 30 | 31 | #if 0 32 | protected: 33 | /** Called to perform two-phase initialization 34 | */ 35 | virtual 36 | void 37 | start() = 0; 38 | #endif 39 | 40 | private: 41 | friend class services; 42 | }; 43 | 44 | } // http_proto 45 | } // boost 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/http_proto/static_fields.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 Mohammad Nejati 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_STATIC_FIELDS_HPP 11 | #define BOOST_HTTP_PROTO_STATIC_FIELDS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | /** A modifiable static container of HTTP fields 22 | */ 23 | template 24 | class static_fields final 25 | : public fields_base 26 | { 27 | alignas(entry) 28 | char buf_[Capacity]; 29 | 30 | public: 31 | 32 | //-------------------------------------------- 33 | // 34 | // Special Members 35 | // 36 | //-------------------------------------------- 37 | 38 | /** Constructor 39 | 40 | Default-constructed fields have no 41 | name-value pairs. 42 | */ 43 | static_fields() noexcept 44 | : fields_view_base( 45 | &this->fields_base::h_) 46 | , fields_base( 47 | detail::kind::fields, 48 | buf_, 49 | Capacity) 50 | { 51 | } 52 | 53 | /** Constructor 54 | */ 55 | explicit static_fields( 56 | core::string_view s) 57 | : fields_view_base( 58 | &this->fields_base::h_) 59 | , fields_base( 60 | detail::kind::fields, 61 | buf_, 62 | Capacity, 63 | s) 64 | { 65 | } 66 | 67 | /** Constructor 68 | */ 69 | static_fields( 70 | static_fields const& other) noexcept 71 | : fields_view_base( 72 | &this->fields_base::h_) 73 | , fields_base( 74 | *other.ph_, 75 | buf_, 76 | Capacity) 77 | { 78 | } 79 | 80 | /** Constructor 81 | */ 82 | static_fields( 83 | fields_view const& other) 84 | : fields_view_base( 85 | &this->fields_base::h_) 86 | , fields_base( 87 | *other.ph_, 88 | buf_, 89 | Capacity) 90 | { 91 | } 92 | 93 | /** Assignment 94 | */ 95 | static_fields& 96 | operator=(static_fields const& f) noexcept 97 | { 98 | copy_impl(*f.ph_); 99 | return *this; 100 | } 101 | 102 | /** Assignment 103 | */ 104 | static_fields& 105 | operator=(fields_view const& f) 106 | { 107 | copy_impl(*f.ph_); 108 | return *this; 109 | } 110 | 111 | /** Conversion 112 | */ 113 | operator fields_view() const noexcept 114 | { 115 | return fields_view(ph_); 116 | } 117 | }; 118 | 119 | } // http_proto 120 | } // boost 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/boost/http_proto/static_request.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 Mohammad Nejati 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_STATIC_REQUEST_HPP 11 | #define BOOST_HTTP_PROTO_STATIC_REQUEST_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | /** A modfiable static container for HTTP requests 19 | */ 20 | template 21 | class static_request 22 | : public request_base 23 | { 24 | alignas(entry) 25 | char buf_[Capacity]; 26 | 27 | public: 28 | /** Constructor 29 | */ 30 | static_request() noexcept 31 | : fields_view_base(&this->fields_base::h_) 32 | , request_base(buf_, Capacity) 33 | { 34 | } 35 | 36 | /** Constructor 37 | */ 38 | explicit 39 | static_request( 40 | core::string_view s) 41 | : fields_view_base(&this->fields_base::h_) 42 | , request_base(s, buf_, Capacity) 43 | { 44 | } 45 | 46 | /** Constructor 47 | */ 48 | static_request( 49 | static_request const& other) noexcept 50 | : fields_view_base(&this->fields_base::h_) 51 | , request_base(*other.ph_, buf_, Capacity) 52 | { 53 | } 54 | 55 | /** Constructor 56 | */ 57 | static_request( 58 | request_view const& other) 59 | : fields_view_base(&this->fields_base::h_) 60 | , request_base(*other.ph_, buf_, Capacity) 61 | { 62 | } 63 | 64 | /** Assignment 65 | */ 66 | static_request& 67 | operator=( 68 | static_request const& other) noexcept 69 | { 70 | copy_impl(*other.ph_); 71 | return *this; 72 | } 73 | 74 | /** Assignment 75 | */ 76 | static_request& 77 | operator=( 78 | request_view const& other) 79 | { 80 | copy_impl(*other.ph_); 81 | return *this; 82 | } 83 | }; 84 | 85 | } // http_proto 86 | } // boost 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /include/boost/http_proto/static_response.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 Mohammad Nejati 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP 11 | #define BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP 12 | 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | /** A modfiable static container for HTTP responses 19 | */ 20 | template 21 | class static_response 22 | : public response_base 23 | { 24 | alignas(entry) 25 | char buf_[Capacity]; 26 | 27 | public: 28 | /** Constructor 29 | */ 30 | static_response() noexcept 31 | : fields_view_base(&this->fields_base::h_) 32 | , response_base(buf_, Capacity) 33 | { 34 | } 35 | 36 | /** Constructor 37 | */ 38 | explicit 39 | static_response( 40 | core::string_view s) 41 | : fields_view_base(&this->fields_base::h_) 42 | , response_base(s, buf_, Capacity) 43 | { 44 | } 45 | 46 | /** Constructor 47 | */ 48 | static_response( 49 | http_proto::status sc, 50 | http_proto::version v) 51 | : static_response() 52 | { 53 | if( sc != h_.res.status || 54 | v != h_.version) 55 | set_start_line(sc, v); 56 | } 57 | 58 | /** Constructor 59 | * 60 | * The start-line of the response will contain the standard 61 | * text for the supplied status code and the HTTP version 62 | * will be defaulted to 1.1. 63 | */ 64 | explicit 65 | static_response( 66 | http_proto::status sc) 67 | : static_response( 68 | sc, http_proto::version::http_1_1) 69 | { 70 | } 71 | 72 | /** Constructor 73 | */ 74 | static_response( 75 | static_response const& other) noexcept 76 | : fields_view_base(&this->fields_base::h_) 77 | , response_base(*other.ph_, buf_, Capacity) 78 | { 79 | } 80 | 81 | /** Constructor 82 | */ 83 | static_response( 84 | response_view const& other) 85 | : fields_view_base(&this->fields_base::h_) 86 | , response_base(*other.ph_, buf_, Capacity) 87 | { 88 | } 89 | 90 | /** Assignment 91 | */ 92 | static_response& 93 | operator=( 94 | static_response const& other) noexcept 95 | { 96 | copy_impl(*other.ph_); 97 | return *this; 98 | } 99 | 100 | /** Assignment 101 | */ 102 | static_response& 103 | operator=( 104 | response_view const& other) 105 | { 106 | copy_impl(*other.ph_); 107 | return *this; 108 | } 109 | }; 110 | 111 | } // http_proto 112 | } // boost 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /include/boost/http_proto/string_body.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_STRING_BODY_HPP 11 | #define BOOST_HTTP_PROTO_STRING_BODY_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | class string_body 22 | { 23 | std::string s_; 24 | buffers::const_buffer cb_; 25 | 26 | public: 27 | using value_type = buffers::const_buffer; 28 | using const_iterator = buffers::const_buffer const*; 29 | 30 | string_body( 31 | string_body&& other) noexcept 32 | : s_(std::move(other.s_)) 33 | , cb_(s_.data(), s_.size()) 34 | { 35 | other.cb_ = {}; 36 | } 37 | 38 | string_body( 39 | string_body const& other) = delete; 40 | 41 | string_body( 42 | std::string s) noexcept 43 | : s_(std::move(s)) 44 | , cb_(s_.data(), s_.size()) 45 | { 46 | } 47 | 48 | const_iterator 49 | begin() const noexcept 50 | { 51 | return &cb_; 52 | } 53 | 54 | const_iterator 55 | end() const noexcept 56 | { 57 | return &cb_ + 1; 58 | } 59 | }; 60 | 61 | //------------------------------------------------ 62 | 63 | } // http_proto 64 | } // boost 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/boost/http_proto/version.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_VERSION_HPP 11 | #define BOOST_HTTP_PROTO_VERSION_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | /** Constants representing HTTP versions. 21 | 22 | Only versions 1.0 and 1.1 are recognized. 23 | */ 24 | enum class version : char 25 | { 26 | http_1_0 = 10, 27 | http_1_1 = 11 28 | }; 29 | 30 | /** Return the serialized string representing the HTTP version 31 | */ 32 | BOOST_HTTP_PROTO_DECL 33 | core::string_view 34 | to_string(version v) noexcept; 35 | 36 | /** Format the version to an output stream. 37 | */ 38 | BOOST_HTTP_PROTO_DECL 39 | std::ostream& 40 | operator<<(std::ostream& os, version v); 41 | 42 | } // http_proto 43 | } // boost 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Boost.HTTP.Proto 4 | 5 | 6 | 7 | Automatic redirection failed, please go to 8 | ./doc/html/index.html 9 |
10 | 11 | Boost.HTTP.Proto
12 |
13 | Copyright (C) 2019 Vinnie Falco
14 |
15 | Distributed under the Boost Software License, Version 1.0. 16 | (See accompanying file LICENSE_1_0.txt or copy at 17 | http://www.boost.org/LICENSE_1_0.txt)
18 |
19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /meta/explicit-failures-markup.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | C++11 is the minimum requirement. 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "http_proto", 3 | "name": "HTTP Proto", 4 | "authors": [ 5 | "Vinnie Falco" 6 | ], 7 | "description": "HTTP/1.1 protocol implementation in C++11", 8 | "category": [ 9 | "Containers", 10 | "Data", 11 | "IO" 12 | ], 13 | "maintainers": [ 14 | "Vinnie Falco " 15 | ], 16 | "cxxstd": "11" 17 | } 18 | -------------------------------------------------------------------------------- /src/context.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | //#include // doesn't support heterogenous lookup yet 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct context::data 19 | { 20 | // Installed services 21 | std::unordered_map< 22 | detail::type_index, 23 | std::unique_ptr, 24 | detail::type_index_hasher 25 | > services; 26 | }; 27 | 28 | //------------------------------------------------ 29 | 30 | context:: 31 | ~context() 32 | { 33 | } 34 | 35 | context:: 36 | context() 37 | : p_(new data) 38 | { 39 | } 40 | 41 | //------------------------------------------------ 42 | 43 | auto 44 | context:: 45 | find_service_impl( 46 | detail::type_index id) const noexcept -> 47 | service* 48 | { 49 | auto it = p_->services.find(id); 50 | if(it != p_->services.end()) 51 | return it->second.get(); 52 | return nullptr; 53 | } 54 | 55 | auto 56 | context:: 57 | make_service_impl( 58 | detail::type_index id, 59 | std::unique_ptr sp) -> 60 | service& 61 | { 62 | auto const result = 63 | p_->services.emplace( 64 | id, std::move(sp)); 65 | if(! result.second) 66 | { 67 | // already exists 68 | detail::throw_out_of_range(); 69 | } 70 | return *result.first->second; 71 | } 72 | 73 | } // http_proto 74 | } // boost 75 | -------------------------------------------------------------------------------- /src/detail/except.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | namespace detail { 19 | 20 | void 21 | throw_bad_alloc( 22 | source_location const& loc) 23 | { 24 | throw_exception( 25 | std::bad_alloc(), loc); 26 | } 27 | 28 | void 29 | throw_invalid_argument( 30 | source_location const& loc) 31 | { 32 | throw_exception( 33 | std::invalid_argument( 34 | "invalid argument"), 35 | loc); 36 | } 37 | 38 | void 39 | throw_invalid_argument( 40 | char const* what, 41 | source_location const& loc) 42 | { 43 | throw_exception( 44 | std::invalid_argument(what), loc); 45 | } 46 | 47 | void 48 | throw_length_error( 49 | source_location const& loc) 50 | { 51 | throw_exception( 52 | std::length_error( 53 | "length error"), loc); 54 | } 55 | 56 | void 57 | throw_length_error( 58 | char const* what, 59 | source_location const& loc) 60 | { 61 | throw_exception( 62 | std::length_error(what), loc); 63 | } 64 | 65 | void 66 | throw_logic_error( 67 | source_location const& loc) 68 | { 69 | throw_exception( 70 | std::logic_error( 71 | "logic error"), 72 | loc); 73 | } 74 | 75 | void 76 | throw_out_of_range( 77 | source_location const& loc) 78 | { 79 | throw_exception( 80 | std::out_of_range("out of range"), loc); 81 | } 82 | 83 | void 84 | throw_runtime_error( 85 | char const* what, 86 | source_location const& loc) 87 | { 88 | throw_exception( 89 | std::runtime_error(what), loc); 90 | } 91 | 92 | void 93 | throw_system_error( 94 | system::error_code const& ec, 95 | source_location const& loc) 96 | { 97 | throw_exception( 98 | system::system_error(ec), loc); 99 | } 100 | 101 | void 102 | throw_system_error( 103 | error e, 104 | source_location const& loc) 105 | { 106 | throw_exception( 107 | system::system_error(e), loc); 108 | } 109 | 110 | } // detail 111 | } // http_proto 112 | } // boost 113 | -------------------------------------------------------------------------------- /src/detail/impl/filter.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Mohammad Nejati 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // Official repository: https://github.com/cppalliance/http_proto 9 | // 10 | 11 | #ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP 12 | #define BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP 13 | 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | namespace detail { 20 | 21 | template< 22 | class MutableBufferSequence, 23 | class ConstBufferSequence> 24 | auto 25 | filter:: 26 | process_impl( 27 | MutableBufferSequence const& out, 28 | ConstBufferSequence const& in, 29 | bool more) -> 30 | results 31 | { 32 | results rv; 33 | auto it_o = buffers::begin(out); 34 | auto it_i = buffers::begin(in); 35 | 36 | if( it_o == buffers::end(out) || 37 | it_i == buffers::end(in) ) 38 | return rv; 39 | 40 | auto ob = *it_o++; 41 | auto ib = *it_i++; 42 | for(;;) 43 | { 44 | // empty buffers may be passed, and this is 45 | // intentional and valid. 46 | results rs = process_impl(ob, ib, more); 47 | 48 | rv.out_bytes += rs.out_bytes; 49 | rv.in_bytes += rs.in_bytes; 50 | rv.ec = rs.ec; 51 | rv.finished = rs.finished; 52 | 53 | if( rv.finished || rv.ec ) 54 | return rv; 55 | 56 | ob = buffers::sans_prefix(ob, rs.out_bytes); 57 | ib = buffers::sans_prefix(ib, rs.in_bytes); 58 | 59 | if( ob.size() == 0 ) 60 | { 61 | if( it_o == buffers::end(out) ) 62 | return rv; 63 | ob = *it_o++; 64 | } 65 | 66 | if( ib.size() == 0 ) 67 | { 68 | if( it_i == buffers::end(in) ) 69 | { 70 | // if `more == false` we return only 71 | // when `out` buffers are full. 72 | if( more ) 73 | return rv; 74 | } 75 | else 76 | { 77 | ib = *it_i++; 78 | } 79 | } 80 | } 81 | } 82 | 83 | } // detail 84 | } // http_proto 85 | } // boost 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/detail/move_chars.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/CPPAlliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_MOVE_CHARS_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_MOVE_CHARS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | namespace detail { 20 | 21 | // Moves characters, and adjusts any passed 22 | // views if they point to any moved characters. 23 | 24 | // true if s completely overlapped by buf 25 | inline 26 | bool 27 | is_overlapping( 28 | core::string_view buf, 29 | core::string_view s) noexcept 30 | { 31 | auto const b0 = buf.data(); 32 | auto const e0 = b0 + buf.size(); 33 | auto const b1 = s.data(); 34 | auto const e1 = b1 + s.size(); 35 | auto const less_equal = 36 | std::less_equal(); 37 | if(less_equal(e0, b1)) 38 | return false; 39 | if(less_equal(e1, b0)) 40 | return false; 41 | // partial overlap is undefined 42 | BOOST_ASSERT(less_equal(e1, e0)); 43 | BOOST_ASSERT(less_equal(b0, b1)); 44 | return true; 45 | } 46 | 47 | inline 48 | void 49 | move_chars_impl( 50 | char*, 51 | char const*, 52 | core::string_view const&) noexcept 53 | { 54 | } 55 | 56 | template 57 | void 58 | move_chars_impl( 59 | char* dest, 60 | char const* src, 61 | core::string_view const& buf, 62 | core::string_view* s, 63 | Sn&&... sn) noexcept 64 | { 65 | if( s != nullptr && 66 | is_overlapping(buf, *s)) 67 | { 68 | *s = { s->data() + (dest - src), s->size() }; 69 | } 70 | move_chars_impl(dest, src, buf, sn...); 71 | } 72 | 73 | template 74 | void 75 | move_chars( 76 | char* dest, 77 | char const* src, 78 | std::size_t n, 79 | Args&&... args) noexcept 80 | { 81 | move_chars_impl( 82 | dest, 83 | src, 84 | core::string_view(src, n), 85 | args...); 86 | std::memmove( 87 | dest, src, n); 88 | } 89 | 90 | } // detail 91 | } // http_proto 92 | } // boost 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /src/detail/number_string.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/CPPAlliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_NUMBER_STRING_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_NUMBER_STRING_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | namespace detail { 20 | 21 | // Convert integer to decimal 22 | // string using in-place storage 23 | class number_string 24 | { 25 | static constexpr unsigned buf_size = 18; 26 | char buf_[buf_size + 1]; 27 | std::size_t size_ = 0; 28 | 29 | void 30 | construct_unsigned( 31 | std::uint64_t n) noexcept 32 | { 33 | buf_[buf_size] = '\0'; 34 | auto const end = 35 | &buf_[buf_size]; 36 | auto p = end; 37 | if(n == 0) 38 | { 39 | *--p = '0'; 40 | } 41 | else 42 | { 43 | while(n > 0) 44 | { 45 | *--p = '0' + (n%10); 46 | n /= 10; 47 | } 48 | } 49 | size_ = end - p; 50 | } 51 | 52 | public: 53 | number_string() = default; 54 | number_string( 55 | number_string const&) = default; 56 | number_string& operator= 57 | (number_string const&) = default; 58 | 59 | explicit 60 | number_string( 61 | std::uint64_t n) noexcept 62 | { 63 | construct_unsigned(n); 64 | } 65 | 66 | char const* 67 | data() const noexcept 68 | { 69 | return &buf_[ 70 | buf_size] - size_; 71 | } 72 | 73 | std::size_t 74 | size() const noexcept 75 | { 76 | return size_; 77 | } 78 | 79 | core::string_view 80 | str() const noexcept 81 | { 82 | return core::string_view( 83 | data(), size()); 84 | } 85 | 86 | operator 87 | core::string_view() const noexcept 88 | { 89 | return str(); 90 | } 91 | }; 92 | 93 | } // detail 94 | } // http_proto 95 | } // boost 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /src/detail/win32_unicode_path.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Mika Fischer (mika.fischer@zoopnet.de) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/boostorg/beast 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_DETAIL_WIN32_UNICODE_PATH_HPP 11 | #define BOOST_HTTP_PROTO_DETAIL_WIN32_UNICODE_PATH_HPP 12 | 13 | #ifdef _WIN32 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { 23 | namespace http_proto { 24 | namespace detail { 25 | 26 | class win32_unicode_path 27 | { 28 | using WCHAR_ = boost::winapi::WCHAR_; 29 | 30 | public: 31 | win32_unicode_path(const char* utf8_path, system::error_code& ec) { 32 | int ret = mb2wide(utf8_path, static_buf_.data(), 33 | static_buf_.size()); 34 | if (ret == 0) 35 | { 36 | int sz = mb2wide(utf8_path, nullptr, 0); 37 | if (sz == 0) 38 | { 39 | ec.assign(winapi::GetLastError(), 40 | system::system_category()); 41 | return; 42 | } 43 | dynamic_buf_.resize(sz); 44 | int ret2 = mb2wide(utf8_path, 45 | dynamic_buf_.data(), 46 | dynamic_buf_.size()); 47 | if (ret2 == 0) 48 | { 49 | ec.assign(winapi::GetLastError(), 50 | system::system_category()); 51 | return; 52 | } 53 | } 54 | } 55 | 56 | WCHAR_ const* c_str() const noexcept 57 | { 58 | return dynamic_buf_.empty() 59 | ? static_buf_.data() 60 | : dynamic_buf_.data(); 61 | } 62 | 63 | private: 64 | int mb2wide(const char* utf8_path, WCHAR_* buf, size_t sz) 65 | { 66 | return winapi::MultiByteToWideChar( 67 | winapi::CP_UTF8_, 68 | winapi::MB_ERR_INVALID_CHARS_, 69 | utf8_path, -1, 70 | buf, static_cast(sz)); 71 | } 72 | 73 | std::array static_buf_; 74 | std::vector dynamic_buf_; 75 | }; 76 | 77 | } // detail 78 | } // http_proto 79 | } // boost 80 | 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/fields.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Christian Mazakas 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // Official repository: https://github.com/cppalliance/http_proto 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | fields:: 22 | fields() noexcept 23 | : fields_view_base( 24 | &this->fields_base::h_) 25 | , fields_base( 26 | detail::kind::fields) 27 | { 28 | } 29 | 30 | fields:: 31 | fields( 32 | core::string_view s) 33 | : fields_view_base( 34 | &this->fields_base::h_) 35 | , fields_base( 36 | detail::kind::fields, s) 37 | { 38 | } 39 | 40 | fields:: 41 | fields( 42 | std::size_t storage_size) 43 | : fields_view_base(&this->fields_base::h_) 44 | , fields_base( 45 | detail::kind::fields, storage_size) 46 | { 47 | } 48 | 49 | fields:: 50 | fields( 51 | std::size_t storage_size, 52 | std::size_t max_storage_size) 53 | : fields_view_base(&this->fields_base::h_) 54 | , fields_base( 55 | detail::kind::fields, 56 | storage_size, max_storage_size) 57 | { 58 | } 59 | 60 | fields:: 61 | fields( 62 | fields&& other) noexcept 63 | : fields_view_base( 64 | &this->fields_base::h_) 65 | , fields_base(other.h_.kind) 66 | { 67 | swap(other); 68 | } 69 | 70 | fields:: 71 | fields( 72 | fields const& other) 73 | : fields_view_base( 74 | &this->fields_base::h_) 75 | , fields_base(*other.ph_) 76 | { 77 | } 78 | 79 | fields:: 80 | fields( 81 | fields_view const& other) 82 | : fields_view_base( 83 | &this->fields_base::h_) 84 | , fields_base(*other.ph_) 85 | { 86 | } 87 | 88 | fields& 89 | fields:: 90 | operator=( 91 | fields&& other) noexcept 92 | { 93 | fields tmp(std::move(other)); 94 | tmp.swap(*this); 95 | return *this; 96 | } 97 | 98 | } // http_proto 99 | } // boost 100 | -------------------------------------------------------------------------------- /src/file_body.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | 13 | namespace boost { 14 | namespace http_proto { 15 | 16 | file_body:: 17 | ~file_body() = default; 18 | 19 | file_body:: 20 | file_body( 21 | file_body&&) noexcept = default; 22 | 23 | file_body:: 24 | file_body( 25 | file&& f, 26 | std::uint64_t size) noexcept 27 | : f_(std::move(f)) 28 | , n_(size) 29 | { 30 | } 31 | 32 | auto 33 | file_body:: 34 | on_read( 35 | buffers::mutable_buffer b) -> 36 | source::results 37 | { 38 | source::results rv; 39 | if(n_ > 0) 40 | { 41 | std::size_t n; 42 | if( n_ >= b.size()) 43 | n = b.size(); 44 | else 45 | n = static_cast(n_); 46 | n = f_.read( 47 | b.data(), n, rv.ec); 48 | rv.bytes = n; 49 | n_ -= n; 50 | } 51 | rv.finished = n_ == 0; 52 | return rv; 53 | } 54 | 55 | auto 56 | file_body:: 57 | on_write( 58 | buffers::const_buffer b, bool) -> 59 | sink::results 60 | { 61 | sink::results rv; 62 | if(n_ > 0) 63 | { 64 | std::size_t n; 65 | if( n_ >= b.size()) 66 | n = b.size(); 67 | else 68 | n = static_cast(n_); 69 | n = f_.write( 70 | b.data(), n, rv.ec); 71 | rv.bytes = n; 72 | n_ -= n; 73 | } 74 | return rv; 75 | } 76 | 77 | } // http_proto 78 | } // boost 79 | -------------------------------------------------------------------------------- /src/header_limits.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace http_proto { 16 | 17 | std::size_t 18 | header_limits:: 19 | valid_space_needed() const 20 | { 21 | /* 22 | // "HTTP/1.1 200 OK\r\n\r\n" = 19 23 | // "X / HTTP/1.1\r\n" = 14 24 | // "HTTP/1.1 200\r\n" = 14 25 | // "X:\r\n" = 4 26 | 27 | // make sure `size` is big enough 28 | // to hold the largest default buffer: 29 | //if( max_size < 19) 30 | //max_size = 19; 31 | 32 | // max_size too small 33 | if( max_size < 19) 34 | detail::throw_invalid_argument(); 35 | 36 | // max_size too large 37 | if( max_size > 38 | BOOST_HTTP_PROTO_MAX_HEADER) 39 | detail::throw_invalid_argument(); 40 | 41 | // max_start_line too small 42 | if( max_start_line < 14) 43 | detail::throw_invalid_argument(); 44 | 45 | // max_start_line too large 46 | if( max_start_line > 47 | max_size - 2) 48 | detail::throw_invalid_argument(); 49 | 50 | // max_field too small 51 | if( max_field < 4) 52 | detail::throw_invalid_argument(); 53 | 54 | // max_field too large 55 | if( max_field > 56 | max_size) 57 | detail::throw_invalid_argument(); 58 | 59 | // max_fields too large 60 | if( max_fields > 61 | max_size / 4) 62 | detail::throw_invalid_argument(); 63 | */ 64 | static constexpr auto Align = 65 | alignof(detail::header::entry); 66 | // round up to alignof(A) 67 | return Align * ( 68 | (max_size + Align - 1) / Align) + ( 69 | max_fields * sizeof( 70 | detail::header::entry)); 71 | } 72 | 73 | } // http_proto 74 | } // boost 75 | -------------------------------------------------------------------------------- /src/message_view_base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | } // http_proto 16 | } // boost 17 | -------------------------------------------------------------------------------- /src/request.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Christian Mazakas 4 | // Copyright (c) 2025 Mohammad Nejati 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // Official repository: https://github.com/cppalliance/http_proto 10 | // 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace http_proto { 16 | 17 | request:: 18 | request() noexcept 19 | : fields_view_base( 20 | &this->fields_base::h_) 21 | , request_base() 22 | { 23 | } 24 | 25 | request:: 26 | request( 27 | core::string_view s) 28 | : fields_view_base( 29 | &this->fields_base::h_) 30 | , request_base(s) 31 | { 32 | } 33 | 34 | request:: 35 | request( 36 | std::size_t storage_size) 37 | : fields_view_base( 38 | &this->fields_base::h_) 39 | , request_base(storage_size) 40 | { 41 | } 42 | 43 | request:: 44 | request( 45 | std::size_t storage_size, 46 | std::size_t max_storage_size) 47 | : fields_view_base( 48 | &this->fields_base::h_) 49 | , request_base( 50 | storage_size, 51 | max_storage_size) 52 | { 53 | } 54 | 55 | request:: 56 | request( 57 | request&& other) noexcept 58 | : fields_view_base( 59 | &this->fields_base::h_) 60 | , request_base() 61 | { 62 | swap(other); 63 | } 64 | 65 | request:: 66 | request( 67 | request const& other) 68 | : fields_view_base( 69 | &this->fields_base::h_) 70 | , request_base(*other.ph_) 71 | { 72 | } 73 | 74 | request:: 75 | request( 76 | request_view const& other) 77 | : fields_view_base( 78 | &this->fields_base::h_) 79 | , request_base(*other.ph_) 80 | { 81 | } 82 | 83 | request& 84 | request:: 85 | operator=( 86 | request&& other) noexcept 87 | { 88 | request temp( 89 | std::move(other)); 90 | temp.swap(*this); 91 | return *this; 92 | } 93 | 94 | } // http_proto 95 | } // boost 96 | -------------------------------------------------------------------------------- /src/request_parser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | request_parser:: 16 | request_parser( 17 | context& ctx) 18 | : parser( 19 | ctx, 20 | detail::kind::request) 21 | { 22 | } 23 | 24 | request_view 25 | request_parser:: 26 | get() const 27 | { 28 | return request_view( 29 | safe_get_header()); 30 | } 31 | 32 | } // http_proto 33 | } // boost 34 | -------------------------------------------------------------------------------- /src/response.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // Copyright (c) 2024 Christian Mazakas 4 | // Copyright (c) 2025 Mohammad Nejati 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // Official repository: https://github.com/cppalliance/http_proto 10 | // 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | response:: 21 | response() noexcept 22 | : fields_view_base( 23 | &this->fields_base::h_) 24 | , response_base() 25 | { 26 | } 27 | 28 | response:: 29 | response( 30 | core::string_view s) 31 | : fields_view_base( 32 | &this->fields_base::h_) 33 | , response_base(s) 34 | { 35 | } 36 | 37 | response:: 38 | response( 39 | std::size_t storage_size) 40 | : fields_view_base( 41 | &this->fields_base::h_) 42 | , response_base(storage_size) 43 | { 44 | } 45 | 46 | response:: 47 | response( 48 | std::size_t storage_size, 49 | std::size_t max_storage_size) 50 | : fields_view_base( 51 | &this->fields_base::h_) 52 | , response_base( 53 | storage_size, max_storage_size) 54 | { 55 | } 56 | 57 | response:: 58 | response( 59 | response&& other) noexcept 60 | : response() 61 | { 62 | swap(other); 63 | } 64 | 65 | response:: 66 | response( 67 | response const& other) 68 | : fields_view_base( 69 | &this->fields_base::h_) 70 | , response_base(*other.ph_) 71 | { 72 | } 73 | 74 | response:: 75 | response( 76 | response_view const& other) 77 | : fields_view_base( 78 | &this->fields_base::h_) 79 | , response_base(*other.ph_) 80 | { 81 | } 82 | 83 | response& 84 | response:: 85 | operator=( 86 | response&& other) noexcept 87 | { 88 | response temp( 89 | std::move(other)); 90 | temp.swap(*this); 91 | return *this; 92 | } 93 | 94 | response:: 95 | response( 96 | http_proto::status sc) 97 | : response( 98 | sc, http_proto::version::http_1_1) 99 | { 100 | } 101 | 102 | response:: 103 | response( 104 | http_proto::status sc, 105 | http_proto::version v) 106 | : response() 107 | { 108 | if( sc != h_.res.status || 109 | v != h_.version) 110 | set_start_line(sc, v); 111 | } 112 | 113 | } // http_proto 114 | } // boost 115 | -------------------------------------------------------------------------------- /src/response_base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 Mohammad Nejati 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace http_proto { 16 | 17 | void 18 | response_base:: 19 | set_impl( 20 | http_proto::status sc, 21 | unsigned short si, 22 | core::string_view rs, 23 | http_proto::version v) 24 | { 25 | auto const vs = to_string(v); 26 | auto const new_prefix = 27 | vs.size() + 1 + // HTTP-version SP 28 | 3 + 1 + // status-code SP 29 | rs.size() + 2; // reason-phrase CRLF 30 | 31 | // Introduce a new scope so that prefix_op's 32 | // destructor runs before h_.on_start_line(). 33 | { 34 | auto op = prefix_op_t(*this, new_prefix, &rs); 35 | char* dest = h_.buf; 36 | 37 | h_.version = v; 38 | vs.copy(dest, vs.size()); 39 | dest += vs.size(); 40 | *dest++ = ' '; 41 | 42 | h_.res.status = sc; 43 | h_.res.status_int = si; 44 | dest[0] = '0' + ((h_.res.status_int / 100) % 10); 45 | dest[1] = '0' + ((h_.res.status_int / 10) % 10); 46 | dest[2] = '0' + ((h_.res.status_int / 1) % 10); 47 | dest[3] = ' '; 48 | dest += 4; 49 | 50 | std::memmove(dest, rs.data(), rs.size()); 51 | dest += rs.size(); 52 | dest[0] = '\r'; 53 | dest[1] = '\n'; 54 | } 55 | 56 | h_.on_start_line(); 57 | } 58 | 59 | } // http_proto 60 | } // boost 61 | -------------------------------------------------------------------------------- /src/response_parser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | response_parser:: 16 | response_parser( 17 | context& ctx) 18 | : parser( 19 | ctx, 20 | detail::kind::response) 21 | { 22 | } 23 | 24 | response_view 25 | response_parser:: 26 | get() const 27 | { 28 | return response_view( 29 | safe_get_header()); 30 | } 31 | 32 | } // http_proto 33 | } // boost 34 | -------------------------------------------------------------------------------- /src/rfc/combine_field_values.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | core::string_view 16 | combine_field_values( 17 | fields_view_base::subrange const& vr, 18 | grammar::recycled_ptr& temp) 19 | { 20 | core::string_view result; 21 | bool acquired = false; 22 | for(auto s : vr) 23 | { 24 | if(s.empty()) 25 | continue; 26 | if(result.empty()) 27 | { 28 | result = s; 29 | } 30 | else if(! acquired) 31 | { 32 | acquired = true; 33 | if(temp.empty()) 34 | temp.acquire(); 35 | temp->clear(); 36 | temp->reserve( 37 | result.size() + 38 | 1 + s.size()); 39 | *temp = result; 40 | temp->push_back(','); 41 | temp->append( 42 | s.data(), s.size()); 43 | result = *temp; 44 | } 45 | else 46 | { 47 | temp->reserve( 48 | temp->size() + 49 | 1 + s.size()); 50 | temp->push_back(','); 51 | temp->append( 52 | s.data(), s.size()); 53 | result = *temp; 54 | } 55 | } 56 | return result; 57 | } 58 | 59 | } // http_proto 60 | } // boost 61 | -------------------------------------------------------------------------------- /src/rfc/detail/rules.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 Christian Mazakas 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP 11 | #define BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP 12 | 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace http_proto 19 | { 20 | namespace detail 21 | { 22 | 23 | // header-field = field-name ":" OWS field-value OWS 24 | struct field_name_rule_t 25 | { 26 | using value_type = core::string_view; 27 | 28 | system::result 29 | parse( 30 | char const*& it, 31 | char const* end) const noexcept; 32 | }; 33 | 34 | constexpr field_name_rule_t field_name_rule{}; 35 | 36 | struct field_value_rule_t 37 | { 38 | struct value_type 39 | { 40 | core::string_view value; 41 | // detected occurrence of `\r\n `, `\r\n\t` 42 | bool has_obs_fold = false; 43 | // detected `\r\nX`, attempt at field termination 44 | bool has_crlf = false; 45 | }; 46 | 47 | system::result 48 | parse( 49 | char const*& it, 50 | char const* end) const noexcept; 51 | }; 52 | 53 | constexpr field_value_rule_t field_value_rule{}; 54 | 55 | } // namespace detail 56 | } // namespace http_proto 57 | } // namespace boost 58 | 59 | 60 | 61 | #endif // BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP 62 | -------------------------------------------------------------------------------- /src/rfc/parameter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | 13 | namespace boost { 14 | namespace http_proto { 15 | 16 | auto 17 | parameter_rule_t:: 18 | parse( 19 | char const*& it, 20 | char const* end) const noexcept -> 21 | system::result 22 | { 23 | (void)it; 24 | (void)end; 25 | return system::error_code{}; 26 | } 27 | 28 | } // http_proto 29 | } // boost 30 | -------------------------------------------------------------------------------- /src/rfc/quoted_token_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | namespace detail { 22 | 23 | struct obs_text 24 | { 25 | constexpr 26 | bool 27 | operator()(char ch) const noexcept 28 | { 29 | return static_cast< 30 | unsigned char>(ch) >= 0x80; 31 | } 32 | }; 33 | 34 | struct qdtext 35 | { 36 | constexpr 37 | bool 38 | operator()(char ch) const noexcept 39 | { 40 | return 41 | ch == '\t' || 42 | ch == ' ' || 43 | ch == 0x21 || 44 | (ch >= 0x23 && ch <= 0x5b) || 45 | (ch >= 0x5d && ch <= 0x7e) || 46 | static_cast(ch) >= 0x80; 47 | } 48 | }; 49 | 50 | // qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text 51 | constexpr grammar::lut_chars qdtext_chars(qdtext{}); 52 | 53 | // qpchars = ( HTAB / SP / VCHAR / obs-text ) 54 | constexpr auto qpchars = 55 | grammar::lut_chars(grammar::vchars) + 56 | grammar::lut_chars(obs_text{}) + '\t' + ' '; 57 | 58 | } // detail 59 | 60 | //------------------------------------------------ 61 | 62 | auto 63 | quoted_token_rule_t:: 64 | parse( 65 | char const*& it, 66 | char const* end) const noexcept -> 67 | system::result 68 | { 69 | if(it == end) 70 | { 71 | BOOST_HTTP_PROTO_RETURN_EC( 72 | grammar::error::need_more); 73 | } 74 | if(*it != '\"') 75 | { 76 | // token 77 | auto rv = grammar::parse( 78 | it, end, token_rule); 79 | if(rv.has_value()) 80 | return quoted_token_view(*rv); 81 | return rv.error(); 82 | } 83 | // quoted-string 84 | auto const it0 = it++; 85 | std::size_t n = 0; 86 | for(;;) 87 | { 88 | auto it1 = it; 89 | it = grammar::find_if_not( 90 | it, end, detail::qdtext_chars); 91 | if(it == end) 92 | { 93 | BOOST_HTTP_PROTO_RETURN_EC( 94 | grammar::error::need_more); 95 | } 96 | n += static_cast(it - it1); 97 | if(*it == '\"') 98 | break; 99 | if(*it != '\\') 100 | { 101 | BOOST_HTTP_PROTO_RETURN_EC( 102 | grammar::error::syntax); 103 | } 104 | ++it; 105 | if(it == end) 106 | { 107 | BOOST_HTTP_PROTO_RETURN_EC( 108 | grammar::error::need_more); 109 | } 110 | if(! detail::qpchars(*it)) 111 | { 112 | BOOST_HTTP_PROTO_RETURN_EC( 113 | grammar::error::syntax); 114 | } 115 | ++it; 116 | ++n; 117 | } 118 | return value_type(core::string_view( 119 | it0, ++it - it0), n); 120 | } 121 | 122 | } // http_proto 123 | } // boost 124 | -------------------------------------------------------------------------------- /src/rfc/transfer_encoding_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RFC_TRANSFER_ENCODING_RULE_HPP 11 | #define BOOST_HTTP_PROTO_RFC_TRANSFER_ENCODING_RULE_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | namespace detail { 22 | 23 | //------------------------------------------------ 24 | 25 | /** A value of Transfer-Encoding 26 | */ 27 | struct transfer_encoding 28 | { 29 | enum coding 30 | { 31 | unknown = 0, 32 | chunked, 33 | compress, 34 | deflate, 35 | gzip 36 | }; 37 | 38 | struct param 39 | { 40 | core::string_view key; 41 | quoted_token_view value; 42 | }; 43 | 44 | coding id = unknown; 45 | core::string_view str; 46 | grammar::range params; 47 | }; 48 | 49 | //------------------------------------------------ 50 | 51 | /** Rule to match transfer-coding 52 | 53 | @par Value Type 54 | @code 55 | using value_type = transfer_encoding; 56 | @endcode 57 | 58 | @par Example 59 | @code 60 | @endcode 61 | 62 | @par BNF 63 | @code 64 | transfer-coding = "chunked" 65 | / "compress" 66 | / "deflate" 67 | / "gzip" 68 | / transfer-extension 69 | transfer-extension = token *( OWS ";" OWS transfer-parameter ) 70 | transfer-parameter = token BWS "=" BWS ( token / quoted-string ) 71 | @endcode 72 | 73 | @par Specification 74 | @li 3.3.1. Transfer-Encoding (rfc7230) 76 | */ 77 | #ifdef BOOST_HTTP_PROTO_DOCS 78 | constexpr __implementation_defined__ transfer_encoding_rule; 79 | #else 80 | struct transfer_encoding_rule_t 81 | { 82 | using value_type = transfer_encoding; 83 | 84 | BOOST_HTTP_PROTO_DECL 85 | auto 86 | parse( 87 | char const*& it, 88 | char const* end) const noexcept -> 89 | system::result; 90 | }; 91 | 92 | constexpr transfer_encoding_rule_t transfer_encoding_rule_impl{}; 93 | #endif 94 | 95 | //------------------------------------------------ 96 | 97 | /** Rule matching the Transfer-Encoding field value 98 | 99 | @par Value Type 100 | @code 101 | using value_type = grammar::range< transfer_encoding >; 102 | @endcode 103 | 104 | @par Example 105 | @code 106 | @endcode 107 | 108 | @par BNF 109 | @code 110 | Transfer-Encoding = 1#transfer-coding 111 | @endcode 112 | 113 | @par Specification 114 | @li 3.3.1. Transfer-Encoding (rfc7230) 116 | */ 117 | constexpr auto transfer_encoding_rule = 118 | list_rule( transfer_encoding_rule_impl, 1 ); 119 | 120 | } // detail 121 | } // http_proto 122 | } // boost 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /src/rfc/upgrade_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | auto 19 | upgrade_protocol_rule_t:: 20 | parse( 21 | char const*& it, 22 | char const* end) const noexcept -> 23 | system::result 24 | { 25 | value_type t; 26 | // token 27 | { 28 | auto rv = grammar::parse( 29 | it, end, token_rule); 30 | if(! rv) 31 | return rv.error(); 32 | t.name = *rv; 33 | } 34 | // [ "/" token ] 35 | if( it == end || 36 | *it != '/') 37 | return t; 38 | ++it; 39 | auto rv = grammar::parse( 40 | it, end, token_rule); 41 | if(! rv) 42 | return rv.error(); 43 | t.version = *rv; 44 | return t; 45 | } 46 | 47 | } // http_proto 48 | } // boost 49 | -------------------------------------------------------------------------------- /src/service/service.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | service:: 16 | ~service() = default; 17 | 18 | } // http_proto 19 | } // boost 20 | -------------------------------------------------------------------------------- /src/service/zlib_service.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 Mohammad Nejati 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | namespace zlib { 15 | namespace detail { 16 | 17 | const char* 18 | error_cat_type:: 19 | name() const noexcept 20 | { 21 | return "boost.http.proto.zlib"; 22 | } 23 | 24 | bool 25 | error_cat_type:: 26 | failed(int ev) const noexcept 27 | { 28 | return ev < 0; 29 | } 30 | 31 | std::string 32 | error_cat_type:: 33 | message(int ev) const 34 | { 35 | return message(ev, nullptr, 0); 36 | } 37 | 38 | char const* 39 | error_cat_type:: 40 | message( 41 | int ev, 42 | char*, 43 | std::size_t) const noexcept 44 | { 45 | switch(static_cast(ev)) 46 | { 47 | case error::ok: return "Z_OK"; 48 | case error::stream_end: return "Z_STREAM_END"; 49 | case error::need_dict: return "Z_NEED_DICT"; 50 | case error::errno_: return "Z_ERRNO"; 51 | case error::stream_err: return "Z_STREAM_ERROR"; 52 | case error::data_err: return "Z_DATA_ERROR"; 53 | case error::mem_err: return "Z_MEM_ERROR"; 54 | case error::buf_err: return "Z_BUF_ERROR"; 55 | case error::version_err: return "Z_VERSION_ERROR"; 56 | default: 57 | return "unknown"; 58 | } 59 | } 60 | 61 | // msvc 14.0 has a bug that warns about inability 62 | // to use constexpr construction here, even though 63 | // there's no constexpr construction 64 | #if defined(_MSC_VER) && _MSC_VER <= 1900 65 | # pragma warning( push ) 66 | # pragma warning( disable : 4592 ) 67 | #endif 68 | 69 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L 70 | constinit error_cat_type error_cat; 71 | #else 72 | error_cat_type error_cat; 73 | #endif 74 | 75 | #if defined(_MSC_VER) && _MSC_VER <= 1900 76 | # pragma warning( pop ) 77 | #endif 78 | 79 | } // detail 80 | } // zlib 81 | } // http_proto 82 | } // boost 83 | -------------------------------------------------------------------------------- /src/sink.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | auto 16 | sink:: 17 | on_write( 18 | buffers::const_buffer_span bs, 19 | bool more) -> 20 | results 21 | { 22 | auto it = bs.begin(); 23 | auto const end_ = bs.end(); 24 | results rv; 25 | if(it == end_) 26 | return rv; 27 | do 28 | { 29 | buffers::const_buffer b(*it++); 30 | rv += on_write(b, 31 | it != end_ || 32 | more); 33 | if(rv.ec.failed()) 34 | return rv; 35 | } 36 | while(it != end_); 37 | return rv; 38 | } 39 | 40 | } // http_proto 41 | } // boost 42 | -------------------------------------------------------------------------------- /src/source.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/buffers 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace http_proto { 16 | 17 | auto 18 | source:: 19 | on_read( 20 | buffers::mutable_buffer_span bs) -> 21 | results 22 | { 23 | results rv; 24 | auto it = bs.begin(); 25 | auto const end_ = bs.end(); 26 | if(it == end_) 27 | return rv; 28 | do 29 | { 30 | buffers::mutable_buffer b(*it++); 31 | rv += on_read(b); 32 | if(rv.ec.failed()) 33 | return rv; 34 | if(rv.finished) 35 | break; 36 | } 37 | while(it != end_); 38 | return rv; 39 | } 40 | 41 | } // http_proto 42 | } // boost 43 | -------------------------------------------------------------------------------- /src/version.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | 13 | namespace boost { 14 | namespace http_proto { 15 | 16 | core::string_view 17 | to_string( 18 | version v) noexcept 19 | { 20 | switch(v) 21 | { 22 | case version::http_1_0: 23 | return "HTTP/1.0"; 24 | default: 25 | case version::http_1_1: 26 | return "HTTP/1.1"; 27 | } 28 | } 29 | 30 | std::ostream& 31 | operator<<( 32 | std::ostream& os, 33 | version v) 34 | { 35 | os << to_string(v); 36 | return os; 37 | } 38 | 39 | } // http_proto 40 | } // boost 41 | -------------------------------------------------------------------------------- /src_brotli/src_brotli.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/CPPAlliance/http_proto 8 | // 9 | 10 | #include 11 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/cppalliance/http_proto 8 | # 9 | 10 | if(NOT TARGET tests) 11 | add_custom_target(tests) 12 | set_property(TARGET tests PROPERTY FOLDER Dependencies) 13 | endif() 14 | 15 | if(NOT BUILD_SHARED_LIBS) 16 | add_subdirectory(limits) 17 | endif() 18 | add_subdirectory(unit) 19 | -------------------------------------------------------------------------------- /test/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/CPPAlliance/http_proto 8 | # 9 | 10 | build-project limits ; 11 | build-project unit ; 12 | -------------------------------------------------------------------------------- /test/cmake_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 Christian Mazakas 3 | # Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com) 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # https://www.boost.org/LICENSE_1_0.txt 7 | # 8 | 9 | cmake_minimum_required(VERSION 3.5...3.16) 10 | 11 | project(cmake_subdir_test LANGUAGES CXX) 12 | set(__ignore__ ${CMAKE_C_COMPILER}) 13 | set(__ignore__ ${CMAKE_C_FLAGS}) 14 | 15 | if(BOOST_CI_INSTALL_TEST) 16 | find_package(Boost CONFIG REQUIRED COMPONENTS http_proto) 17 | else() 18 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 19 | add_subdirectory(../.. boostorg/http_proto) 20 | 21 | set(BOOST_URL_BUILD_TESTS OFF CACHE BOOL "" FORCE) 22 | 23 | set(deps 24 | # Primary dependencies 25 | 26 | assert 27 | buffers 28 | config 29 | container_hash 30 | core 31 | mp11 32 | static_assert 33 | system 34 | throw_exception 35 | type_traits 36 | url 37 | winapi 38 | 39 | # Secondary dependencies 40 | 41 | describe 42 | variant2 43 | align 44 | optional 45 | predef 46 | detail 47 | utility 48 | preprocessor 49 | io 50 | ) 51 | 52 | foreach(dep IN LISTS deps) 53 | add_subdirectory(../../../${dep} boostorg/${dep} EXCLUDE_FROM_ALL) 54 | endforeach() 55 | endif() 56 | 57 | add_executable(main main.cpp) 58 | target_link_libraries(main Boost::http_proto) 59 | 60 | enable_testing() 61 | add_test(NAME main COMMAND main) 62 | add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) 63 | -------------------------------------------------------------------------------- /test/cmake_test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | boost::http_proto::request request; 5 | request.set_payload_size(1337); 6 | if (request.payload_size() != 1337) { 7 | throw; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/limits/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/cppalliance/http_proto 8 | # 9 | 10 | set(TEST_MAIN ../../../url/extra/test_main.cpp) 11 | 12 | file(GLOB_RECURSE LIMITS_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.cpp) 13 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES limits.cpp Jamfile) 14 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/../../../url/extra PREFIX "_extra" FILES ${TEST_MAIN}) 15 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/../../src PREFIX "_extra" FILES ${LIMITS_SOURCES}) 16 | add_executable(boost_http_proto_limits limits.cpp Jamfile ${TEST_MAIN} ${LIMITS_SOURCES}) 17 | target_include_directories(boost_http_proto_limits PRIVATE ../../) 18 | target_include_directories(boost_http_proto_limits PRIVATE ../../include ../../../url/extra ../../..) 19 | target_compile_definitions(boost_http_proto_limits PRIVATE 20 | BOOST_HTTP_PROTO_MAX_HEADER=20 21 | BOOST_HTTP_PROTO_NO_LIB=1 22 | BOOST_HTTP_PROTO_STATIC_LINK 23 | ) 24 | target_link_libraries(boost_http_proto_limits PRIVATE 25 | Boost::align 26 | Boost::assert 27 | Boost::buffers 28 | Boost::config 29 | Boost::container_hash 30 | Boost::system 31 | Boost::throw_exception 32 | Boost::url 33 | Boost::utility) 34 | 35 | target_link_libraries(boost_http_proto_limits INTERFACE Boost::http_proto) 36 | 37 | if (ZLIB_FOUND) 38 | target_link_libraries(boost_http_proto_limits INTERFACE ZLIB::ZLIB) 39 | endif() 40 | 41 | add_test(NAME boost_http_proto_limits COMMAND boost_http_proto_limits) 42 | add_dependencies(tests boost_http_proto_limits) 43 | -------------------------------------------------------------------------------- /test/limits/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/CPPAlliance/http_proto 8 | # 9 | 10 | import testing ; 11 | 12 | project 13 | : requirements 14 | $(c11-requires) 15 | ../../../url/extra/test_main.cpp 16 | . 17 | ../.. 18 | ../../../url/extra 19 | /boost//buffers 20 | /boost//url 21 | ; 22 | 23 | run limits.cpp ../../../url/extra/test_main.cpp /boost/http_proto//http_proto_sources 24 | : requirements 25 | BOOST_HTTP_PROTO_MAX_HEADER=20 26 | BOOST_HTTP_PROTO_NO_LIB 27 | BOOST_HTTP_PROTO_STATIC_LINK 28 | /boost//buffers 29 | /boost//url 30 | static 31 | ; 32 | -------------------------------------------------------------------------------- /test/limits/limits.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "test_suite.hpp" 15 | 16 | #include 17 | #include 18 | 19 | // These ensure that limits is compiled correctly 20 | #if \ 21 | defined(BOOST_HTTP_PROTO_DYN_LINK) || \ 22 | ( defined(BOOST_ALL_DYN_LINK) && ! defined(BOOST_HTTP_PROTO_STATIC_LINK) ) 23 | #error "Limits should not be built with shared linking." 24 | #endif 25 | 26 | namespace boost { 27 | namespace http_proto { 28 | 29 | // This has to be at least 19 because 30 | // of the default request buffer. 31 | static_assert(max_offset == 20, "max_offset != 20"); 32 | 33 | class limits_test 34 | { 35 | public: 36 | void 37 | testLimits() 38 | { 39 | { 40 | request req; 41 | BOOST_TEST_THROWS( 42 | req.set_start_line( 43 | method::connect, 44 | "https://www.example.com", 45 | version::http_1_1), 46 | std::length_error); 47 | } 48 | } 49 | 50 | void 51 | testFields() 52 | { 53 | // reserve 54 | { 55 | { 56 | fields f; 57 | BOOST_TEST_NO_THROW( 58 | f.reserve_bytes(0)); 59 | } 60 | { 61 | fields f; 62 | BOOST_TEST_NO_THROW( 63 | f.reserve_bytes(max_offset)); 64 | } 65 | { 66 | fields f; 67 | BOOST_TEST_NO_THROW(f.reserve_bytes( 68 | f.max_capacity_in_bytes())); 69 | } 70 | { 71 | fields f; 72 | BOOST_TEST_THROWS( 73 | f.reserve_bytes(max_offset + 1), 74 | std::length_error); 75 | } 76 | { 77 | fields f; 78 | BOOST_TEST_THROWS(f.reserve_bytes( 79 | f.max_capacity_in_bytes() + 1), 80 | std::length_error); 81 | } 82 | } 83 | 84 | // append 85 | { 86 | fields f; 87 | std::string s; 88 | s.append(max_offset, 'x'); 89 | BOOST_TEST_THROWS( 90 | f.append(s, "v"), 91 | std::length_error); 92 | } 93 | 94 | // set 95 | { 96 | fields f; 97 | BOOST_TEST_THROWS( 98 | f.set("x", 99 | "0123456789" 100 | "0123456789"), 101 | std::length_error); 102 | } 103 | } 104 | 105 | void 106 | run() 107 | { 108 | testLimits(); 109 | testFields(); 110 | } 111 | }; 112 | 113 | TEST_SUITE( 114 | limits_test, 115 | "boost.http_proto.limits"); 116 | 117 | } // http_proto 118 | } // boost 119 | -------------------------------------------------------------------------------- /test/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/cppalliance/http_proto 8 | # 9 | 10 | set(EXTRAFILES 11 | ../../../url/extra/test_main.cpp 12 | ../../../url/extra/test_suite.hpp 13 | ./test_helpers.hpp 14 | ./test_helpers.cpp 15 | ) 16 | 17 | file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS *.cpp *.hpp) 18 | list(APPEND PFILES 19 | CMakeLists.txt 20 | Jamfile 21 | ) 22 | 23 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES}) 24 | source_group("_extra" FILES ${EXTRAFILES}) 25 | add_executable(boost_http_proto_tests ${PFILES} ${EXTRAFILES}) 26 | target_include_directories(boost_http_proto_tests PRIVATE . ../../../url/extra) 27 | target_link_libraries(boost_http_proto_tests PRIVATE Boost::filesystem) 28 | 29 | if (ZLIB_FOUND) 30 | target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto_zlib ZLIB::ZLIB) 31 | else () 32 | target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto) 33 | endif () 34 | 35 | add_test(NAME boost_http_proto_tests COMMAND boost_http_proto_tests) 36 | add_dependencies(tests boost_http_proto_tests) 37 | -------------------------------------------------------------------------------- /test/unit/Jamfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | # 7 | # Official repository: https://github.com/CPPAlliance/http_proto 8 | # 9 | 10 | import testing ; 11 | import ac ; 12 | 13 | using zlib ; 14 | 15 | project 16 | : requirements 17 | $(c11-requires) 18 | /boost/http_proto//boost_http_proto 19 | [ ac.check-library /boost/http_proto//boost_http_proto_zlib : /boost/http_proto//boost_http_proto_zlib : ] 20 | ../../../url/extra/test_main.cpp 21 | ./test_helpers.cpp 22 | . 23 | ../../../url/extra 24 | extra 25 | on 26 | darwin,norecover:static 27 | ; 28 | 29 | local SOURCES = 30 | context.cpp 31 | error.cpp 32 | field.cpp 33 | fields.cpp 34 | fields_base.cpp 35 | fields_view.cpp 36 | fields_view_base.cpp 37 | file.cpp 38 | file_base.cpp 39 | file_body.cpp 40 | header_limits.cpp 41 | http_proto.cpp 42 | message_base.cpp 43 | message_view_base.cpp 44 | metadata.cpp 45 | method.cpp 46 | parser.cpp 47 | request.cpp 48 | request_parser.cpp 49 | request_view.cpp 50 | response.cpp 51 | response_parser.cpp 52 | response_view.cpp 53 | sandbox.cpp 54 | serializer.cpp 55 | sink.cpp 56 | source.cpp 57 | static_fields.cpp 58 | static_request.cpp 59 | static_response.cpp 60 | status.cpp 61 | string_body.cpp 62 | test_helpers.cpp 63 | version.cpp 64 | zlib.cpp 65 | rfc/combine_field_values.cpp 66 | rfc/list_rule.cpp 67 | rfc/parameter.cpp 68 | rfc/quoted_token_rule.cpp 69 | rfc/quoted_token_view.cpp 70 | rfc/token_rule.cpp 71 | rfc/transfer_encoding_rule.cpp 72 | rfc/detail/rules.cpp 73 | service/service.cpp 74 | service/zlib_service.cpp 75 | service/virtual_service.cpp 76 | ; 77 | 78 | for local f in $(SOURCES) 79 | { 80 | # run $(f) : : : ; 81 | run $(f) : target-name $(f:B)_ ; 82 | } 83 | 84 | local FILE_TESTS = 85 | file_posix.cpp 86 | file_stdio.cpp 87 | file_win32.cpp 88 | ; 89 | 90 | for local f in $(FILE_TESTS) 91 | { 92 | run $(f) /boost/filesystem//boost_filesystem 93 | : : : off norecover:static 94 | : $(f:B)_ ; 95 | } 96 | -------------------------------------------------------------------------------- /test/unit/context.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct context_test 19 | { 20 | void 21 | testContext() 22 | { 23 | // default construction 24 | { 25 | context ctx; 26 | } 27 | } 28 | 29 | void 30 | run() 31 | { 32 | testContext(); 33 | } 34 | }; 35 | 36 | TEST_SUITE( 37 | context_test, 38 | "boost.http_proto.context"); 39 | 40 | } // http_proto 41 | } // boost 42 | -------------------------------------------------------------------------------- /test/unit/fields_view.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include 14 | 15 | #include "test_helpers.hpp" 16 | 17 | #include 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | struct fields_view_test 23 | { 24 | void 25 | testSpecial() 26 | { 27 | // fields_view() 28 | { 29 | fields_view fv; 30 | } 31 | 32 | // fields_view(fields_view const&) 33 | { 34 | { 35 | fields_view f1; 36 | fields_view f2(f1); 37 | (void)f2; 38 | } 39 | } 40 | 41 | // operator=(fields_view const&) 42 | { 43 | { 44 | fields_view f1; 45 | fields_view f2; 46 | f1 = f2; 47 | } 48 | } 49 | } 50 | 51 | void 52 | run() 53 | { 54 | testSpecial(); 55 | } 56 | }; 57 | 58 | TEST_SUITE( 59 | fields_view_test, 60 | "boost.http_proto.fields_view"); 61 | 62 | } // http_proto 63 | } // boost 64 | -------------------------------------------------------------------------------- /test/unit/file.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/file_base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/file_body.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct file_body_test 19 | { 20 | void 21 | run() 22 | { 23 | } 24 | }; 25 | 26 | TEST_SUITE( 27 | file_body_test, 28 | "boost.http_proto.file_body"); 29 | 30 | } // http_proto 31 | } // boost 32 | -------------------------------------------------------------------------------- /test/unit/file_posix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #if BOOST_HTTP_PROTO_USE_POSIX_FILE 14 | 15 | #include "file_test.hpp" 16 | #include "test_suite.hpp" 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | class file_posix_test 22 | { 23 | public: 24 | void 25 | run() 26 | { 27 | test_file(); 28 | } 29 | }; 30 | 31 | TEST_SUITE( 32 | file_posix_test, 33 | "boost.http_proto.file_posix"); 34 | 35 | } // http_proto 36 | } // boost 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /test/unit/file_stdio.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include 14 | 15 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || \ 16 | defined(__CYGWIN__) 17 | #define BOOST_HTTP_PROTO_IS_WIN 18 | #endif 19 | 20 | #if defined(BOOST_NO_RTTI) && defined(BOOST_HTTP_PROTO_IS_WIN) && \ 21 | defined(BOOST_GCC) 22 | 23 | #include 24 | 25 | BOOST_PRAGMA_MESSAGE("skipping file_stdio_ tests for this configuration") 26 | 27 | #else 28 | 29 | #include "file_test.hpp" 30 | #include "test_suite.hpp" 31 | 32 | namespace boost { 33 | namespace http_proto { 34 | 35 | class file_stdio_test 36 | { 37 | public: 38 | void 39 | run() 40 | { 41 | #ifdef BOOST_MSVC 42 | test_file(); 43 | #else 44 | test_file(); 45 | #endif 46 | } 47 | }; 48 | 49 | TEST_SUITE( 50 | file_stdio_test, 51 | "boost.http_proto.file_stdio"); 52 | } // http_proto 53 | } // boost 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /test/unit/file_win32.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || \ 14 | defined(__CYGWIN__) 15 | #define BOOST_HTTP_PROTO_IS_WIN 16 | #endif 17 | 18 | #if defined(BOOST_NO_RTTI) && defined(BOOST_HTTP_PROTO_IS_WIN) && \ 19 | defined(BOOST_GCC) 20 | 21 | #include 22 | 23 | BOOST_PRAGMA_MESSAGE("skipping file_win32_ tests for this configuration") 24 | 25 | #else 26 | 27 | #if BOOST_HTTP_PROTO_USE_WIN32_FILE 28 | 29 | #include "file_test.hpp" 30 | #include "test_suite.hpp" 31 | 32 | namespace boost { 33 | namespace http_proto { 34 | 35 | class file_win32_test 36 | { 37 | public: 38 | void 39 | run() 40 | { 41 | test_file(); 42 | } 43 | }; 44 | 45 | TEST_SUITE( 46 | file_win32_test, 47 | "boost.http_proto.file_win32"); 48 | 49 | } // http_proto 50 | } // boost 51 | 52 | #endif // BOOST_HTTP_PROTO_USE_WIN32_FILE 53 | #endif 54 | -------------------------------------------------------------------------------- /test/unit/header_limits.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct header_limits_test 19 | { 20 | void 21 | testSpecial() 22 | { 23 | // header_limits(); 24 | { 25 | header_limits lim; 26 | (void)lim; 27 | } 28 | } 29 | 30 | void 31 | run() 32 | { 33 | testSpecial(); 34 | } 35 | }; 36 | 37 | TEST_SUITE( 38 | header_limits_test, 39 | "boost.http_proto.header_limits"); 40 | 41 | } // http_proto 42 | } // boost 43 | -------------------------------------------------------------------------------- /test/unit/http_proto.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/message_base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/message_view_base.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/method.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | class method_test 19 | { 20 | public: 21 | void 22 | testVerb() 23 | { 24 | auto const good = 25 | [&](method v) 26 | { 27 | BOOST_TEST(string_to_method( 28 | to_string(v)) == v); 29 | }; 30 | 31 | good(method::unknown); 32 | 33 | good(method::delete_); 34 | good(method::get); 35 | good(method::head); 36 | good(method::post); 37 | good(method::put); 38 | good(method::connect); 39 | good(method::options); 40 | good(method::trace); 41 | good(method::copy); 42 | good(method::lock); 43 | good(method::mkcol); 44 | good(method::move); 45 | good(method::propfind); 46 | good(method::proppatch); 47 | good(method::search); 48 | good(method::unlock); 49 | good(method::bind); 50 | good(method::rebind); 51 | good(method::unbind); 52 | good(method::acl); 53 | good(method::report); 54 | good(method::mkactivity); 55 | good(method::checkout); 56 | good(method::merge); 57 | good(method::msearch); 58 | good(method::notify); 59 | good(method::subscribe); 60 | good(method::unsubscribe); 61 | good(method::patch); 62 | good(method::purge); 63 | good(method::mkcalendar); 64 | good(method::link); 65 | good(method::unlink); 66 | 67 | auto const bad = 68 | [&](core::string_view s) 69 | { 70 | auto const v = string_to_method(s); 71 | BOOST_TEST(v == method::unknown); 72 | }; 73 | 74 | bad("AC_"); 75 | bad("BIN_"); 76 | bad("CHECKOU_"); 77 | bad("CONNEC_"); 78 | bad("COP_"); 79 | bad("DELET_"); 80 | bad("GE_"); 81 | bad("HEA_"); 82 | bad("LIN_"); 83 | bad("LOC_"); 84 | bad("M-SEARC_"); 85 | bad("MERG_"); 86 | bad("MKACTIVIT_"); 87 | bad("MKCALENDA_"); 88 | bad("MKCO_"); 89 | bad("MOV_"); 90 | bad("NOTIF_"); 91 | bad("OPTION_"); 92 | bad("PATC_"); 93 | bad("POS_"); 94 | bad("PROPFIN_"); 95 | bad("PROPPATC_"); 96 | bad("PURG_"); 97 | bad("PU_"); 98 | bad("REBIN_"); 99 | bad("REPOR_"); 100 | bad("SEARC_"); 101 | bad("SUBSCRIB_"); 102 | bad("TRAC_"); 103 | bad("UNBIN_"); 104 | bad("UNLIN_"); 105 | bad("UNLOC_"); 106 | bad("UNSUBSCRIB_"); 107 | 108 | try 109 | { 110 | to_string(static_cast(-1)); 111 | BOOST_TEST_FAIL(); 112 | } 113 | catch(std::exception const&) 114 | { 115 | BOOST_TEST_PASS(); 116 | } 117 | } 118 | 119 | void 120 | run() 121 | { 122 | testVerb(); 123 | } 124 | }; 125 | 126 | TEST_SUITE(method_test, "boost.http_proto.method"); 127 | 128 | } // http_proto 129 | } // boost 130 | -------------------------------------------------------------------------------- /test/unit/natvis.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "test_suite.hpp" 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | struct natvis_test 23 | { 24 | void 25 | run() 26 | { 27 | { 28 | request req( 29 | "GET / HTTP/1.1\r\n" 30 | "Connection: keep-alive\r\n" 31 | "Server: localhost\r\n" 32 | "\r\n"); 33 | request_view rv(req); 34 | } 35 | { 36 | std::error_condition ec(std::errc::address_in_use); 37 | response res( 38 | "HTTP/1.1 200 OK\r\n" 39 | "Connection: keep-alive\r\n" 40 | "Server: localhost\r\n" 41 | "\r\n"); 42 | response_view rv(res); 43 | } 44 | } 45 | }; 46 | 47 | TEST_SUITE(natvis_test, "boost.http_proto.natvis"); 48 | 49 | } // http_proto 50 | } // boost 51 | -------------------------------------------------------------------------------- /test/unit/request_view.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | class request_view_test 19 | { 20 | public: 21 | void 22 | run() 23 | { 24 | // request_view() 25 | { 26 | request_view req; 27 | } 28 | 29 | // request_view(request_view const&) 30 | { 31 | { 32 | request_view req1; 33 | request_view req2(req1); 34 | } 35 | } 36 | 37 | // operator=(request_view const&) 38 | { 39 | { 40 | request_view req1; 41 | request_view req2; 42 | req1 = req2; 43 | } 44 | } 45 | } 46 | }; 47 | 48 | TEST_SUITE( 49 | request_view_test, 50 | "boost.http_proto.request_view"); 51 | 52 | } // http_proto 53 | } // boost 54 | 55 | -------------------------------------------------------------------------------- /test/unit/response_parser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include 14 | 15 | #include "test_suite.hpp" 16 | 17 | namespace boost { 18 | namespace http_proto { 19 | 20 | class response_parser_test 21 | { 22 | public: 23 | void 24 | testSpecial() 25 | { 26 | // response_parser(context&) 27 | { 28 | context ctx; 29 | response_parser::config cfg; 30 | install_parser_service(ctx, cfg); 31 | response_parser pr(ctx); 32 | } 33 | } 34 | 35 | void 36 | run() 37 | { 38 | testSpecial(); 39 | } 40 | }; 41 | 42 | TEST_SUITE( 43 | response_parser_test, 44 | "boost.http_proto.response_parser"); 45 | 46 | } // http_proto 47 | } // boost 48 | -------------------------------------------------------------------------------- /test/unit/response_view.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | class response_view_test 19 | { 20 | public: 21 | void 22 | run() 23 | { 24 | // response_view() 25 | { 26 | response_view req; 27 | } 28 | 29 | // response_view(response_view const&) 30 | { 31 | { 32 | response_view res1; 33 | response_view res2(res1); 34 | (void)res2; 35 | } 36 | } 37 | 38 | // operator=(response_view const&) 39 | { 40 | { 41 | response_view res1; 42 | response_view res2; 43 | res1 = res2; 44 | } 45 | } 46 | } 47 | }; 48 | 49 | TEST_SUITE( 50 | response_view_test, 51 | "boost.http_proto.response_view"); 52 | 53 | } // http_proto 54 | } // boost 55 | 56 | -------------------------------------------------------------------------------- /test/unit/rfc/combine_field_values.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct combine_field_values_test 19 | { 20 | void 21 | run() 22 | { 23 | fields f( 24 | "Content-Length: 42\r\n" 25 | "x: 1\r\n" 26 | "y: 2\r\n" 27 | "Set-Cookie: a\r\n" 28 | "x: 3\r\n" 29 | "z: 4\r\n" 30 | "Set-Cookie: b\r\n" 31 | "x: 5\r\n" 32 | "p: 6\r\n" 33 | "User-Agent: boost\r\n" 34 | "\r\n"); 35 | grammar::recycled_ptr< 36 | std::string> temp; 37 | BOOST_TEST(combine_field_values( 38 | f.find_all("x"), temp) == 39 | "1,3,5"); 40 | BOOST_TEST(combine_field_values( 41 | f.find_all("y"), temp) == 42 | "2"); 43 | BOOST_TEST(combine_field_values( 44 | f.find_all("q"), temp) == ""); 45 | BOOST_TEST(combine_field_values( 46 | f.find_all( 47 | field::user_agent), temp) == "boost"); 48 | BOOST_TEST(combine_field_values( 49 | f.find_all( 50 | field::set_cookie), temp) == "a,b"); 51 | } 52 | }; 53 | 54 | TEST_SUITE( 55 | combine_field_values_test, 56 | "boost.http_proto.combine_field_values"); 57 | 58 | } // http_proto 59 | } // boost 60 | -------------------------------------------------------------------------------- /test/unit/rfc/detail/rules.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_rule.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | namespace detail { 18 | 19 | struct rules_test 20 | { 21 | void 22 | testReplaceObsFold() 23 | { 24 | auto const check = 25 | []( core::string_view sv0, 26 | core::string_view sv1) 27 | { 28 | std::string s( 29 | sv0.data(), sv0.size()); 30 | remove_obs_fold( 31 | &s[0], s.data() + s.size()); 32 | BOOST_TEST(sv1 == s); 33 | }; 34 | 35 | check("", ""); 36 | check(" ", " "); 37 | check("\t", "\t"); 38 | check("\r", "\r"); 39 | check("\r\n", "\r\n"); 40 | check(" \r\n", " \r\n"); 41 | check("\r\n\r", "\r\n\r"); 42 | check(" \r\n.", " \r\n."); 43 | check(" \r\n\t", " \t"); 44 | check("\r\n\r\n", "\r\n\r\n"); 45 | check(".\r\n .\r\n", ". .\r\n"); 46 | check(" \r\n \r", " \r"); 47 | check(" \r\n \r ", " \r "); 48 | } 49 | 50 | void 51 | run() 52 | { 53 | testReplaceObsFold(); 54 | } 55 | }; 56 | 57 | TEST_SUITE( 58 | rules_test, 59 | "boost.http_proto.rules_test"); 60 | 61 | } // detail 62 | } // http_proto 63 | } // boost 64 | -------------------------------------------------------------------------------- /test/unit/rfc/list_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "test_suite.hpp" 17 | 18 | #include 19 | 20 | namespace boost { 21 | namespace http_proto { 22 | 23 | struct list_rule_test 24 | { 25 | void 26 | bad(core::string_view s) 27 | { 28 | auto rv = grammar::parse(s, 29 | list_rule(token_rule)); 30 | BOOST_TEST(rv.has_error()); 31 | } 32 | 33 | void 34 | ok( core::string_view s, 35 | std::initializer_list< 36 | core::string_view> init) 37 | { 38 | auto rv = grammar::parse(s, 39 | list_rule(token_rule)); 40 | if(! BOOST_TEST(rv.has_value())) 41 | return; 42 | auto const& t = *rv; 43 | if(! BOOST_TEST( 44 | t.size() == init.size())) 45 | return; 46 | auto it = t.begin(); 47 | for(std::size_t i = 0; 48 | i < t.size(); ++i) 49 | BOOST_TEST(*it++ == 50 | init.begin()[i]); 51 | } 52 | 53 | void 54 | testParse() 55 | { 56 | bad(" "); 57 | bad("\t"); 58 | bad(" \t"); 59 | bad(" "); 60 | 61 | ok("", {}); 62 | ok("x", {"x"}); 63 | ok("x,y", {"x","y"}); 64 | 65 | ok("", {}); 66 | ok(",", {}); 67 | bad(", "); 68 | ok(", ,", {}); 69 | ok(",,,", {}); 70 | 71 | ok("1", {"1"}); 72 | ok(",1", {"1"}); 73 | ok("1,", {"1"}); 74 | ok(", 1", {"1"}); 75 | ok("1 ,", {"1"}); 76 | 77 | ok("1,2", {"1", "2"}); 78 | ok("1,2", {"1", "2"}); 79 | 80 | ok("1,2,3", {"1", "2", "3"}); 81 | ok(", 1,\t2, 3", {"1", "2", "3"}); 82 | } 83 | 84 | void 85 | run() 86 | { 87 | testParse(); 88 | } 89 | }; 90 | 91 | TEST_SUITE( 92 | list_rule_test, 93 | "boost.http_proto.list_rule"); 94 | 95 | } // http_proto 96 | } // boost 97 | -------------------------------------------------------------------------------- /test/unit/rfc/parameter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct parameter_test 19 | { 20 | void 21 | run() 22 | { 23 | } 24 | }; 25 | 26 | TEST_SUITE( 27 | parameter_test, 28 | "boost.http_proto.parameter"); 29 | 30 | } // http_proto 31 | } // boost 32 | -------------------------------------------------------------------------------- /test/unit/rfc/quoted_token_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct quoted_token_rule_test 19 | { 20 | void 21 | run() 22 | { 23 | auto const& t = quoted_token_rule; 24 | 25 | // token 26 | bad(t, ""); 27 | ok(t, "x"); 28 | ok(t, 29 | "!#$%&'*+-.^_`|~" 30 | "0123456789" 31 | "abcdefghijklmnopqrstuvwxyz" 32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 33 | bad(t, "a b"); 34 | 35 | // quoted-string 36 | ok(t, "\"\""); 37 | ok(t, "\"x\""); 38 | ok(t, "\"\\,\""); 39 | ok(t, "\"abc\\ def\""); 40 | } 41 | }; 42 | 43 | TEST_SUITE( 44 | quoted_token_rule_test, 45 | "boost.http_proto.quoted_token_rule"); 46 | 47 | } // http_proto 48 | } // boost 49 | -------------------------------------------------------------------------------- /test/unit/rfc/quoted_token_view.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct quoted_token_view_test 19 | { 20 | void 21 | run() 22 | { 23 | } 24 | }; 25 | 26 | TEST_SUITE( 27 | quoted_token_view_test, 28 | "boost.http_proto.quoted_token_view"); 29 | 30 | } // http_proto 31 | } // boost 32 | -------------------------------------------------------------------------------- /test/unit/rfc/token_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_rule.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct token_rule_test 19 | { 20 | void 21 | run() 22 | { 23 | ok(token_rule, "x", "x"); 24 | ok(token_rule, "xyz", "xyz"); 25 | bad(token_rule, "", grammar::error::need_more); 26 | } 27 | }; 28 | 29 | TEST_SUITE( 30 | token_rule_test, 31 | "boost.http_proto.token_rule"); 32 | 33 | } // http_proto 34 | } // boost 35 | -------------------------------------------------------------------------------- /test/unit/rfc/transfer_encoding_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include "../../src/rfc/transfer_encoding_rule.hpp" 12 | 13 | #include 14 | #include 15 | 16 | #include "test_helpers.hpp" 17 | 18 | namespace boost { 19 | namespace http_proto { 20 | 21 | BOOST_STATIC_ASSERT( 22 | std::is_nothrow_copy_assignable< 23 | system::result>::value); 24 | 25 | BOOST_STATIC_ASSERT( 26 | std::is_nothrow_copy_assignable< 27 | grammar::range>::value); 28 | 29 | BOOST_STATIC_ASSERT( 30 | std::is_nothrow_copy_assignable< 31 | detail::transfer_encoding::param>::value); 32 | 33 | BOOST_STATIC_ASSERT( 34 | std::is_nothrow_copy_assignable< 35 | quoted_token_view>::value); 36 | 37 | BOOST_STATIC_ASSERT( 38 | std::is_nothrow_copy_constructible< 39 | system::result>::value); 40 | 41 | BOOST_STATIC_ASSERT( 42 | std::is_nothrow_copy_constructible< 43 | grammar::range>::value); 44 | 45 | BOOST_STATIC_ASSERT( 46 | std::is_nothrow_copy_constructible< 47 | detail::transfer_encoding::param>::value); 48 | 49 | BOOST_STATIC_ASSERT( 50 | std::is_nothrow_copy_constructible< 51 | quoted_token_view>::value); 52 | 53 | struct transfer_encoding_rule_test 54 | { 55 | void 56 | run() 57 | { 58 | auto const& t = 59 | detail::transfer_encoding_rule; 60 | 61 | bad(t, ""); 62 | bad(t, " "); 63 | bad(t, " x"); 64 | bad(t, "x "); 65 | bad(t, " x "); 66 | ok(t, "chunked"); 67 | ok(t, "compress"); 68 | ok(t, "deflate"); 69 | ok(t, "gzip"); 70 | ok(t, "wakanda;status=good"); 71 | ok(t, "wakanda;x=1;y=2"); 72 | ok(t, "main;dir=\"Program\\ Files\""); 73 | ok(t, "main;dir1=\"Program\\ Files\";dir2=master"); 74 | ok(t, "gzip,chunked"); 75 | ok(t, "gzip, chunked"); 76 | ok(t, "br;level=5,chunked"); 77 | ok(t, "br;level=5, chunked"); 78 | ok(t, "br;level=5, ,chunked"); 79 | ok(t, "br;level=5, ,chunked,"); 80 | ok(t, "br;level=5, ,chunked, ,"); 81 | bad(t, "br;level=5, ,chunked, "); 82 | 83 | ok(t, "chunked"); 84 | ok(t, "compress"); 85 | ok(t, "deflate"); 86 | ok(t, "gzip"); 87 | 88 | ok(t, "Chunked"); 89 | ok(t, "Compress"); 90 | ok(t, "Deflate"); 91 | ok(t, "Gzip"); 92 | 93 | bad(t, "chunked;p=2"); 94 | bad(t, "compress;p=2"); 95 | bad(t, "deflate;p=2"); 96 | bad(t, "gzip;p=2"); 97 | } 98 | }; 99 | 100 | TEST_SUITE( 101 | transfer_encoding_rule_test, 102 | "boost.http_proto.transfer_encoding_rule"); 103 | 104 | } // http_proto 105 | } // boost 106 | -------------------------------------------------------------------------------- /test/unit/rfc/upgrade_rule.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_rule.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct upgrade_rule_test 19 | { 20 | void 21 | run() 22 | { 23 | ok(upgrade_rule, "x"); 24 | ok(upgrade_rule, "xyz"); 25 | ok(upgrade_rule, "xyz/1"); 26 | ok(upgrade_rule, "xyz/1, abc/2"); 27 | bad(upgrade_rule, ""); 28 | bad(upgrade_rule, "/"); 29 | bad(upgrade_rule, "", grammar::error::mismatch); 30 | } 31 | }; 32 | 33 | TEST_SUITE( 34 | upgrade_rule_test, 35 | "boost.http_proto.upgrade_rule"); 36 | 37 | } // http_proto 38 | } // boost 39 | -------------------------------------------------------------------------------- /test/unit/sandbox.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include "test_suite.hpp" 11 | 12 | namespace boost { 13 | namespace http_proto { 14 | 15 | /* 16 | Four body styles for `parser` 17 | * in-place 18 | * a DynamicBuffer 19 | * a Sink 20 | * a parser::stream 21 | 22 | Four body styles for `serializer` 23 | * Specify a ConstBufferSequence 24 | * Specify a Source 25 | * Write into a serializer::stream 26 | * in-place 27 | 28 | struct half_duplex_client; 29 | struct full_duplex_client; 30 | struct pipelined_client; 31 | struct websocket_client; 32 | struct websocket_client_with_permessage_deflate; 33 | 34 | struct half_duplex_server; 35 | struct full_duplex_server; 36 | struct pipelined_server; 37 | struct websocket_server; 38 | struct websocket_server_with_permessage_deflate; 39 | 40 | */ 41 | 42 | struct sandbox_test 43 | { 44 | void 45 | run() 46 | { 47 | /* 48 | std::string s; 49 | read_header( sock, pr ); 50 | char temp[1024]; 51 | auto mb = buffers::buffer(temp); 52 | while(! pr.is_complete()) 53 | { 54 | auto[ec, n] = co_await 55 | async_read_some( sock, pr, mb ); 56 | } 57 | */ 58 | } 59 | }; 60 | 61 | TEST_SUITE( 62 | sandbox_test, 63 | "boost.http_proto.sandbox"); 64 | 65 | } // http_proto 66 | } // boost 67 | -------------------------------------------------------------------------------- /test/unit/service/service.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | -------------------------------------------------------------------------------- /test/unit/service/virtual_service.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Christian Mazakas 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "test_helpers.hpp" 15 | 16 | namespace boost { 17 | namespace http_proto { 18 | 19 | struct virtual_service : 20 | #ifdef BOOST_NO_RTTI 21 | service 22 | #else 23 | virtual service 24 | #endif 25 | { 26 | int *px_ = nullptr; 27 | 28 | virtual_service(context &) : px_(new int{42}) {} 29 | ~virtual_service() override { delete px_; } 30 | int get_value() const { return *px_; } 31 | }; 32 | 33 | struct virtual_service_test { 34 | // want to ensure that our service architecture works with virtual inheritance 35 | void run() { 36 | context ctx; 37 | ctx.make_service(); 38 | 39 | auto const psvc = ctx.find_service(); 40 | BOOST_TEST_EQ(psvc->get_value(), 42); 41 | } 42 | }; 43 | 44 | TEST_SUITE(virtual_service_test, "boost.http_proto.virtual_service"); 45 | 46 | } // namespace http_proto 47 | } // namespace boost 48 | -------------------------------------------------------------------------------- /test/unit/service/zlib_service.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #ifdef BOOST_HTTP_PROTO_HAS_ZLIB 14 | 15 | #include 16 | 17 | #include "test_helpers.hpp" 18 | 19 | namespace boost { 20 | namespace http_proto { 21 | 22 | struct zlib_service_test 23 | { 24 | void 25 | run() 26 | { 27 | context ctx; 28 | zlib::install_service(ctx); 29 | } 30 | }; 31 | 32 | TEST_SUITE( 33 | zlib_service_test, 34 | "boost.http_proto.zlib_service"); 35 | 36 | } // http_proto 37 | } // boost 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /test/unit/sink.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/buffers 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct sink_test 19 | { 20 | struct test_sink : sink 21 | { 22 | std::string s_; 23 | std::size_t fail_; 24 | 25 | explicit 26 | test_sink( 27 | std::size_t fail) noexcept 28 | : fail_(fail) 29 | { 30 | } 31 | 32 | std::string const& 33 | str() const noexcept 34 | { 35 | return s_; 36 | } 37 | 38 | results 39 | on_write( 40 | buffers::const_buffer b, 41 | bool) override 42 | { 43 | results rv; 44 | if(fail_-- == 0) 45 | { 46 | rv.ec = system::error_code( 47 | system::errc::invalid_argument, 48 | system::generic_category()); 49 | return rv; 50 | } 51 | s_.append(static_cast< 52 | char const*>(b.data()), 53 | b.size()); 54 | rv.bytes += b.size(); 55 | return rv; 56 | } 57 | }; 58 | 59 | void 60 | testSink() 61 | { 62 | auto const& pat = test_pattern(); 63 | 64 | // write(ConstBufferSequence) 65 | for(std::size_t i = 0;;++i) 66 | { 67 | test_sink dest(i); 68 | buffers::const_buffer cb[3] = { 69 | { &pat[0], 3 }, 70 | { &pat[3], 5 }, 71 | { &pat[8], 7 } }; 72 | buffers::const_buffer_span bs(cb, 3); 73 | auto rv = dest.write(bs, false); 74 | if(rv.ec.failed()) 75 | continue; 76 | BOOST_TEST_EQ(dest.str(), pat); 77 | break; 78 | } 79 | 80 | // write(const_buffer) 81 | for(std::size_t i = 0;;++i) 82 | { 83 | test_sink dest(i); 84 | buffers::const_buffer cb( 85 | &pat[0], pat.size()); 86 | auto rv = dest.write(cb, false); 87 | if(rv.ec.failed()) 88 | continue; 89 | BOOST_TEST_EQ(dest.str(), pat); 90 | break; 91 | } 92 | 93 | // write(mutable_buffer) 94 | for(std::size_t i = 0;;++i) 95 | { 96 | test_sink dest(i); 97 | std::string s = pat; 98 | buffers::mutable_buffer mb( 99 | &s[0], s.size()); 100 | auto rv = dest.write(mb, false); 101 | if(rv.ec.failed()) 102 | continue; 103 | BOOST_TEST_EQ(dest.str(), pat); 104 | break; 105 | } 106 | 107 | // empty sequence 108 | { 109 | test_sink dest(99); 110 | buffers::const_buffer_span bs; 111 | auto rv = dest.write(bs, true); 112 | BOOST_TEST(! rv.ec.failed()); 113 | BOOST_TEST_EQ(rv.bytes, 0); 114 | } 115 | } 116 | 117 | void 118 | run() 119 | { 120 | testSink(); 121 | } 122 | }; 123 | 124 | TEST_SUITE( 125 | sink_test, 126 | "boost.http_proto.sink"); 127 | 128 | } // http_proto 129 | } // boost 130 | -------------------------------------------------------------------------------- /test/unit/source.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/buffers 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_helpers.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct source_test 19 | { 20 | struct test_source : source 21 | { 22 | buffers::const_buffer cb_; 23 | std::size_t fail_; 24 | 25 | explicit 26 | test_source( 27 | std::size_t fail) noexcept 28 | : fail_(fail) 29 | { 30 | auto const& pat = test_pattern(); 31 | cb_ = { &pat[0], pat.size() }; 32 | } 33 | 34 | results 35 | on_read( 36 | buffers::mutable_buffer b) override 37 | { 38 | results rv; 39 | if(fail_-- == 0) 40 | { 41 | rv.ec = boost::system::error_code( 42 | boost::system::errc::invalid_argument, 43 | boost::system::generic_category()); 44 | return rv; 45 | } 46 | auto const n = 47 | buffers::copy(b, cb_); 48 | cb_ = buffers::sans_prefix(cb_, n); 49 | rv.bytes += n; 50 | rv.finished = cb_.size() == 0; 51 | return rv; 52 | } 53 | }; 54 | 55 | void 56 | testSource() 57 | { 58 | auto const& pat = test_pattern(); 59 | 60 | // read(MutableBufferSequence) 61 | for(std::size_t i = 0;;++i) 62 | { 63 | test_source src(i); 64 | std::string s( 65 | pat.size(), 0); 66 | buffers::mutable_buffer mb[3] = { 67 | { &s[0], 3 }, 68 | { &s[3], 5 }, 69 | { &s[8], 7 } }; 70 | buffers::mutable_buffer_span bs(mb, 3); 71 | auto rv = src.read(bs); 72 | if(rv.ec.failed()) 73 | continue; 74 | BOOST_TEST(rv.finished); 75 | BOOST_TEST_EQ( 76 | rv.bytes, pat.size()); 77 | s.resize(rv.bytes); 78 | BOOST_TEST_EQ(s, pat); 79 | break; 80 | } 81 | 82 | // read(mutable_buffer) 83 | for(std::size_t i = 0;;++i) 84 | { 85 | test_source src(i); 86 | std::string s( 87 | pat.size(), 0); 88 | buffers::mutable_buffer mb( 89 | &s[0], s.size()); 90 | auto rv = src.read(mb); 91 | if(rv.ec.failed()) 92 | continue; 93 | BOOST_TEST(rv.finished); 94 | BOOST_TEST_EQ( 95 | rv.bytes, pat.size()); 96 | s.resize(rv.bytes); 97 | BOOST_TEST_EQ(s, pat); 98 | break; 99 | } 100 | 101 | // empty sequence 102 | { 103 | test_source src(99); 104 | buffers::mutable_buffer_span bs; 105 | auto rv = src.read(bs); 106 | BOOST_TEST(! rv.ec.failed()); 107 | BOOST_TEST_EQ(rv.bytes, 0); 108 | } 109 | } 110 | 111 | void 112 | run() 113 | { 114 | testSource(); 115 | } 116 | }; 117 | 118 | TEST_SUITE( 119 | source_test, 120 | "boost.http_proto.source"); 121 | 122 | } // http_proto 123 | } // boost 124 | -------------------------------------------------------------------------------- /test/unit/string_body.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | struct string_body_test 19 | { 20 | void 21 | run() 22 | { 23 | } 24 | }; 25 | 26 | TEST_SUITE( 27 | string_body_test, 28 | "boost.http_proto.string_body"); 29 | 30 | } // http_proto 31 | } // boost 32 | -------------------------------------------------------------------------------- /test/unit/test_helpers.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #include "test_helpers.hpp" 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | void 19 | test_fields( 20 | fields_view_base const& f, 21 | core::string_view match) 22 | { 23 | fields r(match); 24 | std::size_t n = std::distance( 25 | f.begin(), f.end()); 26 | BOOST_TEST_EQ(f.size(), n); 27 | auto it0 = r.begin(); 28 | auto it1 = f.begin(); 29 | auto const end = r.end(); 30 | while(it0 != end) 31 | { 32 | if(! BOOST_TEST_NE( 33 | it1, f.end())) 34 | break; 35 | BOOST_TEST_EQ( 36 | it0->name, it1->name); 37 | BOOST_TEST_EQ( 38 | it0->value, it1->value); 39 | ++it0; 40 | ++it1; 41 | } 42 | } 43 | 44 | } // http_proto 45 | } // boost 46 | 47 | -------------------------------------------------------------------------------- /test/unit/test_helpers.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_TEST_HELPERS_HPP 11 | #define BOOST_HTTP_PROTO_TEST_HELPERS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "test_suite.hpp" 23 | 24 | #include 25 | #include 26 | 27 | namespace boost { 28 | namespace http_proto { 29 | 30 | inline 31 | std::string const& 32 | test_pattern() 33 | { 34 | static std::string const pat = 35 | "012" "34567" "89abcde"; 36 | return pat; 37 | } 38 | 39 | template 40 | std::string 41 | test_to_string(Buffers const& bs) 42 | { 43 | std::string s( 44 | buffers::size(bs), 0); 45 | s.resize(buffers::copy( 46 | buffers::make_buffer(&s[0], s.size()), 47 | bs)); 48 | return s; 49 | } 50 | 51 | //------------------------------------------------ 52 | 53 | // Test that fields equals HTTP string 54 | void 55 | test_fields( 56 | fields_view_base const& f, 57 | core::string_view match); 58 | 59 | //------------------------------------------------ 60 | 61 | // rule must match the string 62 | template 63 | typename std::enable_if< 64 | grammar::is_rule::value>::type 65 | ok( R const& r, 66 | core::string_view s) 67 | { 68 | BOOST_TEST(grammar::parse(s, r).has_value()); 69 | } 70 | 71 | // rule must match the string and value 72 | template 73 | typename std::enable_if< 74 | grammar::is_rule::value>::type 75 | ok( R const& r, 76 | core::string_view s, 77 | V const& v) 78 | { 79 | auto rv = grammar::parse(s, r); 80 | if(BOOST_TEST(rv.has_value())) 81 | BOOST_TEST_EQ(rv.value(), v); 82 | } 83 | 84 | // rule must fail the string 85 | template 86 | typename std::enable_if< 87 | grammar::is_rule::value>::type 88 | bad( 89 | R const& r, 90 | core::string_view s) 91 | { 92 | BOOST_TEST(grammar::parse(s, r).has_error()); 93 | } 94 | 95 | // rule must fail the string with error 96 | template 97 | typename std::enable_if< 98 | grammar::is_rule::value>::type 99 | bad( 100 | R const& r, 101 | core::string_view s, 102 | system::error_code const& e) 103 | { 104 | auto rv = grammar::parse(s, r); 105 | if(BOOST_TEST(rv.has_error())) 106 | BOOST_TEST_EQ(rv.error(), e); 107 | } 108 | 109 | } // http_proto 110 | } // boost 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /test/unit/test_rule.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | #ifndef BOOST_HTTP_PROTO_RULE_TESTS_HPP 11 | #define BOOST_HTTP_PROTO_RULE_TESTS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "test_suite.hpp" 19 | 20 | namespace boost { 21 | namespace http_proto { 22 | 23 | // rule must match the string 24 | template 25 | typename std::enable_if< 26 | grammar::is_rule::value>::type 27 | ok( R const& r, 28 | core::string_view s) 29 | { 30 | BOOST_TEST(grammar::parse(s, r).has_value()); 31 | } 32 | 33 | // rule must match the string and value 34 | template 35 | typename std::enable_if< 36 | grammar::is_rule::value>::type 37 | ok( R const& r, 38 | core::string_view s, 39 | V const& v) 40 | { 41 | auto rv = grammar::parse(s, r); 42 | if(BOOST_TEST(rv.has_value())) 43 | BOOST_TEST_EQ(rv.value(), v); 44 | } 45 | 46 | // rule must fail the string 47 | template 48 | typename std::enable_if< 49 | grammar::is_rule::value>::type 50 | bad( 51 | R const& r, 52 | core::string_view s) 53 | { 54 | BOOST_TEST(grammar::parse(s, r).has_error()); 55 | } 56 | 57 | // rule must fail the string with error 58 | template 59 | typename std::enable_if< 60 | grammar::is_rule::value>::type 61 | bad( 62 | R const& r, 63 | core::string_view s, 64 | system::error_code const& e) 65 | { 66 | auto rv = grammar::parse(s, r); 67 | if(BOOST_TEST(rv.has_error())) 68 | BOOST_TEST_EQ(rv.error(), e); 69 | } 70 | 71 | } // http_proto 72 | } // boost 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /test/unit/version.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 3 | // 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | // Official repository: https://github.com/cppalliance/http_proto 8 | // 9 | 10 | // Test that header file is self-contained. 11 | #include 12 | #include 13 | #include "test_suite.hpp" 14 | 15 | namespace boost { 16 | namespace http_proto { 17 | 18 | class version_test 19 | { 20 | public: 21 | void 22 | check(version v, core::string_view s) 23 | { 24 | std::stringstream ss; 25 | ss << v; 26 | BOOST_TEST(ss.str() == s); 27 | } 28 | 29 | void 30 | run() 31 | { 32 | check(version::http_1_0, "HTTP/1.0"); 33 | check(version::http_1_1, "HTTP/1.1"); 34 | } 35 | }; 36 | 37 | TEST_SUITE( 38 | version_test, 39 | "boost.http_proto.version"); 40 | 41 | } // http_proto 42 | } // boost 43 | --------------------------------------------------------------------------------