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

[feature] WebSocket support #99

Closed
benja-wu opened this issue Jul 2, 2021 · 0 comments · Fixed by #103
Closed

[feature] WebSocket support #99

benja-wu opened this issue Jul 2, 2021 · 0 comments · Fixed by #103
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@benja-wu
Copy link
Contributor

benja-wu commented Jul 2, 2021

Background

  • Easegress is popular for reverse proxy usage in production and development scenarios.
  • In reversed proxy use cases, WebSocket is a widely used protocol for a full-duplex communication solution between client and server. It relies on TCP.[1]
  • Many reverse proxy support WebSocket,e.g., NGINX[2], Traefik, and so on.

Proposal

  • Bring WebSocketServer as an BusinessController to Easegress. (Should treat it as an HTTPServer like traffic gate in the future. )
  • Using github.com/gorilla/websocket as the WebSocket client implementation, since it has rich features supproted and a quite active community.(15k star/2.5k fork) Comparing to the original golang.org/x/net/websocket package, it can receive fragmented message and send close message.[3]

Design

  1. Spec
kind: WebSocketServer
name: websocketSvr
https: false                  # client need to use http/https firstly for connection upgrade      
certBase64:
keyBase64:
port: 10020                   # proxy servers listening port

backend: ws://localhost:3001  # the reserved proxy target
                              #  Easegress will exame the backend URL's scheme, If it starts with `wss`,
                              #  then `wssCerBase64` and `wssKeyBase64` must not be empty

wssCertBase64:                # wss backend certificate in base64 format
wssKeyBase64:                 # wss backend key in base64 format
  1. Request sequence
   +--------------+                +--------------+                +--------------+  
   |              |  1             |              |   2            |              | 
   |   client     +--------------->|  Easegress   +--------------->|  websocket   |
   |              |<---------------+(WebSocketSvr)|<---------------+  backend     | 
   |              |  4             |              |   3            |              |
   +--------------+                +--------------+                +--------------+
  1. The WebSocketServer shares some configurations with HTTPServer. Since WebSocket runs on HTTP 1.1 only, and it works on opening two long-life goroutines for the reverse proxy scenario, it's quite different from the original Easegress' HTTPServer+Pipeline's process. So I decide not to implement it into HTTPServer and catalog it into TrafficGate in the first version right now.

  2. I will implement this WebSocketServer first version and try to figure out how to integrate with the original HTTPServer at the same time. (Moreover, multiple protocols supporting requirements, such as MQTT, TPC, are on the way... )

References

  1. https://datatracker.ietf.org/doc/html/rfc6455
  2. https://www.nginx.com/blog/websocket-nginx/
  3. https://github.com/gorilla/websocket
@benja-wu benja-wu added the enhancement New feature or request label Jul 2, 2021
@benja-wu benja-wu added this to the v1.0.2 milestone Jul 2, 2021
@benja-wu benja-wu self-assigned this Jul 2, 2021
@benja-wu benja-wu added this to To do in Easegress Project via automation Jul 2, 2021
@benja-wu benja-wu changed the title WeSocket support [feature] WeSocket support Jul 2, 2021
@benja-wu benja-wu changed the title [feature] WeSocket support [feature] WebSocket support Jul 2, 2021
@benja-wu benja-wu pinned this issue Jul 2, 2021
@benja-wu benja-wu unpinned this issue Jul 6, 2021
@benja-wu benja-wu linked a pull request Jul 6, 2021 that will close this issue
@benja-wu benja-wu moved this from To do to In progress in Easegress Project Jul 17, 2021
@benja-wu benja-wu moved this from In progress to Review in progress in Easegress Project Jul 17, 2021
Easegress Project automation moved this from Review in progress to Done Jul 20, 2021
xxx7xxxx pushed a commit that referenced this issue Jul 20, 2021
* [ws] add WebSocketServer

* [ws] close megaese#99

* [wc] fix make test failed

* [ws] correct log format

* [ws] refactor TLS validate and update comment

Co-authored-by: benjaminwu <yihengwu@megaease.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant