mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 04:42:00 +08:00
[assetHandler] Allow middleware to set the content-type for an assets file (#2286)
This commit is contained in:
parent
8c7fa4cf4c
commit
8f92cf1074
@ -154,16 +154,19 @@ func (d *assetHandler) serveFSFile(rw http.ResponseWriter, req *http.Request, fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buf [512]byte
|
var buf [512]byte
|
||||||
n, err := file.Read(buf[:])
|
var n int
|
||||||
if err != nil && err != io.EOF {
|
if _, haveType := rw.Header()[HeaderContentType]; !haveType {
|
||||||
return err
|
// Detect MimeType by sniffing the first 512 bytes
|
||||||
}
|
n, err = file.Read(buf[:])
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Detect MimeType by sniffing the first 512 bytes
|
// Do the custom MimeType sniffing even though http.ServeContent would do it in case
|
||||||
// Do the custom MimeType sniffing even though http.ServeContent would do it in case
|
// of an io.ReadSeeker. We would like to have a consistent behaviour in both cases.
|
||||||
// of an io.ReadSeeker. We would like to have a consistent behaviour in both cases.
|
if contentType := GetMimetype(filename, buf[:n]); contentType != "" {
|
||||||
if contentType := GetMimetype(filename, buf[:n]); contentType != "" {
|
rw.Header().Set(HeaderContentType, contentType)
|
||||||
rw.Header().Set(HeaderContentType, contentType)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileSeeker, _ := file.(io.ReadSeeker); fileSeeker != nil {
|
if fileSeeker, _ := file.(io.ReadSeeker); fileSeeker != nil {
|
||||||
|
@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
- Added Webview GPU acceleration options for [Windows](/docs/reference/options#webviewgpuisdisabled) and [Linux](/docs/reference/options#webviewgpupolicy). Added by @Lyimmi in [PR](https://github.com/wailsapp/wails/pull/2266)
|
- Added Webview GPU acceleration options for [Windows](/docs/reference/options#webviewgpuisdisabled) and [Linux](/docs/reference/options#webviewgpupolicy). Added by @Lyimmi in [PR](https://github.com/wailsapp/wails/pull/2266)
|
||||||
- Added `EnableFraudulentWebsiteDetection` option to opt-in to scan services for fraudulent content, such as malware or phishing attempts. Older releases had the scan services per default activated. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2269)
|
- Added `EnableFraudulentWebsiteDetection` option to opt-in to scan services for fraudulent content, such as malware or phishing attempts. Older releases had the scan services per default activated. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2269)
|
||||||
|
- Allow an [AssetServer Middleware](/docs/reference/options#middleware) to specify the `Content-Type` of a file served by the [Assets](/docs/reference/options#assets-1) `fs.FS`. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2286)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Improved fullscreen mode for frameless window on Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279), [PR](https://github.com/wailsapp/wails/pull/2288) and [PR](https://github.com/wailsapp/wails/pull/2299)
|
- Improved fullscreen mode for frameless window on Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279), [PR](https://github.com/wailsapp/wails/pull/2288) and [PR](https://github.com/wailsapp/wails/pull/2299)
|
||||||
|
Loading…
Reference in New Issue
Block a user