http

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeaders added in v1.9.0

func AddHeaders(dest http.Header, source http.Header)

AddHeaders - copy all the headers

func CleanURI

func CleanURI(name string) string

CleanURI - cleans and validates the URI

Types

type Configuration added in v1.9.0

type Configuration struct {
	Host        string
	Port        int
	ChannelSize int
	Responses   map[string][]Endpoint
	T           *testing.T
}

Configuration - configuration

type Endpoint added in v1.9.0

type Endpoint struct {
	// URI - the endpoint's uri
	URI string
	// Methods - the list of http methods (GET, POST, ...) containing the respective response
	Methods map[string]Response
	// Regexp - activates regular expression for uris
	Regexp bool
}

Endpoint - an endpoint to be listened

type Request added in v1.9.0

type Request struct {
	URI     string
	Body    []byte
	Method  string
	Headers http.Header
}

Request - the request data made to the server

func WaitForServerRequest

func WaitForServerRequest(server *Server, waitFor, maxRequestTimeout time.Duration) *Request

WaitForServerRequest - wait until timeout or for the server sets the request in the channel

type Response added in v1.9.0

type Response struct {
	// Body - the body to be put in the response
	Body interface{}
	// Headers - the headers to be included in the response
	Headers http.Header
	// Status - the code status to be returned
	Status int
	// Wait - a time to wait until responds
	Wait time.Duration
}

Response - the endpoint response data

type Server

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

Server - the server listening for HTTP requests

func NewServer

func NewServer(configuration *Configuration) *Server

NewServer - creates a new HTTP listener server

func (*Server) Close

func (hs *Server) Close()

Close - closes this server

func (*Server) DoRequest added in v1.9.0

func (hs *Server) DoRequest(request *Request) *http.Response

DoRequest - does a request

func (*Server) RequestChannel

func (hs *Server) RequestChannel() <-chan *Request

RequestChannel - reads from the request channel

func (*Server) SetMode added in v1.9.0

func (hs *Server) SetMode(mode string)

SetMode - sets the server mode

Jump to

Keyboard shortcuts

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