Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive header names #1737

Merged
merged 2 commits into from Feb 11, 2022

Conversation

amosonn
Copy link

@amosonn amosonn commented Feb 7, 2022

Description

If we add a content header to a request, but use non-standard casing (e.g., adding the header content-type), currently RestSharp doesn't correctly add this header to HttpContent, and then later it attempts to add it to HttpRequest and fails:

System.InvalidOperationException: Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
   at System.Net.Http.Headers.HttpHeaders.GetHeaderDescriptor(String name)
   at System.Net.Http.Headers.HttpHeaders.Remove(String name)
   at RestSharp.HttpRequestMessageExtensions.<AddHeaders>g__AddHeader|0_2(Parameter parameter, HttpHeaders httpHeaders)
   at RestSharp.HttpRequestMessageExtensions.<>c__DisplayClass0_0.<AddHeaders>b__1(Parameter x)
   at RestSharp.Extensions.CollectionExtensions.ForEach[T](IEnumerable`1 items, Action`1 action)
   at RestSharp.HttpRequestMessageExtensions.AddHeaders(HttpRequestMessage message, RequestHeaders headers)
   at RestSharp.RestClient.ExecuteInternal(RestRequest request, CancellationToken cancellationToken)

This PR fixes this (and tests the fix).

Purpose

This pull request is a:

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

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

Successfully merging this pull request may close these issues.

None yet

2 participants