Documentation
¶
Index ¶
- Constants
- func BuildProxyPath(target string, headers map[string]string, tlsProfile string) string
- func BuildProxyURL(host, target string, headers map[string]string, tlsProfile string) string
- func DeleteFile(filePath string) error
- func Dialer(protocol int, proxyAddr, userID string, timeout time.Duration) func(string, string) (net.Conn, error)
- func FasthttpDialer(protocol int, proxyAddr, userID string, timeout time.Duration) func(string) (net.Conn, error)
- func GetCookies(u string) ([]*http.Cookie, error)
- func GetDecompressedReader(res *fasthttp.Response) (io.Reader, error)
- func Init()
- func PrepareProxy(option *RequestOptions, targetURL string) (*fasthttp.Client, error)
- func Proxy(ctx *fasthttp.RequestCtx)
- func ReadAll(res *fasthttp.Response) ([]byte, error)
- func SanitizeFilename(name string) string
- func SanitizeFolderName(name string) string
- func SanitizeFolderPath(dir string) string
- func SaveFile(filePath string, data *[]byte) error
- func SetCookiesString(u string, cookies []string) error
- func SetMaxBodySize(n int)
- func TouchFile(filePath string) (*os.File, error)
- type RequestOptions
- type Response
- type StringOrBytes
- type TLSConfig
Constants ¶
const ( SOCKS4 = iota SOCKS4A )
const DefaultMaxBodySize = 10 << 20
Variables ¶
This section is empty.
Functions ¶
func BuildProxyPath ¶
BuildProxyPath is retained for callers that build server-relative paths (e.g. HLS child rewriting inside the proxy handler, which already knows the request origin). Prefer BuildProxyURL for anything handed to a client/player.
func BuildProxyURL ¶
BuildProxyURL converts a raw media/stream URL into an absolute proxy URL (host included) that, when requested by the player/reader, makes miru-core fetch the target server-side with the supplied headers applied. When tlsProfile is non-empty the fetch is routed through the browser-impersonating tls-client (required for TLS-fingerprinting CDNs).
host must be the origin the player reaches miru-core at (scheme://host, e.g. "http://localhost:3000"). It is required: a relative "/proxy/..." path is not directly requestable by a browser player, and (for HLS) every rewritten child segment/key must point back at the same origin. The host is NOT validated for reachability -- the caller owns that (usually config.Global).
func DeleteFile ¶
func FasthttpDialer ¶
func GetDecompressedReader ¶
GetDecompressedReader returns an io.Reader that automatically decompresses the response body based on the Content-Encoding header. Supports gzip, deflate, brotli, and zstd.
func PrepareProxy ¶
func PrepareProxy(option *RequestOptions, targetURL string) (*fasthttp.Client, error)
func Proxy ¶
func Proxy(ctx *fasthttp.RequestCtx)
func SanitizeFilename ¶
func SanitizeFolderName ¶
func SanitizeFolderPath ¶
func SetCookiesString ¶
func SetMaxBodySize ¶
func SetMaxBodySize(n int)
Types ¶
type RequestOptions ¶
type RequestOptions struct {
Headers map[string]string `json:"headers"`
Method string `json:"method"`
ProxyHost string `json:"proxy_host"`
ProxyScheme string `json:"proxy_scheme"`
ProxyUserName string `json:"proxy_username"`
ProxyPassword string `json:"proxy_password"`
RequestBody string `json:"request_body"`
RequestBodyRaw []byte `json:"request_body_raw"`
Timeout int `json:"timeout"`
// TLSConfig, when set, routes the request through a browser-impersonating
// tls-client instead of the default fasthttp client. Presence of this field
// (not any particular sub-field) is what triggers the tls-client path.
TLSConfig *TLSConfig `json:"tls_config,omitempty"`
}
type Response ¶
type Response[T StringOrBytes] struct { Res *fasthttp.Response Body T StatusCode int Headers map[string]string }
func FetchString ¶
func FetchString(url string, option *RequestOptions, readPreference func(*fasthttp.Response) ([]byte, error)) (Response[string], error)
FetchString is the non-generic string specialization of Request. It exists so the Scriggo (Go) extension runtime can invoke it: Scriggo's reflect-based callable cannot instantiate generic functions, so the golang runtime's Fetch delegates here instead of calling Request[string].
func Request ¶
func Request[T StringOrBytes](url string, option *RequestOptions, readPreference func(*fasthttp.Response) ([]byte, error)) (Response[T], error)
Request makes an HTTP request and returns the response as type T.
Parameters:
url: The URL to send the request to. option: Pointer to RequestOptions struct containing headers, method, proxy, etc. readPreference: Function to read and process the response body (e.g., io.ReadAll,io.Read,).
Returns:
The response body as type T (string or []byte), and an error if any occurred.
type StringOrBytes ¶
type TLSConfig ¶
type TLSConfig struct {
Profile string `json:"profile"`
UserAgent string `json:"userAgent,omitempty"`
DisableRedirect bool `json:"disableRedirect,omitempty"`
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}
TLSConfig configures the browser-impersonating tls-client transport. Profile is a named tls-client fingerprint such as "chrome_133" (see github.com/bogdanfinn/tls-client/profiles). An empty Profile falls back to the library default.