public Task <Stream> UpgradeAsync() { if (!IsUpgradableRequest) { if (Request.ProtocolVersion != System.Net.HttpVersion.Version11) { throw new InvalidOperationException("Upgrade requires HTTP/1.1."); } throw new InvalidOperationException("This request cannot be upgraded because it has a body."); } if (Response.HasStarted) { throw new InvalidOperationException("This request cannot be upgraded, the response has already started."); } // Set the status code and reason phrase Response.StatusCode = StatusCodes.Status101SwitchingProtocols; Response.ReasonPhrase = HttpReasonPhrase.Get(StatusCodes.Status101SwitchingProtocols); Response.SendOpaqueUpgrade(); // TODO: Async Request.SwitchToOpaqueMode(); Response.SwitchToOpaqueMode(); var opaqueStream = new OpaqueStream(Request.Body, Response.Body); return(Task.FromResult <Stream>(opaqueStream)); }
public Task <Stream> UpgradeAsync() { if (!IsUpgradableRequest) { throw new InvalidOperationException("This request cannot be upgraded, it is incompatible."); } if (Response.HasStarted) { throw new InvalidOperationException("This request cannot be upgraded, the response has already started."); } // Set the status code and reason phrase Response.StatusCode = StatusCodes.Status101SwitchingProtocols; Response.ReasonPhrase = HttpReasonPhrase.Get(StatusCodes.Status101SwitchingProtocols); Response.SendOpaqueUpgrade(); // TODO: Async Request.SwitchToOpaqueMode(); Response.SwitchToOpaqueMode(); var opaqueStream = new OpaqueStream(Request.Body, Response.Body); return(Task.FromResult <Stream>(opaqueStream)); }