apple / swift-nio-http2

HTTP/2 support for SwiftNIO
https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2
Apache License 2.0
462 stars 82 forks source link

Content-Length in responses on HEAD method produce error #418

Closed keyvariable closed 11 months ago

keyvariable commented 11 months ago

I have a server that uses HTTP2FramePayloadToHTTP1ServerCodec. Server provides a response with result of long-running calculations in body of 256 bytes. I'd like to use the same code for GET and HEAD methods but actually perform calculations only for GET method. When I write Content-Length: 256 header and conditionally omit body for HEAD method, ContentLengthViolated(file: "/swift-nio-http2/Sources/NIOHTTP2/ContentLengthVerifier.swift", line: 45) error occurs.

Is there a way to write responses for HEAD method with non-zero Content-Length and no body using HTTP2FramePayloadToHTTP1ServerCodec?

I could write fake bytes but it's a wrong way.

Lukasa commented 11 months ago

Can you clarify what version of swift-nio-http2 you're using?

Lukasa commented 11 months ago

Additionally it'd be quite useful if you can produce a small repro for this: the code appears to handle this use-case appropriately, so I'd really like to see if I can reproduce this locally.

keyvariable commented 11 months ago

Can you clarify what version of swift-nio-http2 you're using?

Thank you! I had been using 1.22.0. On 1.27.0 no error occurs.