http

package
v0.0.0-...-cb950d2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBuilder = &ResponseBuilder{
	StatusCode: http.StatusOK,
	Header: map[string]string{
		"mosn-test-default": "http1",
	},
	Body: []byte("default-http1"),
}
View Source
var DefaultErrorBuilder = &ResponseBuilder{
	StatusCode: http.StatusInternalServerError,
	Header: map[string]string{
		"error-mesage": "no matched config",
	},
}
View Source
var DefaultHTTPServe = &HTTPServe{
	Configs: map[string]*HTTPResonseConfig{
		"/": &HTTPResonseConfig{
			Builder:      DefaultBuilder,
			ErrorBuidler: DefaultErrorBuilder,
		},
	},
}
View Source
var DefaultVeirfy = &VerifyConfig{
	ExpectedStatus: http.StatusOK,
}

Functions

func BuildHTTP1Request

func BuildHTTP1Request(method string, header map[string]string, body []byte) (types.HeaderMap, types.IoBuffer)

Types

type Client

type Client struct {
	Cfg *ClientConfig
	// Stats
	Stats *ClientStats
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *ClientConfig, maxConnections uint32) *Client

func (*Client) Close

func (c *Client) Close()

Close All the connections

func (*Client) SyncCall

func (c *Client) SyncCall() bool

type ClientConfig

type ClientConfig struct {
	Addr          string
	MakeRequest   MakeRequestFunc
	RequestMethod string
	RequestHeader map[string]string
	RequestBody   []byte
	// request timeout is used for sync call
	// if zero, we set default request time, 5 second
	RequestTImeout time.Duration
	// if Verify is nil, just expected returns success
	Verify ResponseVerify
}

func CreateSimpleConfig

func CreateSimpleConfig(addr string) *ClientConfig

type ClientStats

type ClientStats struct {
	*ServerStats
	// contains filtered or unexported fields
}

func NewClientStats

func NewClientStats() *ClientStats

func (*ClientStats) ExpectedResponse

func (c *ClientStats) ExpectedResponse() (uint32, uint32)

func (*ClientStats) Response

func (c *ClientStats) Response(expected bool)

type ConnClient

type ConnClient struct {
	MakeRequest MakeRequestFunc
	SyncTimeout time.Duration
	// contains filtered or unexported fields
}

func NewConnClient

func NewConnClient(addr string, f MakeRequestFunc) (*ConnClient, error)

func (*ConnClient) Close

func (c *ConnClient) Close()

func (*ConnClient) IsClosed

func (c *ConnClient) IsClosed() bool

func (*ConnClient) OnEvent

func (c *ConnClient) OnEvent(event types.ConnectionEvent)

func (*ConnClient) SyncSend

func (c *ConnClient) SyncSend(method string, header map[string]string, body []byte) (*Response, error)

type ConnStats

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

func (*ConnStats) ActiveConnection

func (s *ConnStats) ActiveConnection()

func (*ConnStats) CloseConnection

func (s *ConnStats) CloseConnection()

func (*ConnStats) ConnectionStats

func (s *ConnStats) ConnectionStats() (uint32, uint32, uint32)

type HTTPResonseConfig

type HTTPResonseConfig struct {
	ExpectedHeader      http.Header // map[string][]string
	UnexpectedHeaderKey []string
	ExpectedMethod      string
	//
	Builder      *ResponseBuilder
	ErrorBuidler *ResponseBuilder
}

TODO: support more

func (*HTTPResonseConfig) Match

func (cfg *HTTPResonseConfig) Match(r *http.Request) bool

func (*HTTPResonseConfig) ServeHTTP

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

type HTTPServe

type HTTPServe struct {
	Configs map[string]*HTTPResonseConfig
}

func (*HTTPServe) Serve

func (s *HTTPServe) Serve(srv *MockServer)

type MakeRequestFunc

type MakeRequestFunc func(method string, header map[string]string, body []byte) (types.HeaderMap, types.IoBuffer)

type MockServer

type MockServer struct {
	*http.Server
	*ServerStats
	Addr string
	Mux  map[string]func(http.ResponseWriter, *http.Request)
	// contains filtered or unexported fields
}

func NewMockServer

func NewMockServer(addr string, f ServeFunc) *MockServer

func (*MockServer) HandleFunc

func (srv *MockServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*MockServer) ServeHTTP

func (srv *MockServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

A wrapper of ServerHTTP

func (*MockServer) Start

func (srv *MockServer) Start()

type Response

type Response struct {
	Header mosnhttp.ResponseHeader
	Data   []byte
	Cost   time.Duration
}

Client

type ResponseBuilder

type ResponseBuilder struct {
	StatusCode int
	Header     map[string]string
	Body       []byte
}

func (*ResponseBuilder) Build

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

type ResponseVerify

type ResponseVerify func(*Response) bool

type ResponseWriterWrapper

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

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(code int)

type ServeFunc

type ServeFunc func(srv *MockServer)

type ServerStats

type ServerStats struct {
	*ConnStats
	// contains filtered or unexported fields
}

func NewServerStats

func NewServerStats(cs *ConnStats) *ServerStats

func (*ServerStats) Request

func (s *ServerStats) Request()

func (*ServerStats) RequestStats

func (s *ServerStats) RequestStats() uint32

func (*ServerStats) Response

func (s *ServerStats) Response(status int16)

func (*ServerStats) ResponseStats

func (s *ServerStats) ResponseStats() map[int16]uint32

type StatsConn

type StatsConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*StatsConn) Close

func (conn *StatsConn) Close() error

type StatsListener

type StatsListener struct {

	// stats
	*ConnStats
	// contains filtered or unexported fields
}

StatsListener implements a net.Listener for http.Server

func NewStatsListener

func NewStatsListener(ln net.Listener) *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 {
	ExpectedStatus int
	// if ExepctedHeader is nil, means do not care about header
	// if ExepctedHeader is exists, means resposne Header should contain all the ExpectedHeader
	// TODO :  support regex
	ExpectedHeader map[string]string
	// if ExpectedBody is nil, means do not care about body
	// TODO: support regex
	ExpectedBody []byte
	// if ExpectedRT is zero, means do not care about rt
	// if ExpectedRT is not zero, means response's rt should no more than it
	ExpectedRT time.Duration
	// if MinRT is zero means do not care about it
	// if MinRT is not zero, means response's rt should more than it
	MinRT time.Duration
}

func (*VerifyConfig) Verify

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

Jump to

Keyboard shortcuts

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