Created
May 10, 2017 08:28
-
-
Save ondravondra/99c8645908a7fd74e0b01728cf9a38bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Startup | |
{ | |
/// <summary> | |
/// This hax is necessary for signalr2 to work | |
/// </summary> | |
private void HackInWebsockets(IAppBuilder app) | |
{ | |
app.Use((c, n) => | |
{ | |
c.Environment.Add("server.Capabilities", new Dictionary<string, object> | |
{ | |
{ "websocket.Version", "1.0" } | |
}); | |
var accept = c.Get<Action<IDictionary<string, object>, Func<IDictionary<string, object>, Task>>>("websocket.Accept"); | |
if (accept != null) | |
{ | |
c.Set<Action<IDictionary<string, object>, Func<IDictionary<string, object>, Task>>>("websocket.Accept", (_, hcb) => | |
{ | |
accept(_, aenv => | |
{ | |
aenv.Add(typeof(WebSocketContext).FullName, new HackedWebSocketContext((WebSocket)aenv[typeof(WebSocket).FullName])); | |
return hcb(aenv); | |
}); | |
}); | |
} | |
return n(); | |
}); | |
} | |
private class HackedWebSocketContext : WebSocketContext | |
{ | |
private readonly WebSocket webSocket; | |
public override Uri RequestUri => throw new NotImplementedException(); | |
public override NameValueCollection Headers => throw new NotImplementedException(); | |
public override string Origin => throw new NotImplementedException(); | |
public override IEnumerable<string> SecWebSocketProtocols => throw new NotImplementedException(); | |
public override string SecWebSocketVersion => throw new NotImplementedException(); | |
public override string SecWebSocketKey => throw new NotImplementedException(); | |
public override CookieCollection CookieCollection => throw new NotImplementedException(); | |
public override IPrincipal User => throw new NotImplementedException(); | |
public override bool IsAuthenticated => throw new NotImplementedException(); | |
public override bool IsLocal => throw new NotImplementedException(); | |
public override bool IsSecureConnection => throw new NotImplementedException(); | |
public override WebSocket WebSocket => webSocket; | |
public HackedWebSocketContext(WebSocket webSocket) | |
{ | |
this.webSocket = webSocket; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment