khttpclient

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpClient

type HttpClient struct {
	*http.Client
	// contains filtered or unexported fields
}

HttpClient used to mock http.Client methods in order to store or retrieve outputs from request's context.

func NewHttpClient

func NewHttpClient(client *http.Client) *HttpClient

NewHttpClient is used to embed the http.Client pointer in order to mock its methods. The purpose is to capture or replay its method's outputs according to "KEPLOY_SDK_MODE". It returns nil if client parameter is nil.

Note: Always call SetCtxHttpClient method of *integrations.HttpClient before using http-client's method. This should be done so that
      request's context can be modified for storing or retrieving outputs of http methods.

func (*HttpClient) Do

func (cl *HttpClient) Do(req *http.Request) (*http.Response, error)

Do is used to override http.Client's Do method. More about this net/http method: https://pkg.go.dev/net/http#Client.Do.

func (*HttpClient) Get

func (cl *HttpClient) Get(url string) (*http.Response, error)

Get mocks the http.Client.Get method of net/http package. More about this net/http method: https://pkg.go.dev/net/http#Client.Get.

func (*HttpClient) Head

func (cl *HttpClient) Head(url string) (*http.Response, error)

Head mocks http.Client.Head method. More about this net/http method: https://pkg.go.dev/net/http#Client.Head.

func (*HttpClient) Post

func (cl *HttpClient) Post(url, contentType string, body io.Reader) (*http.Response, error)

Post mocks the http.Client.Post method. More about this net/http method: https://pkg.go.dev/net/http#Client.Post.

func (*HttpClient) PostForm

func (cl *HttpClient) PostForm(url string, data url.Values) (*http.Response, error)

PostForm Method mocks net/http Client's method. About mocked method: https://pkg.go.dev/net/http#Client.PostForm.

func (*HttpClient) SetCtxHttpClient

func (cl *HttpClient) SetCtxHttpClient(ctx context.Context)

SetCtxHttpClient is used to set integrations.HttpClient.ctx to http.Request.Context(). It should be called before calling any http.Client method so that, their outputs can be stored or retrieved from http.Request.Context() according to "KEPLOY_SDK_MODE".

ctx parameter should be the context of http.Request.

type ReadCloser

type ReadCloser struct {
	*bytes.Reader
	Body io.ReadCloser
}

ReadCloser is used so that gob could encode-decode http.Response.

func (ReadCloser) Close

func (rc ReadCloser) Close() error

func (*ReadCloser) MarshalBinary

func (rc *ReadCloser) MarshalBinary() ([]byte, error)

func (*ReadCloser) UnmarshalBinary

func (rc *ReadCloser) UnmarshalBinary(b []byte) error

Jump to

Keyboard shortcuts

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