recorder

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package recorder 记录http transaction

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBinaryBody

func IsBinaryBody(contentType string) bool

body是否是二进制内容

Types

type Body

type Body struct {
	IsBinary    bool   `json:"is_binary"`
	Len         int    `json:"len"`
	ContentType string `json:"content_type"`
	Content     []byte `json:"content"`
}

Body HTTP请求、响应Body

func NewBody

func NewBody() *Body

NewBody 创建Body

type CertCache

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

CertCache 证书缓存

func NewCertCache

func NewCertCache(q *common.Queue) *CertCache

创建CertCache

func (*CertCache) Get

func (c *CertCache) Get(host string) *tls.Certificate

Get 获取证书

func (*CertCache) Set

func (c *CertCache) Set(host string, cert *tls.Certificate)

Set 保存证书

type Interceptor

type Interceptor interface {
	// Connect 收到客户端连接, 自定义response返回, 只支持HTTP
	Connect(ctx *goproxy.Context, rw http.ResponseWriter)
	// BeforeRequest 请求发送前, 修改request
	BeforeRequest(ctx *goproxy.Context)
	// BeforeResponse 响应发送前, 修改response
	BeforeResponse(ctx *goproxy.Context, resp *http.Response, err error)
}

Interceptor 拦截器

type Output

type Output interface {
	Write(*Transaction) error
}

Output 输出transaction接口

type Recorder

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

Recorder 记录http transaction

func NewRecorder

func NewRecorder() *Recorder

NewRecorder 创建recorder

func (*Recorder) Auth

func (r *Recorder) Auth(ctx *goproxy.Context, rw http.ResponseWriter)

Auth 代理身份认证

func (*Recorder) BeforeRequest

func (r *Recorder) BeforeRequest(ctx *goproxy.Context)

BeforeRequest 请求发送前处理

func (*Recorder) BeforeResponse

func (r *Recorder) BeforeResponse(ctx *goproxy.Context, resp *http.Response, err error)

BeforeResponse 响应发送前处理

func (*Recorder) Connect

func (r *Recorder) Connect(ctx *goproxy.Context, rw http.ResponseWriter)

Connect 收到客户端连接

func (*Recorder) DoRequest

func (r *Recorder) DoRequest(req *http.Request)

DoRequest 执行请求

func (*Recorder) ErrorLog

func (r *Recorder) ErrorLog(err error)

ErrorLog 记录错误日志

func (*Recorder) Finish

func (r *Recorder) Finish(ctx *goproxy.Context)

Finish 请求结束

func (*Recorder) ParentProxy

func (r *Recorder) ParentProxy(req *http.Request) (*url.URL, error)

ParentProxy 设置上级代理

func (*Recorder) Replay

func (r *Recorder) Replay(txId string) error

Replay 回放

func (*Recorder) SetInterceptor

func (r *Recorder) SetInterceptor(i Interceptor)

SetInterceptor 设置拦截器

func (*Recorder) SetOutput

func (r *Recorder) SetOutput(o Output)

SetOutput 设置transaction输出

func (*Recorder) SetProxy

func (r *Recorder) SetProxy(p *goproxy.Proxy)

SetProxy 设置中间人代理

func (*Recorder) SetStorage

func (r *Recorder) SetStorage(s Storage)

SetStorage 设置transaction存储

func (*Recorder) Storage

func (r *Recorder) Storage() Storage

Storage 获取存储

type Request

type Request struct {
	// Proto HTTP协议版本
	Proto string `json:"proto"`
	// Method 请求方法
	Method string `json:"method"`
	// Scheme 请求协议
	Scheme string `json:"scheme"`
	// Host 请求主机名
	Host string `json:"host"`
	// Path 请求path
	Path string `json:"path"`
	// QueryParam URL参数
	QueryParam string `json:"query_param"`
	// URL 完整URL
	URL string `json:"url"`
	// Header 请求Header
	Header http.Header `json:"header"`
	// Body 请求body
	Body *Body `json:"body"`
}

Request HTTP请求

func NewRequest

func NewRequest() *Request

NewRequest 创建请求

func (*Request) Restore

func (req *Request) Restore() (*http.Request, error)

Restore 还原请求

type Response

type Response struct {
	// Proto 响应协议
	Proto string `json:"proto"`
	// Status 状态状态
	Status string `json:"status"`
	// StatusCode 响应码
	StatusCode int `json:"status_code"`
	// Header 响应Header
	Header http.Header `json:"header"`
	// Body 响应Body
	Body *Body `json:"body"`
	// Err 错误信息
	Err string `json:"err"`
}

Response HTTP响应

func NewResponse

func NewResponse() *Response

type Storage

type Storage interface {
	Get(txId string) (*Transaction, error)
	Put(*Transaction) error
}

Storage 存取transaction接口

type Transaction

type Transaction struct {
	// Id 唯一id
	Id string `json:"id"`
	// Req 请求
	Req *Request `json:"request"`
	// Resp 响应
	Resp *Response `json:"response"`
	// ClientIP 客户端IP
	ClientIP string `json:"client_ip"`
	// ServerIP 服务端IP
	ServerIP string `json:"server_ip"`
	// StartTime 开始时间
	StartTime time.Time `json:"start_time"`
	// Duration 持续时间
	Duration time.Duration `json:"duration"`
}

Transaction HTTP事务

func NewTransaction

func NewTransaction() *Transaction

NewTransaction 创建HTTP事务

func (*Transaction) DumpRequest

func (tx *Transaction) DumpRequest(req *http.Request)

DumpRequest 提取request

func (*Transaction) DumpResponse

func (tx *Transaction) DumpResponse(resp *http.Response, e error)

DumpRequest 提取response

Directories

Path Synopsis
Package storage 存储http transaction
Package storage 存储http transaction

Jump to

Keyboard shortcuts

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