Remove SetContentLength and company

This commit is contained in:
Claus Vium 2019-02-26 21:08:30 +01:00
parent 4e229ad86b
commit f1c93ae618
11 changed files with 8 additions and 53 deletions

View file

@ -327,7 +327,6 @@ namespace Emby.Server.Implementations.HttpClientManager
} }
httpWebRequest.ContentType = contentType; httpWebRequest.ContentType = contentType;
// httpWebRequest.ContentLength = bytes.Length;
(await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length); (await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length);
} }
catch (Exception ex) catch (Exception ex)

View file

@ -63,8 +63,6 @@ namespace Emby.Server.Implementations.HttpServer
if (string.IsNullOrWhiteSpace(rangeHeader)) if (string.IsNullOrWhiteSpace(rangeHeader))
{ {
// TODO
//Headers["Content-Length"] = TotalContentLength.ToString(UsCulture);
StatusCode = HttpStatusCode.OK; StatusCode = HttpStatusCode.OK;
} }
else else
@ -99,7 +97,6 @@ namespace Emby.Server.Implementations.HttpServer
// Content-Length is the length of what we're serving, not the original content // Content-Length is the length of what we're serving, not the original content
var lengthString = RangeLength.ToString(UsCulture); var lengthString = RangeLength.ToString(UsCulture);
// TODO Headers["Content-Length"] = lengthString;
var rangeString = string.Format("bytes {0}-{1}/{2}", RangeStart, RangeEnd, TotalContentLength); var rangeString = string.Format("bytes {0}-{1}/{2}", RangeStart, RangeEnd, TotalContentLength);
Headers["Content-Range"] = rangeString; Headers["Content-Range"] = rangeString;

View file

@ -649,11 +649,6 @@ namespace Emby.Server.Implementations.HttpServer
private static Task Write(IResponse response, string text) private static Task Write(IResponse response, string text)
{ {
var bOutput = Encoding.UTF8.GetBytes(text); var bOutput = Encoding.UTF8.GetBytes(text);
response.SetContentLength(bOutput.Length);
// TODO
response.Headers.Remove("Content-Length"); // DO NOT SET THIS, IT'S DONE AUTOMATICALLY BECAUSE MS ARE NOT STUPID
response.SendChunked = true;
return response.OutputStream.WriteAsync(bOutput, 0, bOutput.Length); return response.OutputStream.WriteAsync(bOutput, 0, bOutput.Length);
} }
@ -672,6 +667,7 @@ namespace Emby.Server.Implementations.HttpServer
} }
else else
{ {
// TODO what is this?
var httpsUrl = url var httpsUrl = url
.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase) .Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)
.Replace(":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture), ":" + _config.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase); .Replace(":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture), ":" + _config.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase);

View file

@ -131,7 +131,7 @@ namespace Emby.Server.Implementations.HttpServer
content = Array.Empty<byte>(); content = Array.Empty<byte>();
} }
result = new StreamWriter(content, contentType, contentLength); result = new StreamWriter(content, contentType);
} }
else else
{ {
@ -175,7 +175,7 @@ namespace Emby.Server.Implementations.HttpServer
bytes = Array.Empty<byte>(); bytes = Array.Empty<byte>();
} }
result = new StreamWriter(bytes, contentType, contentLength); result = new StreamWriter(bytes, contentType);
} }
else else
{ {
@ -334,13 +334,13 @@ namespace Emby.Server.Implementations.HttpServer
if (isHeadRequest) if (isHeadRequest)
{ {
var result = new StreamWriter(Array.Empty<byte>(), contentType, contentLength); var result = new StreamWriter(Array.Empty<byte>(), contentType);
AddResponseHeaders(result, responseHeaders); AddResponseHeaders(result, responseHeaders);
return result; return result;
} }
else else
{ {
var result = new StreamWriter(content, contentType, contentLength); var result = new StreamWriter(content, contentType);
AddResponseHeaders(result, responseHeaders); AddResponseHeaders(result, responseHeaders);
return result; return result;
} }
@ -590,11 +590,6 @@ namespace Emby.Server.Implementations.HttpServer
} }
else else
{ {
if (totalContentLength.HasValue)
{
// TODO responseHeaders["Content-Length"] = totalContentLength.Value.ToString(UsCulture);
}
if (isHeadRequest) if (isHeadRequest)
{ {
using (stream) using (stream)

View file

@ -96,8 +96,7 @@ namespace Emby.Server.Implementations.HttpServer
RangeLength = 1 + RangeEnd - RangeStart; RangeLength = 1 + RangeEnd - RangeStart;
// Content-Length is the length of what we're serving, not the original content // Content-Length is the length of what we're serving, not the original content
// TODO Headers["Content-Length"] = RangeLength.ToString(UsCulture); Headers["Content-Range"] = $"bytes {RangeStart}-{RangeEnd}/{TotalContentLength}";
Headers["Content-Range"] = string.Format("bytes {0}-{1}/{2}", RangeStart, RangeEnd, TotalContentLength);
if (RangeStart > 0 && SourceStream.CanSeek) if (RangeStart > 0 && SourceStream.CanSeek)
{ {

View file

@ -57,7 +57,6 @@ namespace Emby.Server.Implementations.HttpServer
if (length > 0) if (length > 0)
{ {
res.SetContentLength(length);
res.SendChunked = false; res.SendChunked = false;
} }
} }

View file

@ -53,11 +53,6 @@ namespace Emby.Server.Implementations.HttpServer
SourceStream = source; SourceStream = source;
Headers["Content-Type"] = contentType; Headers["Content-Type"] = contentType;
if (source.CanSeek)
{
// TODO Headers["Content-Length"] = source.Length.ToString(UsCulture);
}
} }
/// <summary> /// <summary>
@ -65,8 +60,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary> /// </summary>
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <param name="contentType">Type of the content.</param> /// <param name="contentType">Type of the content.</param>
/// <param name="logger">The logger.</param> public StreamWriter(byte[] source, string contentType)
public StreamWriter(byte[] source, string contentType, int contentLength)
{ {
if (string.IsNullOrEmpty(contentType)) if (string.IsNullOrEmpty(contentType))
{ {
@ -76,8 +70,6 @@ namespace Emby.Server.Implementations.HttpServer
SourceBytes = source; SourceBytes = source;
Headers["Content-Type"] = contentType; Headers["Content-Type"] = contentType;
// TODO Headers["Content-Length"] = contentLength.ToString(UsCulture);
} }
public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken) public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken)

View file

@ -43,14 +43,9 @@ namespace Emby.Server.Implementations.Services
{ {
var contentLength = bytesResponse.Length; var contentLength = bytesResponse.Length;
if (response != null)
{
response.SetContentLength(contentLength);
}
if (contentLength > 0) if (contentLength > 0)
{ {
await responseStream.WriteAsync(bytesResponse, 0, contentLength).ConfigureAwait(false); await responseStream.WriteAsync(bytesResponse, 0, contentLength, cancellationToken).ConfigureAwait(false);
} }
return; return;
} }

View file

@ -20,8 +20,6 @@ namespace Emby.Server.Implementations.Services
{ {
response.StatusCode = (int)HttpStatusCode.NoContent; response.StatusCode = (int)HttpStatusCode.NoContent;
} }
response.SetContentLength(0);
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -55,7 +53,6 @@ namespace Emby.Server.Implementations.Services
{ {
if (string.Equals(responseHeaders.Key, "Content-Length", StringComparison.OrdinalIgnoreCase)) if (string.Equals(responseHeaders.Key, "Content-Length", StringComparison.OrdinalIgnoreCase))
{ {
response.SetContentLength(long.Parse(responseHeaders.Value));
continue; continue;
} }
@ -104,7 +101,6 @@ namespace Emby.Server.Implementations.Services
if (bytes != null) if (bytes != null)
{ {
response.ContentType = "application/octet-stream"; response.ContentType = "application/octet-stream";
response.SetContentLength(bytes.Length);
if (bytes.Length > 0) if (bytes.Length > 0)
{ {
@ -117,7 +113,6 @@ namespace Emby.Server.Implementations.Services
if (responseText != null) if (responseText != null)
{ {
bytes = Encoding.UTF8.GetBytes(responseText); bytes = Encoding.UTF8.GetBytes(responseText);
response.SetContentLength(bytes.Length);
if (bytes.Length > 0) if (bytes.Length > 0)
{ {
return response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken); return response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
@ -149,8 +144,6 @@ namespace Emby.Server.Implementations.Services
var contentLength = ms.Length; var contentLength = ms.Length;
response.SetContentLength(contentLength);
if (contentLength > 0) if (contentLength > 0)
{ {
await ms.CopyToAsync(response.OutputStream).ConfigureAwait(false); await ms.CopyToAsync(response.OutputStream).ConfigureAwait(false);

View file

@ -143,14 +143,6 @@ namespace Emby.Server.Implementations.SocketSharp
private set; private set;
} }
public void SetContentLength(long contentLength)
{
// you can happily set the Content-Length header in Asp.Net
// but HttpListener will complain if you do - you have to set ContentLength64 on the response.
// workaround: HttpListener throws "The parameter is incorrect" exceptions when we try to set the Content-Length header
//_response.ContentLength64 = contentLength;
}
public void SetCookie(Cookie cookie) public void SetCookie(Cookie cookie)
{ {
var cookieStr = AsHeaderValue(cookie); var cookieStr = AsHeaderValue(cookie);

View file

@ -145,8 +145,6 @@ namespace MediaBrowser.Model.Services
/// </summary> /// </summary>
bool IsClosed { get; } bool IsClosed { get; }
void SetContentLength(long contentLength);
//Add Metadata to Response //Add Metadata to Response
Dictionary<string, object> Items { get; } Dictionary<string, object> Items { get; }