web-worker-csp

command
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 6 Imported by: 0

README

Web Workers under Content Security Policy

HyperServe's browser-header middleware blocks blob: worker sources by default. This example opts into them for an application that deliberately creates Web Workers from blob URLs.

Run

The assets are relative to this directory:

cd examples/web-worker-csp
go run .

Open http://localhost:8080, start the worker, and inspect the response's Content-Security-Policy header.

Configuration

app, err := hyperserve.New(hyperserve.WithCSPWebWorkerSupport())
if err != nil {
    log.Fatal(err)
}

app.Use(hyperserve.HeadersMiddleware(app.Options()))

WithCSPWebWorkerSupport changes the configured CSP value; it does not attach middleware by itself. HeadersMiddleware reads the finalized snapshot and adds worker-src 'self' blob: and child-src 'self' blob: to responses.

Leave the option off unless the application needs blob-backed workers. It widens the set of script execution sources allowed by the browser policy.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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