Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Trim response headers in CurlHandler#4194

Merged
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:trim_response_header
Oct 28, 2015
Merged

Trim response headers in CurlHandler#4194
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:trim_response_header

Conversation

@stephentoub
Copy link
Copy Markdown
Member

Apply same header response trimming done by WinHttpHandler.
Fixes #4187
cc: @kapilash, @davidsh

(At some point I'd like to go through and replace all Substring(...).Trim() calls with a more efficient SubstringTrim(...) that doesn't allocate an intermediate string. But in the meantime, this addresses the problem.)

Apply same header response trimming done by WinHttpHandler.
Fixes #4187

(At some point I'd like to go through and replace all Substring(...).Trim() calls with a more efficient SubstringTrim(...) that doesn't allocate an intermediate string.  But in the meantime, this addresses the problem.)
@ellismg
Copy link
Copy Markdown
Contributor

ellismg commented Oct 28, 2015

(At some point I'd like to go through and replace all Substring(...).Trim() calls with a more efficient SubstringTrim(...) that doesn't allocate an intermediate string. But in the meantime, this addresses the problem.)

Yay! Was just going to recommend this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit:
Trim will remove characters which return true for Char.IsWhitespace. Right?
The spec says we can have what it calls OWS here (optional whitespace). And OWS is defined as SPACE | HTAB.

Would it be possible to use Trim(' ', '\t') here? Otherwise, theoretically, CurlHandler could end up having different values for headers.
Or, if needed I can handle it in #4131

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm following what's being done in WinHttpHandler:
https://github.com/dotnet/corefx/blob/master/src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseParser.cs#L201
@davidsh, is WinHttpHandler too aggressive here, or have I misunderstood?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kapilash, if you'd like to incorporate the fix into your change, that's fine, too, and you can close this. Either way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If @davidsh says this needs to be fixed, I will handle it in the other PR. As you pointed out, CurlHandler and WinHttpHandler are in sync with Trim().

On a side note, may be, we should consider moving the header parsing to a common place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is WinHttpHandler too aggressive here, or have I misunderstood?

To be more efficient, it might have been better for WinHttpHandler to specify the specific list of "whitespace" characters to trim away based on what the HTTP protocol would allow as "ignorable whitespace". Instead, I simply used Trim(). In practice, for example, there can't be things like CR or LF characters in the header values because it would never parse as valid HTTP protocol in the first place.

I think the safest thing to do right now is to keep CurlHandler the same as WinHttpHandler and use Trim(). In parallel, I will consult with other HTTP experts here to determine what a better, more mimimal set of trim characters could be. Then, later, we can optimize the algorithm and perhaps re-factor into some Common code modules that both handlers could share.

@kapilash
Copy link
Copy Markdown
Contributor

LGTM!

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Oct 28, 2015

@stephentoub Also, this parsing bug needs to get into RC1. Can you drive this with shiproom?

@davidsh davidsh added this to the 1.0.0-rc1 milestone Oct 28, 2015
@vijaykota
Copy link
Copy Markdown
Contributor

LGTM. Thanks for fixing, @stephentoub

stephentoub added a commit that referenced this pull request Oct 28, 2015
@stephentoub stephentoub merged commit e45d704 into dotnet:master Oct 28, 2015
@stephentoub stephentoub deleted the trim_response_header branch November 4, 2015 19:36
@karelz karelz added the os-linux Linux OS (any supported distro) label Mar 8, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…header

Trim response headers in CurlHandler

Commit migrated from dotnet/corefx@e45d704
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net os-linux Linux OS (any supported distro)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants