https

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxRedirectDepth 重定向的最大深度
	MaxRedirectDepth = 10
)

Variables

RedirectCodes 有重定向含义的 http 响应码

Functions

func ClientRequestHost

func ClientRequestHost(c *gin.Context) string

ClientRequestHost 获取客户端请求的 Host

func ClientRequestUrl

func ClientRequestUrl(c *gin.Context) string

ClientRequestUrl 获取客户端请求的完整地址

func CloneHeader

func CloneHeader(c *gin.Context, header http.Header)

CloneHeader 克隆 http 头部到 gin 的响应头中

func ExtractReqBody added in v1.0.8

func ExtractReqBody(c *gin.Context) ([]byte, error)

ExtractReqBody 克隆并提取请求体 不影响 c 对象之后再次读取请求体

func IsErrorCode added in v1.5.1

func IsErrorCode(code int) bool

IsErrorCode 判断 http code 是否为错误状态

func IsErrorResponse

func IsErrorResponse(c *gin.Context) bool

IsErrorResponse 判断一个请求响应是否是错误响应

判断标准是响应码以 4xx 5xx 开头

func IsRedirectCode

func IsRedirectCode(code int) bool

IsRedirectCode 判断 http code 是否是重定向

301, 302, 307, 308

func IsSuccessCode added in v1.5.1

func IsSuccessCode(code int) bool

IsSuccessCode 判断 http code 是否为成功状态

func MapBody

func MapBody(body map[string]any) io.ReadCloser

MapBody 将 map 转换为 ReadCloser 流

func ProxyRequest

func ProxyRequest(c *gin.Context, remote string, withUri bool) error

ProxyRequest 代理请求

func Request

func Request(method, url string, header http.Header, body io.ReadCloser) (*http.Response, error)

Request 发起 http 请求获取响应

func RequestRedirect added in v1.3.0

func RequestRedirect(method, url string, header http.Header, body io.ReadCloser, autoRedirect bool) (string, *http.Response, error)

RequestRedirect 发起 http 请求获取响应

如果一个请求有多次重定向并且进行了 autoRedirect, 则最后一次重定向的 url 会作为第一个参数返回

Types

This section is empty.

Jump to

Keyboard shortcuts

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