https

package
v1.16.5 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

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

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

func IsErrorCode added in v1.15.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.3.0

func IsSuccessCode(code int) bool

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

func MapBody

func MapBody(body map[string]interface{}) 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, autoRedirect bool) (string, *http.Response, error)

Request 发起 http 请求获取响应

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

Types

type CacheClient added in v1.8.0

type CacheClient struct {
	// contains filtered or unexported fields
}

CacheClient 具有缓存功能的 http 请求客户端

func NewCacheClient added in v1.8.0

func NewCacheClient(maxCacheNum int, expiredTime time.Duration) *CacheClient

NewCacheClient 初始化一个具备缓存特性的 http 客户端

一个请求缓存的过期时间可能存在误差

func (*CacheClient) GetAllCacheUrls added in v1.16.0

func (cc *CacheClient) GetAllCacheUrls() []string

GetAllCacheUrls 获取当前缓存列表中所有的地址

func (*CacheClient) RemoveUrlCache added in v1.16.0

func (cc *CacheClient) RemoveUrlCache(url string)

RemoveUrlCache 移除指定 url 的缓存 如果缓存中不存在该 url 则不进行任何操作

func (*CacheClient) Request added in v1.8.0

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

Request 发起 http 请求获取响应

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳