webproxy

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package webproxy reverse-proxies a browser to an upstream web app and rewrites the response so the app works under a gateway sub-path. A plugin resolves how to reach the upstream and hands the request here for proxying, response rewriting, and the in-scope service worker.

Index

Constants

View Source
const PrefixCookieName = "shellcn_webproxy_prefix"

PrefixCookieName marks the active proxy prefix for same-origin root navigation recovery in the gateway fallback. The value is not secret.

View Source
const SWFile = "__shellcn_sw.js"

SWFile is the in-scope service worker that re-routes the app's root-absolute requests (bundler chunks, dynamic imports, CSS) under the proxy prefix.

Variables

This section is empty.

Functions

func IsTLSPort

func IsTLSPort(port int) bool

IsTLSPort is a best-effort guess that a port serves TLS, by the conventional "443" suffix (443, 8443, 9443, …). Used only when no protocol metadata exists.

func Serve

func Serve(w http.ResponseWriter, r *http.Request, o Options)

Serve reverse-proxies r to the upstream and rewrites the response so the app's absolute paths, redirects, fetches, and assets resolve back under PublicPrefix.

func ServeWorker

func ServeWorker(w http.ResponseWriter, prefix string)

ServeWorker returns the service worker. Served from under the prefix, its default scope is the proxy path, so it controls the app's page and rewrites any root-absolute request it makes back under the prefix.

func WebSchemeFromName

func WebSchemeFromName(name string) (scheme string, ok bool)

WebSchemeFromName reads "http"/"https" from a port's conventional name (a Kubernetes/Swarm port name), reporting ok=false when it names no web protocol.

Types

type Options

type Options struct {
	// Base is the upstream's scheme://host; Transport dials it.
	Base      *url.URL
	Transport http.RoundTripper
	// UpstreamPath/UpstreamRawPath is the path to request on the upstream.
	UpstreamPath    string
	UpstreamRawPath string
	// PublicPrefix is the gateway path the app is served under (for rewriting).
	PublicPrefix string
	// SourcePrefix is a prefix the upstream injects into the app's links and must be
	// mapped back to PublicPrefix. Empty when the app emits its own root-relative paths.
	SourcePrefix string
	// WebSocket tunes how WebSocket upgrades are forwarded (see WebSocketOptions).
	WebSocket WebSocketOptions
}

Options describes one proxied request.

type WebSocketOptions

type WebSocketOptions struct {
	// KeepBrowserOrigin forwards the browser's Origin unchanged instead of mapping it
	// to the upstream origin.
	KeepBrowserOrigin bool
	// KeepForwardedHeaders forwards the gateway's Forwarded/X-Forwarded-* headers
	// instead of stripping them.
	KeepForwardedHeaders bool
}

WebSocketOptions tunes WebSocket upgrade forwarding. Both normalizations are on by default because they let the common upstream accept a gateway-proxied upgrade; set a field to opt out for an upstream that needs the original values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL