Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

HEAD response can include Content-Length header #1163

Merged
merged 1 commit into from
Oct 12, 2016

Conversation

cesarblum
Copy link
Contributor

StaticFiles tests are failing because of this.

@halter73 @mikeharder @Tratcher

var responseHeaders = FrameResponseHeaders;

if (!HttpMethods.IsHead(Method) &&
!responseHeaders.HasTransferEncoding &&
Copy link
Member

@halter73 halter73 Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have to check !responseHeaders.HasTransferEncoding.HasValue since your are checking responseHeaders.HasContentLength?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I prefer checking responseHeaders.HeaderContentLengthValue even though you fixed the set raw issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The spec allows both and Transfer-Encoding should take precedence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. I think the spec suggests removing the content-length header in this case which makes sense to me.

   If a message is received with both a Transfer-Encoding and a
   Content-Length header field, the Transfer-Encoding overrides the
   Content-Length.  Such a message might indicate an attempt to
   perform request smuggling (Section 9.5) or response splitting
   (Section 9.4) and ought to be handled as an error.  A sender MUST
   remove the received Content-Length field prior to forwarding such
   a message downstream.

https://tools.ietf.org/html/rfc7230#section-3.3.3

@Tratcher thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope of the current issue. Apps almost never set Transfer-Encoding so I'm not too worried about it right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halter73 might want to add that as a separate issue to request parsing? (and proxy https://github.com/aspnet/Proxy though I assume the httpclient its using would be handling it)

{
var responseHeaders = FrameResponseHeaders;

if (!HttpMethods.IsHead(Method) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you check that if HttpMethods.IsHead(Method) && responseHeaders.ContentLengthValue.HasValue then _responseBytesWritten == 0 || _responseBytesWritten == responseHeaders.ContentLengthValue.Value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that we actually ignore writes now for HEAD responses. I guess what you have is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we count those bytes, we ignore writes to HEAD responses. It would alert the app that there's an issue, but the error would surface anyways on a response to the same resource using a different method.


using (var server = new TestServer(httpContext =>
{
httpContext.Response.ContentLength = 42;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a HEAD test where we set the content-length and attempt to write a response body in the app. We have ResponseTests.ResponseBodyNotWrittenOnHeadResponseAndLoggedOnlyOnce, but it doesn't attempt to set a content-length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@halter73
Copy link
Member

:shipit: b

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants