smithy icon indicating copy to clipboard operation
smithy copied to clipboard

Should HTTPResponseTests include a Content-Length assertion?

Open hlbarber opened this issue 2 years ago • 2 comments

In many of the HttpRequestTests there includes a

https://github.com/awslabs/smithy/blob/d654ab1d4ef8eeb1e89fec72028b9a2b456ec347/smithy-aws-protocol-tests/model/awsJson1_1/documents.smithy#L36-L38

asserting the existence of a Content-Length header.

Should such an assertion exist for HttpResponseTests too?

https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2

A user agent SHOULD send a Content-Length in a request message when no Transfer-Encoding is sent and the request method defines a meaning for an enclosed payload body.

Aside from the cases defined above, in the absence of Transfer-Encoding, an origin server SHOULD send a Content-Length header field when the payload body size is known prior to sending the complete header section.

seems to suggest that including a Content-Length header is recommended (but not required) for both clients and servers.

hlbarber avatar Jun 03 '22 16:06 hlbarber

Yeah they could. I was being more prescriptive on the client and less so on the service because clients really shouldn’t rely on always getting a Content-Length because it’s not mandated by HTTP.

mtdowling avatar Jun 04 '22 03:06 mtdowling

There is also the opposite approach where test coverage doesn't cover anything outside the Smithy spec? For example, only check Content-Length in the case where @requiresLength is present. This approach might be chosen to avoid the grey area of whether or not tests should cover other SHOULDs in the HTTP spec.

Perhaps this comment is relevant.

hlbarber avatar Jun 04 '22 08:06 hlbarber