mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 03:20:09 +08:00

* [assetserver, darwin] Fix copying request headers by using strdup * [assetserver, linux] Fake some basic http headers for legacy webkit2 versions to support proxying requests to other servers This fixes the devserver on v2 for newer vite versions that use the custom scheme. * [v2, windows] 304 responses are going to hang the WebView2 so prevent them by removing cache related headers in the request. * [v2, dev] Now uses the custom schemes `wails://` on macOS and Linux for all Vite versions. Prevent missing reload after fast multiple savings on Linux and Windows.
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
//go:build linux && !(webkit2_36 || webkit2_40)
|
|
|
|
package webview
|
|
|
|
/*
|
|
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
|
|
|
#include "gtk/gtk.h"
|
|
#include "webkit2/webkit2.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"unsafe"
|
|
)
|
|
|
|
const Webkit2MinMinorVersion = 0
|
|
|
|
func webkit_uri_scheme_request_get_http_method(_ *C.WebKitURISchemeRequest) string {
|
|
return http.MethodGet
|
|
}
|
|
|
|
func webkit_uri_scheme_request_get_http_headers(_ *C.WebKitURISchemeRequest) http.Header {
|
|
// Fake some basic default headers that are needed if e.g. request are being proxied to the an external sever, like
|
|
// we do in the devserver.
|
|
h := http.Header{}
|
|
h.Add("Accept", "*/*")
|
|
h.Add("User-Agent", "wails.io/605.1.15")
|
|
return h
|
|
}
|
|
|
|
func webkit_uri_scheme_request_get_http_body(_ *C.WebKitURISchemeRequest) io.ReadCloser {
|
|
return http.NoBody
|
|
}
|
|
|
|
func webkit_uri_scheme_request_finish(req *C.WebKitURISchemeRequest, code int, header http.Header, stream *C.GInputStream, streamLength int64) error {
|
|
if code != http.StatusOK {
|
|
return fmt.Errorf("StatusCodes not supported: %d - %s", code, http.StatusText(code))
|
|
}
|
|
|
|
cMimeType := C.CString(header.Get(HeaderContentType))
|
|
C.webkit_uri_scheme_request_finish(req, stream, C.gint64(streamLength), cMimeType)
|
|
C.free(unsafe.Pointer(cMimeType))
|
|
return nil
|
|
}
|