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

Commit

Permalink
Fixing logger nullref when context created with no feature #532
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Jan 12, 2016
1 parent 48451bd commit de66e88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Microsoft.AspNet.TestHost/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ internal RequestState(HttpRequestMessage request, PathString pathBase, IHttpAppl
request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped);
}

Context = application.CreateContext(new FeatureCollection());
var contextFeatures = new FeatureCollection();
contextFeatures.Set<IHttpRequestFeature>(new RequestFeature());
_responseFeature = new ResponseFeature();
contextFeatures.Set<IHttpResponseFeature>(_responseFeature);
Context = application.CreateContext(contextFeatures);
var httpContext = Context.HttpContext;

httpContext.Features.Set<IHttpRequestFeature>(new RequestFeature());
_responseFeature = new ResponseFeature();
httpContext.Features.Set<IHttpResponseFeature>(_responseFeature);
var serverRequest = httpContext.Request;
serverRequest.Protocol = "HTTP/" + request.Version.ToString(2);
serverRequest.Scheme = request.RequestUri.Scheme;
Expand Down
7 changes: 4 additions & 3 deletions src/Microsoft.AspNet.TestHost/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ public RequestState(Uri uri, PathString pathBase, CancellationToken cancellation
_application = application;

// HttpContext
Context = _application.CreateContext(new FeatureCollection());
var contextFeatures = new FeatureCollection();
contextFeatures.Set<IHttpRequestFeature>(new RequestFeature());
contextFeatures.Set<IHttpResponseFeature>(new ResponseFeature());
Context = _application.CreateContext(contextFeatures);
var httpContext = Context.HttpContext;

// Request
httpContext.Features.Set<IHttpRequestFeature>(new RequestFeature());
var request = httpContext.Request;
request.Protocol = "HTTP/1.1";
var scheme = uri.Scheme;
Expand Down Expand Up @@ -130,7 +132,6 @@ public RequestState(Uri uri, PathString pathBase, CancellationToken cancellation
request.Body = Stream.Null;

// Response
httpContext.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var response = httpContext.Response;
response.Body = Stream.Null;
response.StatusCode = 200;
Expand Down
1 change: 0 additions & 1 deletion test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Testing.xunit;
Expand Down

0 comments on commit de66e88

Please sign in to comment.