hummingbird-project / hummingbird

Lightweight, flexible HTTP server framework written in Swift
Apache License 2.0
1.12k stars 53 forks source link

Trouble when Hummingbird 2.0.1 used with an Nginx proxy. #570

Open dkyowell opened 3 days ago

dkyowell commented 3 days ago

Discussed in https://github.com/hummingbird-project/hummingbird/discussions/568

Originally posted by **dkyowell** September 28, 2024 I have been converting some internal projects from Vapor to Hummingbird. I have run into an issue when using Hummingbird as the protected server behind an Nginx reverse proxy. My Hummingbird based server generates PDF content dynamically. It works perfectly when accessed directly by clients on the LAN. It works across the Nginx proxy when the PDF is very small. When the PDF is larger, I get the following error in my iOS client using URLSession. (It also fails to load from Postman when used with the proxy). The exact same client setup and Nginx reverse proxy worked fine when using Vapor. `Task <8A55EAB5-D2A9-4D3C-A478-F107C107C304>.<29> failed strict content length check - expected: 283409, received: 131629, received (uncompressed): 0 ` Any thoughts on what could be causing this?
Joannis commented 2 days ago

How do you create the ResponseBody containing the PDF? I think it's related to that

dkyowell commented 1 day ago
let body = ResponseBody.init(byteBuffer: .init(data: pdfData))
var headers = HTTPFields.init()
headers.append(.init(name: .contentType, value: MediaType.applicationPdf.description))
return .init(status: .ok, headers: headers, body: body)