Skip to content

Commit

Permalink
Releasing tag 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Feb 27, 2017
1 parent 1bc76ac commit 6905216
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 213 deletions.
13 changes: 11 additions & 2 deletions src/Unosquare.Labs.EmbedIO/System.Net/ChunkStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !NET46
#if CHUNKED
#if !NET46
//
// System.Net.ChunkStream
//
Expand Down Expand Up @@ -376,7 +377,7 @@ private State ReadTrailer(byte[] buffer, ref int offset, int size)
var reader = new StringReader(_saved.ToString());
string line;
while ((line = reader.ReadLine()) != null && line != "")
Headers.Add(line);
AddHeader(line);

return State.None;
}
Expand All @@ -386,6 +387,14 @@ private static void ThrowProtocolViolation(string message)
var we = new System.Net.WebException(message, null, System.Net.WebExceptionStatus.ServerProtocolViolation, null);
throw we;
}

internal void AddHeader(string data)
{
var set = data.Split(':');
if (set.Length == 2)
Headers[set[0].Trim()] = set[1].Trim();
}
}
}
#endif
#endif
7 changes: 3 additions & 4 deletions src/Unosquare.Labs.EmbedIO/System.Net/ChunkedInputStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !NET46
#if CHUNKED
#if !NET46
//
// System.Net.ChunkedInputStream
//
Expand Down Expand Up @@ -35,7 +36,6 @@ namespace Unosquare.Net
internal class ChunkedInputStream : RequestStream
{
private bool _disposed;
private readonly HttpListenerContext _context;
private bool _noMoreData;

private class ReadBufferState
Expand All @@ -61,7 +61,6 @@ public ChunkedInputStream(HttpListenerContext context, Stream stream,
byte[] buffer, int offset, int length)
: base(stream, buffer, offset, length)
{
_context = context;
Decoder = new ChunkStream(context.Request.Headers);
}

Expand Down Expand Up @@ -186,5 +185,5 @@ public void Close()
}
}
}

#endif
#endif
6 changes: 6 additions & 0 deletions src/Unosquare.Labs.EmbedIO/System.Net/HttpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,22 @@ public RequestStream GetRequestStream(bool chunked, long contentlength)
var buffer = _ms.ToArray();
var length = (int) _ms.Length;
_ms = null;

if (chunked)
{
#if CHUNKED
_chunked = true;
_context.Response.SendChunked = true;
_iStream = new ChunkedInputStream(_context, Stream, buffer, _position, length - _position);
#else
throw new InvalidOperationException("Chunked transfer encoding is not supported");
#endif
}
else
{
_iStream = new RequestStream(Stream, buffer, _position, length - _position, contentlength);
}

return _iStream;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !NET46
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

Expand Down
51 changes: 6 additions & 45 deletions src/Unosquare.Labs.EmbedIO/System.Net/HttpListenerRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override ChannelBinding GetChannelBinding(ChannelBindingKind kind)
private bool _isChunked;
private bool _kaSet;
private bool _keepAlive;

#if SSL
delegate X509Certificate2 GccDelegate();
GccDelegate _gccDelegate;
Expand Down Expand Up @@ -254,6 +254,7 @@ internal void FinishInitialization()
_url = HttpListenerRequestUriBuilder.GetRequestUri(RawUrl, _url.Scheme,
_url.Authority, _url.LocalPath, _url.Query);

#if CHUNKED
if (ProtocolVersion >= HttpVersion.Version11)
{
var tEncoding = Headers["Transfer-Encoding"];
Expand All @@ -264,6 +265,7 @@ internal void FinishInitialization()
return;
}
}
#endif

if (!_isChunked && !_clSet)
{
Expand All @@ -280,7 +282,7 @@ internal void FinishInitialization()
output.InternalWrite(_100Continue, 0, _100Continue.Length);
}
}

internal void AddHeader(string header)
{
var colon = header.IndexOf(':');
Expand All @@ -295,6 +297,7 @@ internal void AddHeader(string header)
var val = header.Substring(colon + 1).Trim();
var lower = name.ToLowerInvariant();
Headers.Set(name, val);

switch (lower)
{
case "accept-language":
Expand Down Expand Up @@ -429,7 +432,7 @@ internal bool FlushInput()
/// The accept types.
/// </value>
public string[] AcceptTypes { get; private set; }

#if SSL
/// <summary>
/// Gets the client certificate error code.
Expand Down Expand Up @@ -496,25 +499,16 @@ public int ClientCertificateError
/// <summary>
/// Gets the request headers.
/// </summary>
/// <value>
/// The headers.
/// </value>
public NameValueCollection Headers { get; }

/// <summary>
/// Gets the HTTP method.
/// </summary>
/// <value>
/// The HTTP method.
/// </value>
public string HttpMethod { get; private set; }

/// <summary>
/// Gets the input stream.
/// </summary>
/// <value>
/// The input stream.
/// </value>
public Stream InputStream
{
get
Expand All @@ -534,33 +528,21 @@ public Stream InputStream
/// <summary>
/// Gets a value indicating whether this request is authenticated.
/// </summary>
/// <value>
/// <c>true</c> if this instance is authenticated; otherwise, <c>false</c>.
/// </value>
public bool IsAuthenticated => false;

/// <summary>
/// Gets a value indicating whether this request is local.
/// </summary>
/// <value>
/// <c>true</c> if this instance is local; otherwise, <c>false</c>.
/// </value>
public bool IsLocal => LocalEndPoint.Address.Equals(RemoteEndPoint.Address);

/// <summary>
/// Gets a value indicating whether this request is under a secure connection.
/// </summary>
/// <value>
/// <c>true</c> if this instance is secure connection; otherwise, <c>false</c>.
/// </value>
public bool IsSecureConnection => _context.Connection.IsSecure;

/// <summary>
/// Gets the Keep-Alive value for this request
/// </summary>
/// <value>
/// <c>true</c> if [keep alive]; otherwise, <c>false</c>.
/// </value>
public bool KeepAlive
{
get
Expand Down Expand Up @@ -594,57 +576,36 @@ public bool KeepAlive
/// <summary>
/// Gets the local end point.
/// </summary>
/// <value>
/// The local end point.
/// </value>
public IPEndPoint LocalEndPoint => _context.Connection.LocalEndPoint;

/// <summary>
/// Gets the protocol version.
/// </summary>
/// <value>
/// The protocol version.
/// </value>
public Version ProtocolVersion { get; private set; }

/// <summary>
/// Gets the query string.
/// </summary>
/// <value>
/// The query string.
/// </value>
public NameValueCollection QueryString { get; private set; }

/// <summary>
/// Gets the raw URL.
/// </summary>
/// <value>
/// The raw URL.
/// </value>
public string RawUrl { get; private set; }

/// <summary>
/// Gets the remote end point.
/// </summary>
/// <value>
/// The remote end point.
/// </value>
public IPEndPoint RemoteEndPoint => _context.Connection.RemoteEndPoint;

/// <summary>
/// Gets the request trace identifier.
/// </summary>
/// <value>
/// The request trace identifier.
/// </value>
public Guid RequestTraceIdentifier => Guid.Empty;

/// <summary>
/// Gets the URL.
/// </summary>
/// <value>
/// The URL.
/// </value>
public Uri Url => _url;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !NET46
#if CHUNKED
#if !NET46
//
// System.Net.HttpStreamAsyncResult
//
Expand Down Expand Up @@ -96,4 +97,5 @@ public bool IsCompleted
}
}
}
#endif
#endif
Loading

0 comments on commit 6905216

Please sign in to comment.