Skip to content

Commit 6b00c16

Browse files
committed
refactor: refactored ARCHITECTURE.md and 10 others
- Updated ARCHITECTURE.md - Updated PLAN.md - Updated README.md
1 parent c6b8270 commit 6b00c16

11 files changed

Lines changed: 23 additions & 23 deletions

File tree

ARCHITECTURE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The relay server terminates only the browser WebSocket and yamux session. It use
5454
| Service Worker | `web/sw.js` | Classifies every controlled request, blocks unknowns, manages in-memory tab/entry state, requires per-tab capability tokens on privileged runtime bridge messages, calls the WASM kernel, exposes runtime bridge APIs. |
5555
| Runtime prelude | `web/runtime-prelude.js`, `web/worker-prelude.js` | Installs target-realm containment hooks before target scripts run. Main-window WebSocket/navigation/form/history/location/storage/worker/iframe/device APIs are hooked; main-window fetch/XHR/EventSource are not runtime-polyfilled today. Worker `fetch` is bridged through `/__zp/api/fetch`. Patched function source strings, Canvas/Audio extraction, and speech voices receive basic masking to reduce runtime self-fingerprinting, not to provide full anti-bot spoofing. |
5656
| WASM kernel | `cmd/wasm-kernel/main.go`, `internal/swhttp/*` | Converts JS `Request`/`Response`, initializes transport, owns target HTTP and WebSocket execution. |
57-
| Transport | `internal/wsconn/*`, `internal/yamuxconn/*`, `internal/socks5/*`, `internal/utlskernel/*`, `internal/http1/*`, `internal/wsproto/*` | Browser WebSocket `net.Conn`, yamux streams, SOCKS5 DOMAINNAME CONNECT, uTLS, HTTP/2 and HTTP/1.1 target fetch, target WebSocket upgrade/framing. |
57+
| Transport | `internal/wsconn/*`, `internal/yamuxconn/*`, `internal/socks5/*`, `internal/utlskernel/*`, `internal/zphttp/*`, `internal/wsproto/*` | Browser WebSocket `net.Conn`, yamux streams, SOCKS5 DOMAINNAME CONNECT, uTLS, HTTP/2 and HTTP/1.1 target fetch, target WebSocket upgrade/framing. |
5858
| HTML/header/cookie policy | `internal/htmltx/*`, `internal/headers/*`, `internal/cookiejar/*`, `internal/zpiso/*` | HTML transformation, safe response header constructor policy, target cookie jar, Tor isolation token derivation. |
5959
| Relay server | `cmd/zeroproxy-server/main.go` | Serves assets, accepts `/__zp/ws-pipe` with Gorilla WebSocket, and bridges yamux streams to the configured Tor SOCKS5 address. |
6060

@@ -67,7 +67,7 @@ The relay server terminates only the browser WebSocket and yamux session. It use
6767
5. The WASM kernel ensures one long-lived WebSocket connection to `/__zp/ws-pipe`, wraps it in a yamux client, and opens one yamux stream per target TCP connection.
6868
6. Each target connection performs SOCKS5 `CONNECT` with DOMAINNAME ATYP and a Tor `IsolateSOCKSAuth` username derived from the tab stream-isolation key and target site.
6969
7. HTTPS fetch targets advertise `h2` and `http/1.1` through uTLS ALPN; target WebSocket connections advertise only `http/1.1`.
70-
8. `internal/http1` dispatches negotiated `h2` connections through `golang.org/x/net/http2.ClientConn`; HTTP/1.1 fallback writes a direct request and reads the response with `http.ReadResponse`.
70+
8. `internal/zphttp` dispatches negotiated `h2` connections through `golang.org/x/net/http2.ClientConn`; HTTP/1.1 fallback writes a direct request and reads the response with `http.ReadResponse`.
7171
9. Redirects are followed inside the kernel so raw `Location` headers are not exposed to browser code.
7272
10. HTML document responses are transformed: runtime prelude is injected, document navigation URLs are rewritten to encrypted `/p/<encrypted>#k=<key>` routes, risky tags and headers are removed, and the browser receives a same-origin `Response` with ZeroProxy CSP.
7373

@@ -99,7 +99,7 @@ The Service Worker keeps tab, entry, client-context, route, and stream maps in m
9999

100100
The Go WASM kernel exposes `__zp_kernel_init`, `__go_jshttp`, `__zp_stream`, and `__zp_cookie_set` to the Service Worker. Initialization creates a browser WebSocket to `/__zp/ws-pipe`; the relay accepts it with Gorilla WebSocket and adapts binary messages to a stream-oriented `net.Conn`. A yamux client/server session runs over that connection, and per-target yamux streams are bridged by the relay to Tor SOCKS5.
101101

102-
`internal/http1` builds sanitized target requests, applies the cookie jar, follows redirects up to `MaxRedirects`, dispatches HTTPS fetches to HTTP/2 when ALPN selects `h2`, and falls back to direct HTTP/1.1 request/response handling otherwise. HTTP/2 client connections and reusable HTTP/1.1 idle connections are pooled only within the same target authority, tab, and Tor isolation token. Idle target connections use a browser-style 90 second timeout; HTTP/1.1 connections are reused only after the response body reaches EOF and are closed on partial body cancellation or `Connection: close`. Target WebSocket support stays HTTP/1.1 Upgrade through `internal/wsproto` and the runtime `WebSocket` wrapper.
102+
`internal/zphttp` builds sanitized target requests, applies the cookie jar, follows redirects up to `MaxRedirects`, dispatches HTTPS fetches to HTTP/2 when ALPN selects `h2`, and falls back to direct HTTP/1.1 request/response handling otherwise. HTTP/2 client connections and reusable HTTP/1.1 idle connections are pooled only within the same target authority, tab, and Tor isolation token. Idle target connections use a browser-style 90 second timeout; HTTP/1.1 connections are reused only after the response body reaches EOF and are closed on partial body cancellation or `Connection: close`. Target WebSocket support stays HTTP/1.1 Upgrade through `internal/wsproto` and the runtime `WebSocket` wrapper.
103103

104104
`internal/swhttp.ResponseToJS` constructs JavaScript `Response` objects with a `ReadableStream` backed by the Go response body. Document HTML transformation uses `htmltx.TransformTo` through an `io.Pipe`, so transformed HTML can flow to the browser without first buffering the full document. Request/upload body conversion and browser backpressure/cancellation fidelity are still prototype-level.
105105

PLAN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Browser tab
5656
│ ├─ yamux: multiplexed target streams over the wsconn session
5757
│ ├─ socks5: DOMAINNAME CONNECT + SOCKS auth isolation
5858
│ ├─ utls: target TLS client in WASM
59-
│ ├─ http1: net/http + net/textproto based HTTP/1.1 engine
59+
│ ├─ zphttp: target HTTP/2 and HTTP/1.1 engine
6060
│ ├─ htmltx: x/net/html stream transform
6161
│ │ ├─ runtime prelude injection
6262
│ │ ├─ topbar injection
@@ -313,7 +313,7 @@ internal/zpiso/
313313
token.go // stream isolation token derivation
314314
internal/utlskernel/
315315
dial.go // uTLS UClient over yamux+socks5
316-
internal/http1/
316+
internal/zphttp/
317317
roundtrip.go // net/http Request + net/textproto response parse
318318
redirect.go // internal redirect engine
319319
internal/htmltx/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ These checks cover source/unit policy invariants, buildability, and a local-brow
121121
| `web/runtime-prelude.js`, `web/worker-prelude.js` | Target-realm containment hooks and worker bootstrap. |
122122
| `cmd/wasm-kernel` | Go WASM transport kernel exposed to the Service Worker. |
123123
| `cmd/zeroproxy-server` | Static asset server and Gorilla WebSocket/yamux-to-Tor relay. |
124-
| `internal/http1`, `internal/socks5`, `internal/utlskernel`, `internal/wsproto`, `internal/yamuxconn`, `internal/wsconn` | Target transport path. |
124+
| `internal/zphttp`, `internal/socks5`, `internal/utlskernel`, `internal/wsproto`, `internal/yamuxconn`, `internal/wsconn` | Target transport path. |
125125
| `internal/htmltx`, `internal/headers`, `internal/cookiejar`, `internal/shareurl`, `internal/zpiso` | HTML rewriting, response header policy, cookie handling, share URL envelope, Tor isolation tokens. |
126126
| `test/js`, `test/e2e`, `internal/*/*_test.go` | JavaScript source-policy tests, Puppeteer browser E2E tests, and Go unit tests. |
127127
| `.github/workflows/ci.yml` | GitHub Actions CI for Go tests, JavaScript/Puppeteer tests, WASM build, and relay server build. |

cmd/wasm-kernel/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import (
1818
"github.com/gosuda/zeroproxy/internal/cookiejar"
1919
"github.com/gosuda/zeroproxy/internal/headers"
2020
"github.com/gosuda/zeroproxy/internal/htmltx"
21-
"github.com/gosuda/zeroproxy/internal/http1"
2221
"github.com/gosuda/zeroproxy/internal/swhttp"
2322
"github.com/gosuda/zeroproxy/internal/wsconn"
2423
"github.com/gosuda/zeroproxy/internal/wsproto"
2524
"github.com/gosuda/zeroproxy/internal/yamuxconn"
25+
"github.com/gosuda/zeroproxy/internal/zphttp"
2626
)
2727

2828
type Kernel struct {
2929
mu sync.Mutex
30-
engine *http1.Engine
31-
tabs map[string]*http1.TabState
30+
engine *zphttp.Engine
31+
tabs map[string]*zphttp.TabState
3232
}
3333

34-
func NewKernel() *Kernel { return &Kernel{tabs: make(map[string]*http1.TabState)} }
34+
func NewKernel() *Kernel { return &Kernel{tabs: make(map[string]*zphttp.TabState)} }
3535

3636
func main() {
3737
k := NewKernel()
@@ -73,7 +73,7 @@ func (k *Kernel) ensure(ctx context.Context) error {
7373
}
7474
k.mu.Lock()
7575
if k.engine == nil {
76-
k.engine = &http1.Engine{Mux: sess}
76+
k.engine = &zphttp.Engine{Mux: sess}
7777
sess = nil
7878
}
7979
k.mu.Unlock()
@@ -228,11 +228,11 @@ func (k *Kernel) jsStream(this js.Value, args []js.Value) any {
228228
})
229229
}
230230

231-
func (k *Kernel) tabFor(req *http.Request) *http1.TabState {
231+
func (k *Kernel) tabFor(req *http.Request) *zphttp.TabState {
232232
return k.tabFromValues(req.Header.Get("X-Zp-Tab-Id"), req.Header.Get("X-Zp-Stream-Isolation-Key"))
233233
}
234234

235-
func (k *Kernel) tabFromValues(tabID, keyB64 string) *http1.TabState {
235+
func (k *Kernel) tabFromValues(tabID, keyB64 string) *zphttp.TabState {
236236
if tabID == "" {
237237
tabID = "default"
238238
}
@@ -246,7 +246,7 @@ func (k *Kernel) tabFromValues(tabID, keyB64 string) *http1.TabState {
246246
key = make([]byte, 32)
247247
_, _ = rand.Read(key)
248248
}
249-
t := &http1.TabState{TabID: tabID, CookieJar: cookiejar.New(), StreamIsolationKey: key}
249+
t := &zphttp.TabState{TabID: tabID, CookieJar: cookiejar.New(), StreamIsolationKey: key}
250250
k.tabs[tabID] = t
251251
return t
252252
}

internal/wsproto/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"strings"
1616
"sync"
1717

18-
"github.com/gosuda/zeroproxy/internal/http1"
18+
"github.com/gosuda/zeroproxy/internal/zphttp"
1919
)
2020

2121
const guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
@@ -34,7 +34,7 @@ type Conn struct {
3434
mu sync.Mutex
3535
}
3636

37-
func Dial(ctx context.Context, engine *http1.Engine, target *url.URL, protocols []string, tab *http1.TabState) (*Conn, *http.Response, error) {
37+
func Dial(ctx context.Context, engine *zphttp.Engine, target *url.URL, protocols []string, tab *zphttp.TabState) (*Conn, *http.Response, error) {
3838
if target.Scheme != "ws" && target.Scheme != "wss" {
3939
return nil, nil, fmt.Errorf("TARGET_PROTOCOL_BLOCKED")
4040
}
@@ -59,7 +59,7 @@ func Dial(ctx context.Context, engine *http1.Engine, target *url.URL, protocols
5959
req.Header.Set("Upgrade", "websocket")
6060
req.Header.Set("Sec-WebSocket-Version", "13")
6161
req.Header.Set("Sec-WebSocket-Key", key)
62-
req.Header.Set("User-Agent", http1.TargetUserAgent)
62+
req.Header.Set("User-Agent", zphttp.TargetUserAgent)
6363
if len(protocols) > 0 {
6464
req.Header.Set("Sec-WebSocket-Protocol", strings.Join(protocols, ", "))
6565
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package http1
1+
package zphttp
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package http1
1+
package zphttp
22

33
import (
44
"bufio"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package http1
1+
package zphttp
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package http1
1+
package zphttp
22

33
import (
44
"bufio"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package http1
1+
package zphttp
22

33
import (
44
"bufio"

0 commit comments

Comments
 (0)