mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 07:29:56 +08:00

* 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
39 lines
1.2 KiB
Go
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
|
|
}
|