diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2019-07-14 17:08:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-14 17:08:54 -0400 |
| commit | 135c16c72103249518b31dca4f7a420876fa8e13 (patch) | |
| tree | fb1f13f621a460ea5897fc12746ddd50d3a60f7d | |
| parent | 4f17ed961e2756e0c65b1bb0246e7f62a5f44a8a (diff) | |
| parent | 7bb504d491746d5602b95ab74ed60863cd2e7078 (diff) | |
Merge pull request #1537 from joshuaboniface/contenttype
Properly set content type
| -rw-r--r-- | Emby.Dlna/PlayTo/SsdpHttpClient.cs | 1 | ||||
| -rw-r--r-- | Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | 55 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/HttpRequestOptions.cs | 2 | ||||
| -rw-r--r-- | Mono.Nat/Upnp/Messages/UpnpMessage.cs | 5 |
4 files changed, 6 insertions, 57 deletions
diff --git a/Emby.Dlna/PlayTo/SsdpHttpClient.cs b/Emby.Dlna/PlayTo/SsdpHttpClient.cs index 780b0a889..22aaa6885 100644 --- a/Emby.Dlna/PlayTo/SsdpHttpClient.cs +++ b/Emby.Dlna/PlayTo/SsdpHttpClient.cs @@ -155,7 +155,6 @@ namespace Emby.Dlna.PlayTo } options.RequestContentType = "text/xml"; - options.AppendCharsetToMimeType = true; options.RequestContent = postData; return _httpClient.Post(options); diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index ae62f34e0..613545e21 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -177,10 +177,7 @@ namespace Emby.Server.Implementations.HttpClientManager /// <param name="httpMethod">The HTTP method.</param> /// <returns>Task{HttpResponseInfo}.</returns> public Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod) - { - var httpMethod2 = GetHttpMethod(httpMethod); - return SendAsync(options, httpMethod2); - } + => SendAsync(options, new HttpMethod(httpMethod)); /// <summary> /// send as an asynchronous operation. @@ -216,40 +213,6 @@ namespace Emby.Server.Implementations.HttpClientManager return response; } - private HttpMethod GetHttpMethod(string httpMethod) - { - if (httpMethod.Equals("DELETE", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Delete; - } - else if (httpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Get; - } - else if (httpMethod.Equals("HEAD", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Head; - } - else if (httpMethod.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Options; - } - else if (httpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Post; - } - else if (httpMethod.Equals("PUT", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Put; - } - else if (httpMethod.Equals("TRACE", StringComparison.OrdinalIgnoreCase)) - { - return HttpMethod.Trace; - } - - throw new ArgumentException("Invalid HTTP method", nameof(httpMethod)); - } - private HttpResponseInfo GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url) { if (File.Exists(responseCachePath) @@ -301,23 +264,15 @@ namespace Emby.Server.Implementations.HttpClientManager } else if (options.RequestContent != null) { - httpWebRequest.Content = new StringContent(options.RequestContent); + httpWebRequest.Content = new StringContent( + options.RequestContent, + null, + options.RequestContentType); } else { httpWebRequest.Content = new ByteArrayContent(Array.Empty<byte>()); } - - // TODO: add correct content type - /* - var contentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; - - if (options.AppendCharsetToMimeType) - { - contentType = contentType.TrimEnd(';') + "; charset=\"utf-8\""; - } - - httpWebRequest.Headers.Add(HeaderNames.ContentType, contentType);*/ } if (options.LogRequest) diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs index 0576a1a5d..76bd35e57 100644 --- a/MediaBrowser.Common/Net/HttpRequestOptions.cs +++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs @@ -91,8 +91,6 @@ namespace MediaBrowser.Common.Net public bool EnableDefaultUserAgent { get; set; } - public bool AppendCharsetToMimeType { get; set; } - private string GetHeaderValue(string name) { RequestHeaders.TryGetValue(name, out var value); diff --git a/Mono.Nat/Upnp/Messages/UpnpMessage.cs b/Mono.Nat/Upnp/Messages/UpnpMessage.cs index 1151dd997..ade9df50b 100644 --- a/Mono.Nat/Upnp/Messages/UpnpMessage.cs +++ b/Mono.Nat/Upnp/Messages/UpnpMessage.cs @@ -57,10 +57,9 @@ namespace Mono.Nat.Upnp req.Url = ss; req.EnableKeepAlive = false; req.RequestContentType = "text/xml"; - req.AppendCharsetToMimeType = true; req.RequestHeaders.Add("SOAPACTION", "\"" + device.ServiceType + "#" + upnpMethod + "\""); - string bodyString = "<s:Envelope " + req.RequestContent = "<s:Envelope " + "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" @@ -70,8 +69,6 @@ namespace Mono.Nat.Upnp + "</u:" + upnpMethod + ">" + "</s:Body>" + "</s:Envelope>\r\n\r\n"; - - req.RequestContentBytes = System.Text.Encoding.UTF8.GetBytes(bodyString); return req; } |
