webproxy

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: GPL-3.0 Imports: 8 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 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 itself injects into the app's links
	// and that must be mapped back to PublicPrefix. Empty when proxying straight
	// to an app that emits its own root-relative paths.
	SourcePrefix string
	// WebSocket controls optional request normalization for upstreams that apply
	// strict browser-origin checks during WebSocket upgrades.
	WebSocket WebSocketOptions
}

Options describes one proxied request.

type WebSocketOptions

type WebSocketOptions struct {
	// RewriteOrigin maps the browser's Origin to the upstream origin for WebSocket
	// upgrades. This is needed by apps that reject gateway-origin upgrades.
	RewriteOrigin bool
	// StripForwardedHeaders removes gateway Forwarded/X-Forwarded-* context from
	// WebSocket upgrades. Some upstream apps reject upgrades when these are present.
	StripForwardedHeaders bool
}

Jump to

Keyboard shortcuts

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