[PR #334] [MERGED] enhance(http): Support websocket upgrades #2286

Closed
opened 2026-05-03 05:59:42 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fosrl/newt/pull/334
Author: @LaurenceJJones
Created: 4/29/2026
Status: Merged
Merged: 4/29/2026
Merged by: @oschwartz10612

Base: devHead: private-http-websocket


📝 Commits (2)

  • 8e19e47 Support websocket upgrades in private HTTP proxy
  • b33c3b8 Add some test scripts for ws and move to testing/

📊 Changes

6 files changed (+227 additions, -1 deletions)

View changed files

📝 netstack2/http_handler.go (+21 -1)
netstack2/http_handler_test.go (+97 -0)
📝 testing/udp_client.py (+0 -0)
📝 testing/udp_server.py (+0 -0)
testing/ws_client.py (+60 -0)
testing/ws_server.py (+49 -0)

📄 Description

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

Preserve optional ResponseWriter interfaces through statusCapture so httputil.ReverseProxy can hijack upgraded websocket connections for private http proxy. Add a regression test covering websocket traffic through the HTTP handler path.

How to test?

Added a golang test for regression but any private http application that uses websockets should now upgrade via the proxy.

Without exposing the funcs

INFO: 2026/04/29 07:20:27 HTTP handler: GET /socket?token=test -> http://127.0.0.1:40649
ERROR: 2026/04/29 07:20:27 HTTP handler: upstream error (GET /socket?token=test -> http://127.0.0.1:40649): can't switch protocols using non-Hijacker ResponseWriter type *netstack2.statusCapture
 --- FAIL: TestHTTPHandlerProxiesWebSocketUpgrade (0.00s)
http_handler_test.go:79: dial websocket through proxy: websocket: bad handshake
FAIL
FAIL  github.com/fosrl/newt/netstack2 0.004s
FAIL

with now succeeds

ok    github.com/fosrl/newt/netstack2 0.004s

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fosrl/newt/pull/334 **Author:** [@LaurenceJJones](https://github.com/LaurenceJJones) **Created:** 4/29/2026 **Status:** ✅ Merged **Merged:** 4/29/2026 **Merged by:** [@oschwartz10612](https://github.com/oschwartz10612) **Base:** `dev` ← **Head:** `private-http-websocket` --- ### 📝 Commits (2) - [`8e19e47`](https://github.com/fosrl/newt/commit/8e19e475bf3f552db8aee0984cbbf6063a2aaa52) Support websocket upgrades in private HTTP proxy - [`b33c3b8`](https://github.com/fosrl/newt/commit/b33c3b88497e17d64dcdc692e6531e18434ad793) Add some test scripts for ws and move to testing/ ### 📊 Changes **6 files changed** (+227 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netstack2/http_handler.go` (+21 -1) ➕ `netstack2/http_handler_test.go` (+97 -0) 📝 `testing/udp_client.py` (+0 -0) 📝 `testing/udp_server.py` (+0 -0) ➕ `testing/ws_client.py` (+60 -0) ➕ `testing/ws_server.py` (+49 -0) </details> ### 📄 Description ## Community Contribution License Agreement By creating this pull request, I grant the project maintainers an unlimited, perpetual license to use, modify, and redistribute these contributions under any terms they choose, including both the AGPLv3 and the Fossorial Commercial license terms. I represent that I have the right to grant this license for all contributed content. ## Description Preserve optional ResponseWriter interfaces through statusCapture so httputil.ReverseProxy can hijack upgraded websocket connections for private http proxy. Add a regression test covering websocket traffic through the HTTP handler path. ## How to test? Added a golang test for regression but any private http application that uses websockets should now upgrade via the proxy. Without exposing the funcs ``` INFO: 2026/04/29 07:20:27 HTTP handler: GET /socket?token=test -> http://127.0.0.1:40649 ERROR: 2026/04/29 07:20:27 HTTP handler: upstream error (GET /socket?token=test -> http://127.0.0.1:40649): can't switch protocols using non-Hijacker ResponseWriter type *netstack2.statusCapture --- FAIL: TestHTTPHandlerProxiesWebSocketUpgrade (0.00s) http_handler_test.go:79: dial websocket through proxy: websocket: bad handshake FAIL FAIL github.com/fosrl/newt/netstack2 0.004s FAIL ``` with now succeeds ``` ok github.com/fosrl/newt/netstack2 0.004s ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-03 05:59:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/newt#2286