mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
add content negotiation feature, add context.ReadYAML and fix https://github.com/kataras/neffos/issues/1#issuecomment-515698536
Former-commit-id: 9753e3e45c7c24788b97814d3ecfb4b03f5ff414
This commit is contained in:
@@ -53,6 +53,8 @@
|
||||
};
|
||||
}
|
||||
|
||||
const username = window.prompt("Your username?");
|
||||
|
||||
async function runExample() {
|
||||
// You can omit the "default" and simply define only Events, the namespace will be an empty string"",
|
||||
// however if you decide to make any changes on this example make sure the changes are reflecting inside the ../server.go file as well.
|
||||
@@ -70,6 +72,10 @@
|
||||
addMessage(msg.Body);
|
||||
}
|
||||
}
|
||||
},{
|
||||
headers: {
|
||||
"X-Username": username,
|
||||
}
|
||||
});
|
||||
|
||||
// You can either wait to conenct or just conn.connect("connect")
|
||||
|
||||
@@ -42,7 +42,10 @@ func main() {
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(dialAndConnectTimeout))
|
||||
defer cancel()
|
||||
|
||||
client, err := websocket.Dial(ctx, websocket.DefaultGorillaDialer, endpoint, clientEvents)
|
||||
// username := "my_username"
|
||||
// dialer := websocket.GobwasDialer(websocket.GobwasDialerOptions{Header: websocket.GobwasHeader{"X-Username": []string{username}}})
|
||||
dialer := websocket.DefaultGobwasDialer
|
||||
client, err := websocket.Dial(ctx, dialer, endpoint, clientEvents)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -68,8 +68,17 @@ func main() {
|
||||
SigningMethod: jwt.SigningMethodHS256,
|
||||
})
|
||||
|
||||
idGen := func(ctx iris.Context) string {
|
||||
if username := ctx.GetHeader("X-Username"); username != "" {
|
||||
return username
|
||||
}
|
||||
|
||||
return websocket.DefaultIDGenerator(ctx)
|
||||
}
|
||||
|
||||
// serves the endpoint of ws://localhost:8080/echo
|
||||
websocketRoute := app.Get("/echo", websocket.Handler(websocketServer))
|
||||
// with optional custom ID generator.
|
||||
websocketRoute := app.Get("/echo", websocket.Handler(websocketServer, idGen))
|
||||
|
||||
if enableJWT {
|
||||
// Register the jwt middleware (on handshake):
|
||||
|
||||
Reference in New Issue
Block a user