Skip to content

feat: add URL parser foundation - #6

Merged
zuudevs merged 13 commits into
mainfrom
feat/url-parser
Sep 14, 2026
Merged

zuudevs merged 13 commits into
mainfrom
feat/url-parser

Conversation

@zuudevs

@zuudevs zuudevs commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

Starts the first v1 implementation slice by adding the foundational public error/result types and a tested HTTP URL parser.

Added

  • include/cpp_request/error.hpp
    • frozen ErrorCode taxonomy from the v1 error-model docs
    • lightweight Error with optional native diagnostic code
    • allocation-free error_message()
  • include/cpp_request/result.hpp
    • C++17 Result<T> backed by std::variant<T, Error>
    • [[nodiscard]], has_value(), explicit operator bool(), value(), and error()
  • include/cpp_request/url.hpp
    • parsed URL value type
    • scheme/host/path/query/target views
    • effective port and explicit-port metadata
    • IPv6-literal metadata
  • src/url.cpp
    • http:// parsing
    • case-insensitive HTTP scheme recognition with normalization
    • default port 80
    • explicit port parsing and validation
    • bracketed IPv6 literal support
    • default / path
    • query handling
    • fragment exclusion from request-target
    • rejection of unsupported schemes and v1 user-info
  • tests/url_test.cpp
    • happy-path and invalid-input coverage

Build changes

  • update project baseline from C++11 to the frozen C++17 requirement
  • compile URL parser into the internal target
  • wire GoogleTest into tests/

Scope

This PR intentionally does not implement DNS, sockets, HTTP serialization, response parsing, or Client yet. It establishes the value/error and URL foundation those layers will build on.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c0d64ddcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/CMakeLists.txt Outdated
@@ -0,0 +1,16 @@
find_package(GTest CONFIG REQUIRED)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore a fallback before requiring GTest

On any clean build environment without a preinstalled GTest CMake config, configuration now stops at this line; this includes the checked .github/workflows/ci.yml path, which runs plain cmake -B build without activating the repository's vcpkg toolchain or installing GTest. The repository already has cmake/packages/google-test.cmake to fetch GTest when it is unavailable, so use that bootstrap or otherwise make tests optional instead of making a test-only dependency mandatory for every library configuration.

Useful? React with 👍 / 👎.

Comment thread tests/CMakeLists.txt
target_compile_features(cpp_request_tests PRIVATE cxx_std_17)

include(GoogleTest)
gtest_discover_tests(cpp_request_tests)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enable CTest before registering the URL tests

When GTest is available, this registration is still ineffective because no active CMake path calls enable_testing() or includes CTest; the only existing call is in the unused cmake/packages/google-test.cmake. As documented by cmake --help-command enable_testing, testing must be enabled from the source root, and configuring this tree with a GTest config followed by ctest -N reports Total Tests: 0, so these URL tests will never run through CTest.

Useful? React with 👍 / 👎.

Comment thread src/url.cpp
Comment on lines +105 to +111
if (authority.front() == '[') {
const std::size_t closing = authority.find(']');
if (closing == std::string_view::npos || closing == 1) {
return Error{ErrorCode::InvalidUrl};
}

result.host_is_ipv6_literal_ = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate bracketed hosts before marking them as IPv6

For any nonempty bracket contents, the parser reports success and sets host_is_ipv6_literal_ without checking IPv6 syntax. For example, Url::parse("http://[example.com]/") and Url::parse("http://[:::]/") both succeed and are labeled IPv6 literals even though those are not valid IPv6 addresses, violating the parser's structured invalid-URL behavior; validate the bracketed address before accepting it and setting this metadata.

Useful? React with 👍 / 👎.

@zuudevs
zuudevs merged commit 5b2a2f9 into main Sep 14, 2026
6 checks passed
@zuudevs
zuudevs deleted the feat/url-parser branch September 14, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant