Handle absolute-form requests when converting from/to HTTPTypes (#293)

Handle absolute-form requests when converting from/to HTTPTypes.

### Motivation:

HTTPTypes represent modern HTTP/2 / HTTP/3 semantics which do not
support absolute-form requests.

### Modifications:

When converting an absolute-form request to an HTTPRequest, the request
target is converted to its path. When converting an HTTPRequest back,
the user needs to specify which form to convert to.

### Result:

HTTPRequest no longer contains invalid paths when working with cleartext
HTTP/1 proxies.
This commit is contained in:
Guoye Zhang authored and GitHub committed 2025-11-04 12:31:24 -05:00
1 parent c8e77b29ce
commit d5578e7b77
4 files changed
+153 -11

No files matched your search

@@ -93,14 +93,25 @@ public final class HTTPToHTTP1ServerCodec: ChannelDuplexHandler, RemovableChanne
public typealias OutboundIn = HTTPServerResponsePart
public typealias OutboundOut = HTTPResponsePart
private let absoluteForm: Bool
/// Initializes a `HTTPToHTTP1ServerCodec`.
public init() {}
public init() {
self.absoluteForm = false
}
/// Initializes a `HTTPToHTTP1ServerCodec`.
/// - Parameters:
/// - absoluteForm: Whether the request should use the absolute-form (for cleartext HTTP proxies).
public init(absoluteForm: Bool) {
self.absoluteForm = absoluteForm
}
public func channelRead(context: ChannelHandlerContext, data: NIOAny) {
switch self.unwrapInboundIn(data) {
case .head(let head):
do {
let oldRequest = try HTTPRequestHead(head)
let oldRequest = try HTTPRequestHead(head, absoluteForm: self.absoluteForm)
context.fireChannelRead(self.wrapInboundOut(.head(oldRequest)))
} catch {
context.fireErrorCaught(error)