private Task ProcessSend(HttpContext context) { var connectionId = context.Request.Query["id"]; if (StringValues.IsNullOrEmpty(connectionId)) { throw new InvalidOperationException("Missing connection id"); } ConnectionState state; if (_manager.TryGetConnection(connectionId, out state)) { // If we received an HTTP POST for the connection id and it's not an HttpChannel then fail. // You can't write to a TCP channel directly from here. var httpChannel = state.Connection.Channel as HttpChannel; if (httpChannel == null) { throw new InvalidOperationException("No channel"); } return(context.Request.Body.CopyToAsync(httpChannel.Input)); } throw new InvalidOperationException("Unknown connection id"); }
private async Task <DefaultConnectionContext> GetConnectionAsync(HttpContext context) { var connectionId = GetConnectionId(context); if (StringValues.IsNullOrEmpty(connectionId)) { // There's no connection ID: bad request context.Response.StatusCode = StatusCodes.Status400BadRequest; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Connection ID required"); return(null); } if (!_manager.TryGetConnection(connectionId, out var connection)) { // No connection with that ID: Not Found context.Response.StatusCode = StatusCodes.Status404NotFound; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("No Connection with that ID"); return(null); } return(connection); }