Skip to content

Commit 8b280c0

Browse files
committed
Initial commit
Wrapping llhttp v9.3.0
0 parents  commit 8b280c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+28587
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

CLAUDE.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Swift Package Manager (SPM) library providing Swift bindings for llhttp, the HTTP parser used in Node.js. The package wraps the C library with Swift types and provides multiple abstraction levels to the user.
8+
9+
- `LLHTTP.Preconcurrency`: Direct Swift wrapper around C implementation
10+
- `LLHTTP`: Swift Concurrency-safe actor-based interface
11+
- `HTTPMessagesParser`: Higher-level abstraction that yields complete HTTP messages via callbacks and AsyncStreams
12+
13+
## Platform Requirements
14+
15+
The library supports the following platforms:
16+
- **iOS**: 13.0+
17+
- **macOS**: 10.15+
18+
- **macCatalyst**: 13.0+
19+
- **tvOS**: 13.0+
20+
- **visionOS**: 1.0+
21+
- **watchOS**: 6.0+
22+
23+
**Note**: The `HTTPMessagesParser` class requires higher minimum versions due to its use of `OSAllocatedUnfairLock`:
24+
- **iOS**: 16.0+
25+
- **macOS**: 13.0+
26+
- **tvOS**: 16.0+
27+
- **watchOS**: 9.0+
28+
29+
The lower-level `LLHTTP` and `LLHTTP.Preconcurrency` APIs are available on all supported platform versions listed above.
30+
31+
## Commands
32+
33+
### Build and Test
34+
- **Build**: `swift build --build-tests`
35+
- **Run all tests**: `swift test`
36+
- **Run specific test**: `swift test --filter <TestName>`
37+
38+
## Code and File Structure
39+
40+
### `Sources/Cllhttp`
41+
This directory contains the vendored C `llhttp` source code. It is the lowest layer of the library and must not be modified directly. Changes should only occur when updating to a new version of the upstream C library.
42+
43+
### `Sources/llhttp`
44+
This directory contains all the Swift code, organized by functionality. The core architectural pattern is to define a central type and extend it with logically grouped functionality in separate files.
45+
46+
- **`LLHTTP.swift`**: The core `actor` that wraps the C parser, providing the primary async interface.
47+
- **`LLHTTP+Preconcurrency.swift`**: Defines the `LLHTTP.Preconcurrency` type, a non-concurrency-safe, direct Swift wrapper around the C implementation. This is for users who need to manage thread safety manually for performance reasons.
48+
- **`LLHTTP+*.swift`**: Extensions that add functionality to the `LLHTTP` actor. This is the primary organizational convention.
49+
- `LLHTTP+Events.swift`: Manages the mapping of C callbacks to Swift async streams.
50+
- `LLHTTP+State.swift`: Handles state management.
51+
- `LLHTTP+LenientFlags.swift`: Manages lenient parsing flags.
52+
- `LLHTTP+Mode.swift`: Defines the parser mode enum (both, request, response) for initialization.
53+
- **`HTTPMessagesParser.swift`**: A higher-level API that consumes events from `LLHTTP` and produces complete `HTTPMessage` objects. It offers both a concurrency-safe implementation and a `Preconcurrency` variant.
54+
- **`HTTPMessage.swift`**: Defines the `HTTPRequest` and `HTTPResponse` data models.
55+
- **`HTTPMessageBuilder.swift`**: An internal helper responsible for assembling message objects from parser events.
56+
- **`LLHTTPError.swift`**: Defines the typed errors thrown by the Swift layer.
57+
- **`Array+Subscripting.swift`**: Internal utility providing convenient subscript access for first/last array elements.
58+
59+
## Testing Approach
60+
61+
The project follows a Test-Driven Development (TDD) methodology. New features or bug fixes should be accompanied by tests.
62+
63+
### Testing Framework
64+
- **Swift Testing**: This project uses the modern Swift Testing framework (not XCTest)
65+
- **Assertions**: Use `#expect()` for soft checks and `#require()` for critical preconditions that should abort the test if they fail
66+
- **Error Testing**: Use `#expect(throws: MyError.self) { ... }` to test for thrown errors
67+
68+
### Test Structure
69+
- **File Mapping**: A source file `Sources/llhttp/X.swift` is typically tested by a corresponding `Tests/llhttpTests/XTests.swift`
70+
- **Test Suites**: Tests are organized using `@Suite` attributes and `@Test` functions
71+
- **Test Data**: The `TestHelpers.swift` file contains sample HTTP messages and utilities for testing
72+
73+
## Agent Documentation
74+
75+
Guidance for AI agents on project conventions, such as the testing framework and its usage, can be found in the `Docs/Agent/` directory.

0 commit comments

Comments
 (0)