http

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosedConnection = errors.New("send request on closed connection")
	ErrRequestTimeout   = errors.New("sync call timeout")
)

Functions

func NewHTTP2Server added in v0.26.0

func NewHTTP2Server(config interface{}) types.MockServer

func NewHTTPServer added in v0.16.0

func NewHTTPServer(config interface{}) types.MockServer

func NewHttp2Client added in v0.26.0

func NewHttp2Client(config interface{}) types.MockClient

func NewHttpClient added in v0.16.0

func NewHttpClient(config interface{}) types.MockClient

Types

type Condition added in v0.16.0

type Condition struct {
	// If a request contains the expected header, matched this condition.
	// A request must have the configured header key and value, and can have others headers
	// which will be ingored.
	ExpectedHeader map[string][]string `json:"expected_header"`
	// If a request contains the unexpected header, matched failed.
	UnexpectedHeaderKey []string `json"unexpected_headerkey"`
	// If a request's method is in the expected method, matched this condition.
	ExpectedMethod []string `json:"expected_method"`
}

func (*Condition) Match added in v0.16.0

func (c *Condition) Match(r *http.Request) bool

type HttpClientConfig added in v0.16.0

type HttpClientConfig struct {
	TargetAddr   string         `json:"target_address"`
	ProtocolName string         `json:"protocol_name"`
	MaxConn      uint32         `json:"max_connection"`
	Request      *RequestConfig `json:"request_config"`
	Verify       *VerifyConfig  `json:"verify_config"`
}

func NewHttpClientConfig added in v0.16.0

func NewHttpClientConfig(config interface{}) (*HttpClientConfig, error)

type HttpConn added in v0.16.0

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

func NewConn added in v0.16.0

func NewConn(addr string, pname api.ProtocolName, cb func()) (*HttpConn, error)

func (*HttpConn) AsyncSendRequest added in v0.16.0

func (c *HttpConn) AsyncSendRequest(receiver mtypes.StreamReceiveListener, req *RequestConfig)

func (*HttpConn) Close added in v0.16.0

func (c *HttpConn) Close()

func (*HttpConn) IsClosed added in v0.16.0

func (c *HttpConn) IsClosed() bool

func (*HttpConn) OnEvent added in v0.16.0

func (c *HttpConn) OnEvent(event api.ConnectionEvent)

func (*HttpConn) SyncSendRequest added in v0.16.0

func (c *HttpConn) SyncSendRequest(req *RequestConfig, proto api.ProtocolName) (*Response, error)

type HttpServerConfig added in v0.16.0

type HttpServerConfig struct {
	Addr    string                    `json:"address"`
	Configs map[string]*ResonseConfig `json:"response_configs"`
}

func NewHttpServerConfig added in v0.16.0

func NewHttpServerConfig(config interface{}) (*HttpServerConfig, error)

type MockHttp2Server added in v0.26.0

type MockHttp2Server struct {
	*MockHttpServer
}

func (*MockHttp2Server) ServeHTTP added in v0.26.0

func (s *MockHttp2Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MockHttp2Server) Start added in v0.26.0

func (s *MockHttp2Server) Start()

type MockHttpClient added in v0.16.0

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

MockHttpClient use mosn http protocol and stream control metrics and connection

func (*MockHttpClient) AsyncCall added in v0.16.0

func (c *MockHttpClient) AsyncCall()

TODO: implement it

func (*MockHttpClient) Close added in v0.16.0

func (c *MockHttpClient) Close()

Close will close all the connections

func (*MockHttpClient) Stats added in v0.16.0

func (*MockHttpClient) SyncCall added in v0.16.0

func (c *MockHttpClient) SyncCall() bool

type MockHttpServer added in v0.16.0

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

func (*MockHttpServer) ServeHTTP added in v0.16.0

func (s *MockHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

Wrap a http server so we can get the metrics info

func (*MockHttpServer) Start added in v0.16.0

func (s *MockHttpServer) Start()

func (*MockHttpServer) Stats added in v0.16.0

func (*MockHttpServer) Stop added in v0.16.0

func (s *MockHttpServer) Stop()

type RequestConfig added in v0.16.0

type RequestConfig struct {
	Method  string              `json:"method"`
	Path    string              `json:"path"`
	Header  map[string][]string `json:"header"`
	Body    json.RawMessage     `json:"body"`
	Timeout time.Duration       `json:"timeout"` // request timeout
}

RequestConfig decides what request to send

func (*RequestConfig) BuildRequest added in v0.16.0

func (c *RequestConfig) BuildRequest(ctx context.Context) (api.HeaderMap, buffer.IoBuffer)

type ResonseConfig added in v0.16.0

type ResonseConfig struct {
	Condition     *Condition       `json:"condition"`
	CommonBuilder *ResponseBuilder `json:"common_builder"`
	ErrorBuilder  *ResponseBuilder `json:"error_buidler"`
}

ResponseConfig decides what response to send. If a request matches the Condition, send a common repsonse. If not, send an error response

func (*ResonseConfig) ServeHTTP added in v0.16.0

func (cfg *ResonseConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Response

type Response struct {
	StatusCode int
	Header     map[string][]string
	Body       []byte
	Cost       time.Duration
}

type ResponseBuilder

type ResponseBuilder struct {
	// The response status code
	StatusCode int `json:"status_code"`
	// The response header
	Header map[string][]string `json:"header"`
	// The repsonse body content
	Body string `json:"body"`
}

func (*ResponseBuilder) Build

func (b *ResponseBuilder) Build(w http.ResponseWriter) (int, error)

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriterWrapper wraps a response so we can set the metrics

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(code int)

type StatsConn

type StatsConn struct {
	net.Conn
	CloseEvent func()
}

StatsConn wraps a connection so we can set the metrics

func (*StatsConn) Close

func (conn *StatsConn) Close() error

type StatsListener

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

StatsListener wraps a listener so we can set the metrics

func NewStatsListener

func NewStatsListener(ln net.Listener, stats *types.ServerStats) *StatsListener

func (*StatsListener) Accept

func (sl *StatsListener) Accept() (net.Conn, error)

func (*StatsListener) Addr

func (sl *StatsListener) Addr() net.Addr

func (*StatsListener) Close

func (sl *StatsListener) Close() error

type VerifyConfig

type VerifyConfig struct {
	ExpectedStatusCode int
	// if ExepctedHeader is nil, means do not care about header
	// if ExepctedHeader is exists, means resposne header should contain all the ExpectedHeader
	// If response header contain keys not in ExpectedHeader, we ignore it.
	// TODO: support regex
	ExpectedHeader map[string][]string
	// if ExpectedBody is nil, means do not care about body
	// TODO: support regex
	ExpectedBody []byte
	// if MaxExpectedRT is zero, means do not care about rt
	// if MaxExpectedRT is not zero, means response's rt should no more than it
	MaxExpectedRT time.Duration
	// if MinExpectedRT is zero means do not care about it
	// if MinExpectedRT is not zero, means response's rt should more than it
	MinExpectedRT time.Duration
}

VerifyConfig describes what response want

func (*VerifyConfig) Verify

func (c *VerifyConfig) Verify(resp *Response) bool

Jump to

Keyboard shortcuts

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