Skip to content

Commit

Permalink
Use HTTPFields.contains
Browse files Browse the repository at this point in the history
Doesn't construct http field contents
  • Loading branch information
adam-fowler committed May 19, 2024
1 parent 99ff126 commit 8d2768e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Middleware/CORSMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public struct CORSMiddleware<Context: BaseRequestContext>: RouterMiddleware {
/// apply CORS middleware
public func handle(_ request: Request, context: Context, next: (Request, Context) async throws -> Response) async throws -> Response {
// if no origin header then don't apply CORS
guard request.headers[.origin] != nil else {
guard request.headers.contains(.origin) else {
return try await next(request, context)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Router/ResponseGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public struct EditedResponse<Generator: ResponseGenerator>: ResponseGenerator {
// only add headers from generated response if they don't exist in override headers
var headers = self.headers
for header in response.headers {
if headers[header.name] == nil {
if !headers.contains(header.name) {
headers.append(header)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdCore/Response/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct Response: Sendable {
public init(status: HTTPResponse.Status, headers: HTTPFields = .init(), body: ResponseBody = .init()) {
self.head = .init(status: status, headerFields: headers)
self.body = body
if let contentLength = body.contentLength, headers[values: .contentLength].count == 0 {
if let contentLength = body.contentLength, !headers.contains(.contentLength) {
self.head.headerFields[.contentLength] = String(describing: contentLength)
}
}
Expand Down

0 comments on commit 8d2768e

Please sign in to comment.