http

package
v0.77.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

README

HTTP Endpoint Service

Service Id Action Description Request Response
http/endpoint listen listen on specified port to replay recorded HTTP conversation ListenRequest ListenResponse

This service enable capturing and replaying HTTP traffic to simulate 3rd party dependency.

Capturing HTTP traffic

Capturing 3rd party http traffic

sudo endly -u='http://targetURL'

open you browser with various URL on localhost matching targetURL port

Capturing 3rd party secure http traffic

Make sure you have server cert and key, or you can generate self self-signed (x509) with the following

openssl genrsa -out server.key 2048
openssl ecparam -genkey -name secp384r1 -out server.key
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650

sudo endly -u='https://some.domain.com'

Starting testing endpoint with captured traffic

@listen.yaml

port: 8080
rotate: true
baseDirectory: /recorded_traffic_location/

Start testing endpoint in standalone mode

endly -m=true  -w=action service='http/endpoint' action=listen request=@listen.yaml 

Embeding endpoint within inline workflow

@inline.yaml

pipeline:
  init:
    start-endpoint:
      action: http/endpoint:listen
      port: 8080
      rotate: true
      baseDirectory: /recorded_traffic_location/

Start your workflow

endly -r=inline -m=true

Documentation

Index

Constants

View Source
const (
	//URLKey represents url key
	URLKey = "URL"
	//CookieKey represents cookie header key
	CookieKey = "Cookie"
	//ContentTypeKey represents content type header key
	ContentTypeKey = "Content-Type"
	//MethodKey represents http method key
	MethodKey = "Method"
	//BodyKey represents http body key
	BodyKey = "Body"

	//DefaultRequestTemplate request template
	DefaultRequestTemplate = "%02d-req.json"
	//DefaultResponseTemplate response tempalte
	DefaultResponseTemplate = "%02d-resp.json"
)
View Source
const (
	//ServiceID represents hTTPEndpoint service id.
	ServiceID = "http/endpoint"
)

Variables

View Source
var HTTPRequestKeyProviders = make(map[string]HTTPRequestKeyProvider)

HTTPRequestKeyProviders represents key providers

Functions

func New

func New() endly.Service

New creates

a new HTTP endpoint service, to replay previously recorded HTTP trips.

func StartRecorder

func StartRecorder(targetURLs ...string) error

StartRecorder starts HTTP recorded for supplied URLs

Types

type AppendRequest

type AppendRequest struct {
	Port          int
	BaseDirectory string `` /* 164-byte string literal not displayed */
}

func (AppendRequest) AsHTTPServerTrips

func (r AppendRequest) AsHTTPServerTrips(rotate bool, indexKeys []string) *HTTPServerTrips

AsHTTPServerTrips return a new HTTP trips.

func (AppendRequest) Validate

func (r AppendRequest) Validate() error

Validate checks if request is valid.

type AppendResponse

type AppendResponse struct {
	Trips map[string]*HTTPResponses
}

ListenResponse represents HTTP endpoint listen response with indexed trips

type HTTPRequestKeyProvider

type HTTPRequestKeyProvider func(source interface{}) (string, error)

HTTPRequestKeyProvider represents request key provider to extract a request field.

func HeaderProvider

func HeaderProvider(header string) HTTPRequestKeyProvider

HeaderProvider return a header value for supplied source

type HTTPResponses

type HTTPResponses struct {
	Request   *bridge.HttpRequest
	Responses []*bridge.HttpResponse
	Index     uint32
}

HTTPResponses represents HTTPResponses

type HTTPServerTrips

type HTTPServerTrips struct {
	BaseDirectory string
	Rotate        bool
	Trips         map[string]*HTTPResponses
	IndexKeys     []string
	Mutex         *sync.Mutex
}

HTTPServerTrips represents http trips

func (*HTTPServerTrips) Init

func (t *HTTPServerTrips) Init(requestTemplate string, respTemplate string) error

Init initialises trips

type ListenRequest

type ListenRequest struct {
	Port             int
	Rotate           bool
	RequestTemplate  string   `description:"request file loading template, default: %02d-req.json"`
	ResponseTemplate string   `description:"response file loading template, default: %02d-resp.json"`
	BaseDirectory    string   `` /* 164-byte string literal not displayed */
	IndexKeys        []string `description:"recorded requests matching keys, by default: Method,URL,Body,Cookie,Content-Type"`
}

ListenRequest represent HTTP endpoint listen request

func (ListenRequest) AsHTTPServerTrips

func (r ListenRequest) AsHTTPServerTrips() *HTTPServerTrips

AsHTTPServerTrips return a new HTTP trips.

func (*ListenRequest) Init

func (r *ListenRequest) Init() error

func (ListenRequest) Validate

func (r ListenRequest) Validate() error

Validate checks if request is valid.

type ListenResponse

type ListenResponse struct {
	Trips map[string]*HTTPResponses
}

ListenResponse represents HTTP endpoint listen response with indexed trips

type Server

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

func StartServer

func StartServer(port int, trips *HTTPServerTrips, reqTemplate, respTemplate string) (*Server, error)

StartServer starts http request, the server has ability to replay recorded HTTP trips with https://github.com/viant/toolbox/blob/master/bridge/http_bridge_recording_util.go#L82

func (*Server) Append

func (s *Server) Append(trips *HTTPServerTrips)

func (Server) ServeHTTP

func (h Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type ShutdownRequest

type ShutdownRequest struct {
	Port int
}

ShutdownRequest represent http endpoint shutdown request

Jump to

Keyboard shortcuts

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