mimic

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 11 Imported by: 10 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Mimic

GoDoc

Mimic chromium's HTTP/HTTP2 and TLS implementations.

Documentation
Installation
go get github.com/saucesteals/mimic

Usage

package main

import (
	http "github.com/saucesteals/fhttp"
	"github.com/saucesteals/mimic"
)

func main() {
	transport, _ := mimic.NewTransport(mimic.TransportOptions{
		Version:   "137.0.0.0",
		Brand:     mimic.BrandChrome,     // or mimic.BrandBrave, mimic.BrandEdge
		Platform:  mimic.PlatformWindows, // or mimic.PlatformMac, mimic.PlatformLinux
		Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
	})

	client := &http.Client{Transport: transport}

	req, _ := http.NewRequest(http.MethodGet, "https://tls.peet.ws/api/clean", nil)

	req.Header.Add("rtt", "50")
	req.Header.Add("accept", "text/html,*/*")
	req.Header.Add("x-requested-with", "XMLHttpRequest")
	req.Header.Add("downlink", "3.9")
	req.Header.Add("ect", "4g")
	req.Header.Add("sec-fetch-site", "same-origin")
	req.Header.Add("sec-fetch-mode", "cors")
	req.Header.Add("sec-fetch-dest", "empty")
	req.Header.Add("accept-encoding", "gzip, deflate, br")
	req.Header.Add("accept-language", "en,en_US;q=0.9")
	// mimic automatically sets: user-agent, sec-ch-ua, sec-ch-ua-mobile, sec-ch-ua-platform

	// optional header order
	// req.Header[http.HeaderOrderKey] = []string{
	// 	"user-agent", "sec-ch-ua", "sec-ch-ua-mobile", ...
	// }

	res, _ := client.Do(req)

	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedVersion = errors.New("mimic: unsupported version")
)

Functions

This section is empty.

Types

type Brand

type Brand string
const (
	BrandChrome Brand = "Google Chrome"
	BrandBrave  Brand = "Brave"
	BrandEdge   Brand = "Microsoft Edge"
)

type ClientSpec

type ClientSpec struct {
	HTTP2Options *HTTP2Options
	GetTlsSpec   func() *utls.ClientHelloSpec
	// contains filtered or unexported fields
}

func Chromium

func Chromium(brand Brand, version string) (*ClientSpec, error)

func (*ClientSpec) ClientHintUA

func (c *ClientSpec) ClientHintUA() string

ClientHintUA returns the "sec-ch-ua" header value for the mimicked client.

func (*ClientSpec) ConfigureTransport

func (c *ClientSpec) ConfigureTransport(t1 *http.Transport) *http.Transport

ConfigureTransport configures a http.Transport to follow the client's spec Returns the given Transport for convenience

func (*ClientSpec) PseudoHeaderOrder

func (c *ClientSpec) PseudoHeaderOrder() []string

PseudoHeaderOrder returns the pseudo header order for the mimicked client.

func (*ClientSpec) Version

func (c *ClientSpec) Version() string

Version returns the version for the mimicked client..

type HTTP2Options

type HTTP2Options struct {
	Settings          []http2.Setting
	PseudoHeaderOrder []string
	MaxHeaderListSize uint32
	InitialWindowSize uint32
	HeaderTableSize   uint32
}

type Platform

type Platform string
const (
	PlatformWindows Platform = "win"
	PlatformMac     Platform = "mac"
	PlatformLinux   Platform = "linux"
)

type Transport

type Transport struct {
	Transport         http.RoundTripper
	PseudoHeaderOrder []string
	DefaultHeaders    http.Header
}

Transport is a Transport that takes care of: - Randomizing the header order (if not set) - Pseudo Header Order - Default Headers. See NewTransport for its default headers.

func NewTransport

func NewTransport(opts TransportOptions) (*Transport, error)

NewTransport creates a new Transport for the given options Given a Chromium browser's brand, version and platform, it will create a new Transport that mimics the following: - Pseudo Header Order - Sec-Ch-Ua - Sec-Ch-Ua-Mobile - Sec-Ch-Ua-Platform - User-Agent

See Transport for more details.

func (*Transport) CloseIdleConnections added in v1.0.2

func (t *Transport) CloseIdleConnections()

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

type TransportOptions

type TransportOptions struct {
	// Version is the Chromium version of the browser to mimic
	Version string

	// Brand is the brand of the browser to mimic
	Brand Brand

	// Platform is the platform of the browser to mimic
	Platform Platform

	// Transport is the transport to use for the browser
	// If nil, a new http.Transport will be created
	Transport *http.Transport
}

Directories

Path Synopsis
examples
chrome command

Jump to

Keyboard shortcuts

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