1 //go:build !wasm
2 //:build !wasm
3 4 // Package httpproxy is the bridge for the smesh HTTP-proxy worker boundary.
5 // Two function sets in one package, used in different contexts:
6 //
7 // - Worker-internal (used only inside http-proxy.wasm):
8 // OnMessage, Post, Fetch, Cancel, RevokeBlob.
9 //
10 // - Consumer-side (used only inside app.wasm):
11 // Request, RequestCancel.
12 //
13 // Functions called only from one context are dead-code-eliminated by the
14 // linker for the other context, so the two function sets do not pollute
15 // each other's wasm imports.
16 package httpproxy
17 18 // === Consumer-side: app.wasm asking the worker to do a fetch ===
19 20 // Request asks the http-proxy worker to fetch url and return a Blob URL.
21 // onOK is called with (blobURL, contentType) on success.
22 // onFail is called with (status, errMsg) on failure.
23 // reqID must be unique per outstanding request; the same ID is used as the
24 // correlation key for matching the result.
25 // priority: higher values dispatched first; 0 is the default tier.
26 func Request(reqID int32, url string, priority int32,
27 onOK func(blobURL, contentType string),
28 onFail func(status int32, errMsg string)) {
29 panic("jsbridge")
30 }
31 32 // RequestCancel cancels an outstanding request by ID.
33 func RequestCancel(reqID int32) { panic("jsbridge") }
34 35 // === Worker-internal: http-proxy.wasm talking to its host shim ===
36 37 // OnMessage registers a handler for inbound messages.
38 // fn receives the raw string payload (JSON-array shape: ["TYPE", arg1, arg2, ...]).
39 // The same handler is invoked for messages from the page and for synthetic
40 // internal messages (__FETCH_OK, __FETCH_FAIL) that the JS shim re-injects
41 // after a fetch completes; the moxie code distinguishes by message type.
42 func OnMessage(fn func(msg string)) { panic("jsbridge") }
43 44 // Post sends a string message back to the page over the worker's natural
45 // postMessage channel.
46 func Post(msg string) { panic("jsbridge") }
47 48 // Fetch issues an HTTP GET against the smesh /proxy/<base64url> endpoint
49 // derived from url. The JS shim performs the fetch, builds a Blob URL on
50 // success, and re-injects the result into OnMessage as either
51 // ["__FETCH_OK", reqID, status, contentType, blobURL] or
52 // ["__FETCH_FAIL", reqID, status, errMsg].
53 func Fetch(reqID int32, url string) { panic("jsbridge") }
54 55 // Cancel aborts an in-flight fetch identified by reqID. No-op if the
56 // request has already completed or never started.
57 func Cancel(reqID int32) { panic("jsbridge") }
58 59 // RevokeBlob releases the underlying Blob held by a blob: URL. Call this
60 // when evicting from the LRU; without it the Blob is retained for the
61 // lifetime of the worker.
62 func RevokeBlob(url string) { panic("jsbridge") }
63