http

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MockTransport http.RoundTripper

MockTransport can be set during tests to intercept all HTTP/HTTPS requests created by UniRTM's DefaultTransport.

View Source
var ProxyBypassDomains = []string{
	"aliyun.com",
	"npmmirror.com",
	"tencent.com",
	"huaweicloud.com",
	"163.com",
	"ustc.edu.cn",
	"tsinghua.edu.cn",
	"sjtu.edu.cn",
	"bfsu.edu.cn",
	"lzu.edu.cn",
	"nju.edu.cn",
	"cqu.edu.cn",
	"hit.edu.cn",
	"zju.edu.cn",
	"douban.com",
	"rsproxy.cn",
	"r.cnpmjs.org",
	"goproxy.cn",
	"goproxy.io",
	"gems.ruby-china.com",
	"sn0wdr1am.com",
}

ProxyBypassDomains contains a list of common domestic mirror domains that should bypass any configured HTTP proxies to prevent connection drops.

Functions

func DefaultTransport

func DefaultTransport() *http.Transport

DefaultTransport returns UniRTM's standard http.Transport.

It customizes two behaviors that Go's default transport cannot provide:

  1. Smart Proxy Bypass: domestic mirror domains (aliyun.com, npmmirror.com, etc.) are forced to use DIRECT connections, preventing local proxy software from returning "Bad Request" errors when routing Chinese CDN traffic.

  2. UNIRTM_/MISE_ env prefix support: reads HTTP_PROXY/HTTPS_PROXY/ALL_PROXY through env.Get(), which resolves UNIRTM_HTTP_PROXY and MISE_HTTP_PROXY in addition to the standard names that http.ProxyFromEnvironment covers.

All other settings (connection pool, timeouts) are inherited from Go's http.DefaultTransport via Clone(), so they stay in sync with upstream defaults.

func DisableHTTP2

func DisableHTTP2(trans *http.Transport)

DisableHTTP2 safely disables HTTP/2 on the given transport. This prevents ALPN framing errors when proxies intercept traffic.

func NewClient

func NewClient() *http.Client

NewClient returns an http.Client pre-configured with UniRTM's robust transport.

func NewClientWithTimeout

func NewClientWithTimeout(timeout time.Duration) *http.Client

NewClientWithTimeout returns an http.Client with a timeout and the robust transport.

func ShouldBypassProxy

func ShouldBypassProxy(host string) bool

ShouldBypassProxy returns true if the given host should bypass the proxy.

Types

This section is empty.

Jump to

Keyboard shortcuts

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