Code Monkey home page Code Monkey logo

Comments (9)

kataras avatar kataras commented on August 25, 2024 10

@xXLokerXx @majidbigdeli There is no issue with neffos at all, you don't need to delete a header or things like that, this happesn only on Gorilla websocket upgrader because it has a CheckOrigin field which by-default allows only same-origin. So the solution is to modify that to allow everything - you don't need to catch anything there - neffos + cors will do the job. The gorilla websocket's check origin is type of:

func (r *http.Request) bool

Example Code:

import "github.com/kataras/neffos"
import "github.com/kataras/neffos/gorilla"
import gorillaWs "github.com/gorilla/websocket"

// [...]
websocketServer := websocket.New(
	gorilla.Upgrader(gorillaWs.Upgrader{CheckOrigin: func(*http.Request) bool{return true}}),
	serverEvents)

Hope that helped!

from neffos.

majidbigdeli avatar majidbigdeli commented on August 25, 2024 1

@kataras yes . Gorilla websocket upgrader has a CheckOrigin field . Thank you.

from neffos.

kataras avatar kataras commented on August 25, 2024

@majidbigdeli I know that you are using websockets+cors middleware, so I have to ask you too, do you have the same issue with cors on websockets?

from neffos.

majidbigdeli avatar majidbigdeli commented on August 25, 2024

@kataras I have not issue with cors .

from neffos.

majidbigdeli avatar majidbigdeli commented on August 25, 2024

@xXLokerXx please change websocket.DefaultGorillaUpgrader to websocket.DefaultGobwasUpgrader it is work .

from neffos.

majidbigdeli avatar majidbigdeli commented on August 25, 2024

@kataras

WebSocket connection to 'ws://localhost:3001/echo?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU' failed: Error during WebSocket handshake: Unexpected response code: 403

it issue related to DefaultGorillaUpgrader in my test .
with DefaultGobwasUpgrader it is work .

from neffos.

xXLokerXx avatar xXLokerXx commented on August 25, 2024

Yes, that help me a lot, i'll implement right now
thanks @kataras and @majidbigdeli
im really thankfully for help

from neffos.

kataras avatar kataras commented on August 25, 2024

You are welcome @xXLokerXx of course!

from neffos.

Kevinlinpr avatar Kevinlinpr commented on August 25, 2024

it works.

@xXLokerXx @majidbigdeli There is no issue with neffos at all, you don't need to delete a header or things like that, this happesn only on Gorilla websocket upgrader because it has a CheckOrigin field which by-default allows only same-origin. So the solution is to modify that to allow everything - you don't need to catch anything there - neffos + cors will do the job. The gorilla websocket's check origin is type of:

func (r *http.Request) bool

Example Code:

import "github.com/kataras/neffos"
import "github.com/kataras/neffos/gorilla"
import gorillaWs "github.com/gorilla/websocket"

// [...]
websocketServer := websocket.New(
	gorilla.Upgrader(gorillaWs.Upgrader{CheckOrigin: func(*http.Request) bool{return true}}),
	serverEvents)

Hope that helped!

it works.

from neffos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.