apple / apple/swift-http-types
Calling public HTTP initializer with URL without a scheme results in a precondition crash
- Dominant language
- Swift
- Stars
- 1k
- Forks
- 80
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 12
Description
We called the [`HTTPRequest` initializer `.init(method: Method = .get, url: URL, headerFields: HTTPFields = [:])`](https://github.com/apple/swift-http-types/blob/main/Sources/HTTPTypes/HTTPRequest%2BURL.swift#L68) mistakenly with a url without a scheme.
This resulted in a crash in our application due to a [precondition on the url parameter to have a scheme](https://github.com/apple/swift-http-types/blob/e9b43cc452707206dd5275ab85c4ea24345d19f0/Sources/HTTPTypes/HTTPRequest%2BURL.swift#L133)
This seems like it really isn't public API if there are input constraints that the complier can't check for but result in a runtime crash if violated. Should there be a similar, failable api that gracefully handles type-valid input that fails internal conditions?
Contributor guide
Research direction
Start in Sources/HTTPTypes/HTTPRequest+URL.swift at the public URL initializer around lines 68 and 133. Read how the URL scheme precondition is enforced and review the issue's proposed failable-API direction. Done means the project has an agreed behavior for scheme-less URLs and corresponding coverage for the public initializer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100