feat: add cross-platform HTTP/1.1 parser and local proxy server for iOS and Android#367
Draft
feat: add cross-platform HTTP/1.1 parser and local proxy server for iOS and Android#367
Conversation
cce3ff6 to
57d1b7c
Compare
f91df85 to
29f9c27
Compare
Add a hardened, RFC-conformant HTTP/1.1 request parser and local proxy server for iOS. The parser is exposed to JavaScript running in the WebView, so it enforces strict validation per RFC 7230/9110/9112 to prevent request smuggling, header injection, and resource exhaustion. Includes: - HTTPRequestParser: Incremental parser with disk-backed buffering - HTTPRequestSerializer: Stateless header parsing with full RFC validation - HeaderValue: RFC 2045 parameter extraction with quoted string handling - MultipartPart: RFC 7578 multipart/form-data with lazy file-slice refs - RequestBody: In-memory and file-backed storage with InputStream access - HTTPServer: Local server on Network.framework with async handler API, connection limits, read timeouts (408 per RFC 9110 §15.5.9), and constant-time bearer token auth - HTTPResponse: Response serialization with header sanitization, Content-Length always derived from actual body size All size-related types use Int64 to match Kotlin's Long and prevent ambiguity on future platforms. 820+ tests covering RFC 7230, 7578, 8941, 9110, 9112, and 9651. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tures Add a pure-Kotlin implementation of the HTTP/1.1 request parser that mirrors the Swift GutenbergKitHTTP library, enabling HTTP parsing on Android without native dependencies. Includes HeaderValue, HTTPRequestSerializer, HTTPRequestParser (with disk-backed buffering), ParsedHTTPRequest, MultipartPart, RequestBody, and HttpServer with bearer token authentication, constant-time token comparison, status code clamping, and Content-Length always derived from actual body size — matching the Swift server's security model. Both platforms are validated against 101 shared JSON test fixtures in test-fixtures/http/ covering header value extraction, request parsing (basic, error, incremental), multipart parsing (field-based, raw-body, error), and 8 dedicated UTF-8 edge cases (overlong encodings, lone surrogates, truncated sequences). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add demo app screens that start the local HTTP server and display its address for manual testing with curl or a browser. Enables on-device validation of the parser against adversarial inputs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Run the shared JSON test fixtures on an actual Android device via connectedDebugAndroidTest, validating the pure-Kotlin HTTP parser under ART in addition to the JVM unit tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
29f9c27 to
0a09c12
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds a hardened, RFC-conformant HTTP/1.1 request parser and local proxy server for both iOS (Swift) and Android (Kotlin), with shared cross-platform test fixtures to guarantee behavioral parity.
Why?
GutenbergKit's native integration embeds a web editor that communicates with native networking through an in-process HTTP server. Because the server is exposed to JavaScript running in the WebView, the parser must be hardened against malformed and adversarial input per RFC 7230/9110/9112 — a lenient parser could enable request smuggling, header injection, or denial-of-service via resource exhaustion.
How?
Swift (iOS)
GutenbergKitHTTPmodule — Incremental, stateful parser (HTTPRequestParser) that buffers to a temporary file on disk so memory stays flat regardless of body size. Strict RFC conformance: rejects obs-fold, whitespace before colon, conflicting Content-Length, Transfer-Encoding, invalid UTF-8 (round-trip validated), lone surrogates, overlong encodings.HTTPServer— Local HTTP/1.1 server on Network.framework with async handler API, connection limits, read timeouts, and constant-time bearer token authentication.multipart/form-datasupport with lazy body references (file slices, not copies).RequestBody— Abstracts over in-memory and file-backed storage withInputStreamand asyncdataaccess.Kotlin (Android)
org.wordpress.gutenberg.http) — Feature-identical port of the Swift parser with no native dependencies. IncludesHeaderValue,HTTPRequestSerializer,HTTPRequestParser(with disk-backed buffering viaBuffer/TempFileOwner),ParsedHTTPRequest,MultipartPart, andRequestBody.HttpServer— Local HTTP/1.1 server with connection limits, read timeouts, pure-Kotlin response serialization, and proper 400 responses on premature connection close.Shared cross-platform test fixtures
test-fixtures/http/covering header value extraction (20 cases), request parsing (29 basic + 12 error + 4 incremental), and multipart parsing (18 field-based + 14 raw-body + 6 error).whitespaceBeforeColonerror (request smuggling vector per RFC 7230 §3.2.4).Key design decisions
Content-Lengthon both platforms (SwiftInt64, KotlinLong) with a 4 GB default max body size.inMemoryBodyThreshold(512 KB default) — bodies below threshold stay in memory, larger ones reference the temp file directly as a slice.Testing Instructions
Automated (CI runs these on every push)
swift test— runs 820+ tests including 103 fixture-based cross-platform testscd android && ./gradlew :gutenberg:test— runs all Android unit tests including fixture testsOn-device (manual)
ios/Demo-iOS/Gutenberg.xcodeprojin Xcode, run on a device, navigate to the Media Proxy Server screen — it prints the server URLcd android && ./gradlew :Gutenberg:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.wordpress.gutenberg.http.InstrumentedFixtureTestsruns all 103 fixture cases on a connected device🤖 Generated with Claude Code