Skip to content

Commit

Permalink
Updated StdioServer.cs to create a feature collection per request, to…
Browse files Browse the repository at this point in the history
… avoid the issue of reused requests from Kestrel
  • Loading branch information
david-driscoll committed Jan 15, 2016
1 parent 854fbb6 commit 3114911
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/OmniSharp.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ public static void Main(string[] args)

if (transportType == TransportType.Stdio)
{
builder.UseServerFactory(new StdioServerFactory(Console.In, writer));
builder.UseServer(new StdioServerFactory(Console.In, writer));
}
else
{
builder.UseServerFactory("Microsoft.AspNet.Server.Kestrel");
builder.UseServer("Microsoft.AspNet.Server.Kestrel");
}

var app = builder.Build();
using (app.Start())
using (app)
{
app.Start();
var appLifeTime = app.Services.GetRequiredService<IApplicationLifetime>();

Console.CancelKeyPress += (sender, e) =>
Expand Down
31 changes: 17 additions & 14 deletions src/OmniSharp.Stdio/StdioServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class StdioServer : IServer
private readonly TextReader _input;
private readonly ISharedTextWriter _writer;
private readonly CancellationTokenSource _cancellation;
private readonly RequestFeature _requestFeature;
private readonly ResponseFeature _responseFeature;
private readonly IHttpContextFactory _httpContextFactory;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly object _lock = new object();

public StdioServer(TextReader input, ISharedTextWriter writer)
{
Expand All @@ -35,11 +34,11 @@ public StdioServer(TextReader input, ISharedTextWriter writer)
_httpContextFactory = new HttpContextFactory(_httpContextAccessor);

var features = new FeatureCollection();
_requestFeature = new RequestFeature();
_responseFeature = new ResponseFeature();
var requestFeature = new RequestFeature();
var responseFeature = new ResponseFeature();

features.Set<IHttpRequestFeature>(_requestFeature);
features.Set<IHttpResponseFeature>(_responseFeature);
features.Set<IHttpRequestFeature>(requestFeature);
features.Set<IHttpResponseFeature>(responseFeature);
Features = features;
}

Expand Down Expand Up @@ -96,20 +95,24 @@ private async Task HandleRequest<TContext>(string json, IHttpApplication<TContex
{
try
{
_requestFeature.Reset();
_requestFeature.Path = request.Command;
_requestFeature.Body = inputStream;
_requestFeature.Headers["Content-Type"] = new[] { "application/json" };
var features = new FeatureCollection();
var requestFeature = new RequestFeature();
var responseFeature = new ResponseFeature();

_responseFeature.Reset();
_responseFeature.Body = outputStream;
requestFeature.Path = request.Command;
requestFeature.Body = inputStream;
requestFeature.Headers["Content-Type"] = new[] { "application/json" };
responseFeature.Body = outputStream;

var context = application.CreateContext(Features);
features.Set<IHttpRequestFeature>(requestFeature);
features.Set<IHttpResponseFeature>(responseFeature);

var context = application.CreateContext(features);

// hand off request to next layer
await application.ProcessRequestAsync(context);

if (_responseFeature.StatusCode != 200)
if (responseFeature.StatusCode != 200)
{
response.Success = false;
}
Expand Down

0 comments on commit 3114911

Please sign in to comment.