Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse JsonSerializer in the HTTP server #1073

Merged
merged 2 commits into from
Jan 8, 2018
Merged
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
8 changes: 4 additions & 4 deletions src/OmniSharp.Host/WorkspaceInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void Initialize(
{
try
{
var projectConfiguration = configuration.GetSection((string)projectSystem.Key);
var projectConfiguration = configuration.GetSection(projectSystem.Key);
var enabledProjectFlag = projectConfiguration.GetValue<bool>("enabled", defaultValue: true);
if (enabledProjectFlag)
{
Expand All @@ -45,7 +45,7 @@ public static void Initialize(
{
var message = $"The project system '{projectSystem.GetType().FullName}' threw exception during initialization.";
// if a project system throws an unhandled exception it should not crash the entire server
LoggerExceptions.LogError((ILogger)logger, e, message);
logger.LogError(e, message);
}
}

Expand All @@ -61,7 +61,7 @@ public static void Initialize(
ProvideWorkspaceOptions(compositionHost, workspace, options, logger);
});

LoggerExtensions.LogInformation((ILogger)logger, "Configuration finished.");
logger.LogInformation("Configuration finished.");
}

private static void ProvideWorkspaceOptions(
Expand All @@ -83,7 +83,7 @@ private static void ProvideWorkspaceOptions(
catch (Exception e)
{
var message = $"The workspace options provider '{providerName}' threw exception during initialization.";
LoggerExceptions.LogError(logger, e, message);
logger.LogError(e, message);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/OmniSharp.Http/Middleware/EndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public async Task Invoke(HttpContext httpContext)
Command = endpoint,
ArgumentsStream = httpContext.Request.Body
});
MiddlewareHelpers.WriteTo(httpContext.Response, response);

httpContext.Response.WriteJson(response);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

namespace OmniSharp.Http.Middleware
{
static class MiddlewareHelpers
static class MiddlewareExtensions
{
private static readonly Encoding _encoding = new System.Text.UTF8Encoding(false);
private static readonly JsonSerializer _jsonSerializer = JsonSerializer.Create();
private static readonly Encoding _encoding = new UTF8Encoding(false);

public static void WriteTo(HttpResponse response, object value)
public static void WriteJson(this HttpResponse response, object value)
{
using (var writer = new StreamWriter(response.Body, _encoding, 1024, true))
using (var jsonWriter = new JsonTextWriter(writer))
{
jsonWriter.CloseOutput = false;
var jsonSerializer = JsonSerializer.Create(/*TODO: SerializerSettings*/);
jsonSerializer.Serialize(jsonWriter, value);
_jsonSerializer.Serialize(jsonWriter, value);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/OmniSharp.Http/Middleware/StatusMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public async Task Invoke(HttpContext httpContext)
var endpoint = httpContext.Request.Path.Value;
if (endpoint == OmniSharpEndpoints.CheckAliveStatus)
{
MiddlewareHelpers.WriteTo(httpContext.Response, true);
httpContext.Response.WriteJson(true);
return;
}

if (endpoint == OmniSharpEndpoints.CheckReadyStatus)
{
MiddlewareHelpers.WriteTo(httpContext.Response, _workspace.Initialized);
httpContext.Response.WriteJson(_workspace.Initialized);
return;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/OmniSharp.Http/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public void Configure(
IApplicationBuilder app,
IServiceProvider serviceProvider,
ILoggerFactory loggerFactory,
IEventEmitter eventEmitter,
ISharedTextWriter writer,
HttpEnvironment httpEnvironment,
IOptionsMonitor<OmniSharpOptions> options)
HttpEnvironment httpEnvironment)
{
var workspace = _compositionHost.GetExport<OmniSharpWorkspace>();
var logger = loggerFactory.CreateLogger<Startup>();
Expand Down