5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 07:29:56 +08:00
wails/v3/internal/assetserver/options.go
Fabio Massaioli d4096868e3
[v3] Fix and optimise assetserver (#4049)
* Fix and optimize content type sniffer

- Minimize copying and buffering
- Ensure it sniffs the full 512-bytes prefix

* Fix assorted warnings

* Cleanup error formatting

- Remove unnecessary formatting calls
- Fix invalid format strings
- Standardise logging calls

* Fix and optimize index fallback method

- Pass through non-404 responses correctly
- Do not buffer original response

* Test content sniffing and index fallback

* Update changelog

* Remove obsolete check

* Add safety checks in sniffer
2025-02-09 00:02:54 +11:00

39 lines
1.2 KiB
Go

package assetserver
import (
"errors"
"log/slog"
"net/http"
)
// Options defines the configuration of the AssetServer.
type Options struct {
// Handler which serves all the content to the WebView.
Handler http.Handler
// Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default
// request handler dynamically, e.g. implement specialized Routing etc.
// The Middleware is called to build a new `http.Handler` used by the AssetSever and it also receives the default
// handler used by the AssetServer as an argument.
//
// This middleware injects itself before any of Wails internal middlewares.
//
// If not defined, the default AssetServer request chain is executed.
//
// Multiple Middlewares can be chained together with:
// ChainMiddleware(middleware ...Middleware) Middleware
Middleware Middleware
// Logger is the logger used by the AssetServer. If not defined, no logging will be done.
Logger *slog.Logger
}
// Validate the options
func (o Options) Validate() error {
if o.Handler == nil && o.Middleware == nil {
return errors.New("AssetServer options invalid: either Handler or Middleware must be set")
}
return nil
}