http: abstract http parsing out of httpclient

Avoid #ifdef's in httpclient.c, and move http parsing into its own file.
This commit is contained in:
Edward Thomson
2024-04-19 21:07:11 +01:00
parent 3599de9073
commit d396819101
5 changed files with 305 additions and 155 deletions

View File

@@ -1,39 +1,32 @@
# Optional external dependency: http-parser
if(USE_HTTP_PARSER STREQUAL "builtin")
message(STATUS "support for bundled (legacy) http-parser explicitly requested")
if(USE_HTTP_PARSER STREQUAL "http-parser")
find_package(HTTPParser)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
add_feature_info(http-parser ON "http-parser support (bundled)")
else()
# By default, try to use system LLHTTP. Fall back to
# system http-parser, and even to bundled http-parser
# as a last resort.
find_package(LLHTTP)
if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
set(GIT_HTTPPARSER_HTTPPARSER 1)
add_feature_info(http-parser ON "using http-parser (system)")
else()
message(FATAL_ERROR "http-parser support was requested but not found")
endif()
elseif(USE_HTTP_PARSER STREQUAL "llhttp")
find_package(LLHTTP)
if(LLHTTP_FOUND AND LLHTTP_VERSION_MAJOR EQUAL 9)
add_compile_definitions(USE_LLHTTP)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LLHTTP_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_LIBS ${LLHTTP_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS "-lllhttp")
add_feature_info(llhttp ON "llhttp support (system)")
set(GIT_HTTPPARSER_LLHTTP 1)
add_feature_info(http-parser ON "using llhttp (system)")
else()
message(STATUS "llhttp support was requested but not found; checking (legacy) http-parser support")
find_package(HTTPParser)
if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
add_feature_info(http-parser ON "http-parser support (system)")
else()
message(STATUS "neither llhttp nor http-parser support was found; proceeding with bundled (legacy) http-parser")
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
add_feature_info(http-parser ON "http-parser support (bundled)")
endif()
endif()
message(FATAL_ERROR "llhttp support was requested but not found")
endif()
else()
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
set(GIT_HTTPPARSER_BUILTIN 1)
add_feature_info(http-parser ON "using bundled parser")
endif()