Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom mux for Websocket servers #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anderspitman
Copy link

Implement custom mux for Websocket servers

Motivation:

I need to serve other HTTP content on the same mux as the websocket used by RSocket

Modifications:

Added a function for creating a WebsocketServerTransport with a mux passed in

Result:

Nothing broken, just added another function

@anderspitman
Copy link
Author

Note that I'm not sure this would be the best API for accomplishing this, but it was the easiest to get my code working. If this functionality is desired upstream I'm happy to implement it in another way pending a discussions of tradeoffs.

Copy link
Member

@jjeffcaii jjeffcaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jjeffcaii
Copy link
Member

Thanks for the PR :-)
PS: Please fix the unit tests to prevent from CI failure, thanks.

// NewWebsocketServerTransport creates a new server-side transport.
func NewWebsocketServerTransport(f ListenerFactory, path string, upgrader *websocket.Upgrader) ServerTransport {
func NewWebsocketServerTransport(f ListenerFactory, path string, upgrader *websocket.Upgrader, mux *http.ServeMux) ServerTransport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to keep the original NewWebsocketServerTransport method signature, I think.

For example, extract a private method:

func innerNewWebsocketServerTransport(f ListenerFactory, path string, upgrader *websocket.Upgrader, mux *http.ServeMux) ServerTransport {
      // original codes of NewWebsocketServerTransport
}

func NewWebsocketServerTransportWithMux(f ListenerFactory, path string, upgrader *websocket.Upgrader, mux *http.ServeMux) ServerTransport {
    return innerNewWebsocketServerTransport(f,path,upgrader,mux)
}

func NewWebsocketServerTransport(f ListenerFactory, path string, upgrader *websocket.Upgrader) ServerTransport {
    return innerNewWebsocketServerTransport(f,path,upgrader,nil)
}

jjeffcaii

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants