Skip to content

Commit

Permalink
Add createHeadResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 23, 2024
1 parent 12f5696 commit 590492b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Sources/Hummingbird/Router/EndpointResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ struct EndpointResponders<Context: BaseRequestContext>: Sendable {
mutating func autoGenerateHeadEndpoint() {
if self.methods[.head] == nil, let get = methods[.get] {
self.methods[.head] = CallbackResponder { request, context in
var response = try await get.respond(to: request, context: context)
response.body = .init()
return response
let response = try await get.respond(to: request, context: context)
return response.createHeadResponse()
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/HummingbirdCore/Response/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public struct Response: Sendable {
get { self.head.headerFields }
set { self.head.headerFields = newValue }
}

/// Return HEAD response based off this response
public func createHeadResponse() -> Response {
.init(status: self.status, headers: self.headers, body: .init())
}
}

extension Response: CustomStringConvertible {
Expand Down

0 comments on commit 590492b

Please sign in to comment.