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

Minor perf and logging support changes #256

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,14 @@ Task<Stream> IHttpUpgradeFeature.UpgradeAsync()
{
StatusCode = 101;
ReasonPhrase = "Switching Protocols";
ResponseHeaders["Connection"] = "Upgrade";
if (!ResponseHeaders.ContainsKey("Upgrade"))
_responseHeaders.HeaderConnection = "Upgrade";

if (StringValues.IsNullOrEmpty(_responseHeaders.HeaderUpgrade) &&
!StringValues.IsNullOrEmpty(_requestHeaders.HeaderUpgrade))
Copy link
Contributor

Choose a reason for hiding this comment

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

What if one of those is whitespace only?

{
StringValues values;
if (RequestHeaders.TryGetValue("Upgrade", out values))
{
ResponseHeaders["Upgrade"] = values;
}
_responseHeaders.HeaderUpgrade = _requestHeaders.HeaderUpgrade;
}

ProduceStart();
return Task.FromResult(DuplexStream);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,16 @@ public void ProduceContinue()
{
if (_responseStarted) return;

StringValues expect;
if (HttpVersion.Equals("HTTP/1.1") &&
RequestHeaders.TryGetValue("Expect", out expect) &&
(expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase))
if (HttpVersion.Equals("HTTP/1.1"))
{
SocketOutput.Write(_continueBytes);
foreach(var expect in _requestHeaders.HeaderExpect)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: format here?

Copy link
Contributor

Choose a reason for hiding this comment

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

space after foreach

{
if (expect.Equals("100-continue", StringComparison.OrdinalIgnoreCase))
{
SocketOutput.Write(_continueBytes);
return;
}
}
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ public FrameResponseStream(FrameContext context)

public override bool CanWrite => true;

public override long Length
{
get
{
throw new NotImplementedException();
}
}
public override long Length => Position;
Copy link
Member

Choose a reason for hiding this comment

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

Length is only expected to be available for seekable streams. https://msdn.microsoft.com/en-us/library/system.io.stream.length(v=vs.110).aspx NotSupportedException: A class derived from Stream does not support seeking. Position has the same expectation. https://msdn.microsoft.com/en-us/library/system.io.stream.position(v=vs.110).aspx

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we just add a new property to FrameResponseStream. BytesWritten perhaps? This way we can throw from Length and Position as expected.

@lodejard where were you planning on logging the this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From hosting, corresponding to "bytes written" you see in server logs.

Copy link
Member

Choose a reason for hiding this comment

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

Is this logging meant to be server agnostic? Would using Stream.Length work for WebListener?

Copy link
Member

Choose a reason for hiding this comment

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

No it won't, and it won't work for Nowin either. aspnet/Hosting#403 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both of those could easily be updated. But the idea you suggested of having a request statistics feature should also be considered.


public override long Position { get; set; }

Expand Down Expand Up @@ -60,11 +54,13 @@ public override int Read(byte[] buffer, int offset, int count)

public override void Write(byte[] buffer, int offset, int count)
{
Position += count;
_context.FrameControl.Write(new ArraySegment<byte>(buffer, offset, count));
}

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
Position += count;
return _context.FrameControl.WriteAsync(new ArraySegment<byte>(buffer, offset, count), cancellationToken);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using Microsoft.AspNet.Http.Features;
using Microsoft.Dnx.Compilation.CSharp;
using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Features.Authentication;

namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode
Expand Down