network

package
v0.0.0-...-bda59f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SOCKS4 = iota
	SOCKS4A
)
View Source
const DefaultMaxBodySize = 10 << 20

Variables

This section is empty.

Functions

func BuildProxyPath

func BuildProxyPath(target string, headers map[string]string, tlsProfile string) string

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

func BuildProxyURL(host, target string, headers map[string]string, tlsProfile string) string

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 DeleteFile(filePath string) error

func Dialer

func Dialer(protocol int, proxyAddr, userID string, timeout time.Duration) func(string, string) (net.Conn, error)

func FasthttpDialer

func FasthttpDialer(protocol int, proxyAddr, userID string, timeout time.Duration) func(string) (net.Conn, error)

func GetCookies

func GetCookies(u string) ([]*http.Cookie, error)

func GetDecompressedReader

func GetDecompressedReader(res *fasthttp.Response) (io.Reader, error)

GetDecompressedReader returns an io.Reader that automatically decompresses the response body based on the Content-Encoding header. Supports gzip, deflate, brotli, and zstd.

func Init

func Init()

func PrepareProxy

func PrepareProxy(option *RequestOptions, targetURL string) (*fasthttp.Client, error)

func Proxy

func Proxy(ctx *fasthttp.RequestCtx)

func ReadAll

func ReadAll(res *fasthttp.Response) ([]byte, error)

ReadAll reads the entire response body and returns it as a byte slice.

func SanitizeFilename

func SanitizeFilename(name string) string

func SanitizeFolderName

func SanitizeFolderName(name string) string

func SanitizeFolderPath

func SanitizeFolderPath(dir string) string

func SaveFile

func SaveFile(filePath string, data *[]byte) error

func SetCookiesString

func SetCookiesString(u string, cookies []string) error

func SetMaxBodySize

func SetMaxBodySize(n int)

func TouchFile

func TouchFile(filePath string) (*os.File, error)

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 StringOrBytes interface {
	~string | ~[]byte
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL