zhttp

package
v0.0.0-...-e4c57ef Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: BSD-3-Clause Imports: 26 Imported by: 3

Documentation

Index

Constants

View Source
const DefaultTimeoutSeconds = 15

Variables

View Source
var NoVerifyClient = &http.Client{
	Timeout: 15 * time.Second,
	Transport: &http.Transport{

		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	},
}
View Source
var (
	SetTelemetryForRedirectFunc func(surl string, secs float64)
)

Functions

func AddPathToURL

func AddPathToURL(surl, add string) string

func ArgsFromURL

func ArgsFromURL(u *url.URL) map[string]string

ArgsFromURL gets Query arguments from a url. It can only store k/v of first unqiue key

func CheckErrorFromBody

func CheckErrorFromBody(resp *http.Response) (err error)

func Get

func Get(surl string, params Parameters, receive any) (resp *http.Response, err error)

func GetAndReturnUrlEncodedBodyValues

func GetAndReturnUrlEncodedBodyValues(surl string) (values url.Values, err error)

func GetCopyOfRequestBodyAsString

func GetCopyOfRequestBodyAsString(req *http.Request) string

func GetCopyOfResponseBodyAsString

func GetCopyOfResponseBodyAsString(resp *http.Response) string

func GetHeaders

func GetHeaders(surl string) (header http.Header, err error)

func GetIPAddressAndPortFromRequest

func GetIPAddressAndPortFromRequest(req *http.Request) (ip, port string, err error)

func GetRedirectedURL

func GetRedirectedURL(surl string) (string, error)

func GetResponse

func GetResponse(surl string, params Parameters) (resp *http.Response, err error)

func GetResponseFromReqClient

func GetResponseFromReqClient(params Parameters, request *http.Request, client *http.Client) (resp *http.Response, err error)

func HasURLScheme

func HasURLScheme(str string) bool

func HostIsLocal

func HostIsLocal(host string) bool

func MakeDataURL

func MakeDataURL(data []byte, mime string) string

func MakeHTTPError

func MakeHTTPError(err error, code int, message string) error

func MakeRequest

func MakeRequest(surl string, params Parameters) (request *http.Request, client *http.Client, err error)

func MakeURLWithArgs

func MakeURLWithArgs(surl string, args map[string]string) (string, error)

func Post

func Post(surl string, params Parameters, send, receive any) (resp *http.Response, err error)

Post calls SendBody with method == Post

func Put

func Put(surl string, params Parameters, send, receive any) (resp *http.Response, err error)

Put calls SendBody with method == Put

func ReplaceURLsInText

func ReplaceURLsInText(text string, f func(surl string) string) string

func SendBody

func SendBody(surl string, params Parameters, send, receive any) (*http.Response, error)

SendBody uses send as []byte, map[string]string (to url parameters, or unmarshals to use as body) receive can be []byte, string or a struct to unmarashal to

func SendBytesSetContentLength

func SendBytesSetContentLength(surl string, params Parameters) (resp *http.Response, code int, err error)

func StringStartsWithHTTPX

func StringStartsWithHTTPX(str string) bool

func TruncateLongParametersInURL

func TruncateLongParametersInURL(surl string, onlyIfTotalCharsMoreThan, maxCharsInParameter int) string

func ValsFromURL

func ValsFromURL(surl string) url.Values

Types

type ErrJSON

type ErrJSON struct {
	Messages []string `json:"messages"`
}

type ErrorStruct

type ErrorStruct struct {
	Type       string          `json:"type"`
	ObjectType string          `json:"objectType"`
	Code       json.RawMessage `json:"code"`
	Message    string          `json:"message"`
}

func (ErrorStruct) Check

func (e ErrorStruct) Check(err *error) bool

type GetInfo

type GetInfo struct {
	ConnectSecs        time.Duration
	DnsSecs            time.Duration
	TlsHandshakeSecs   time.Duration
	FirstByteSecs      time.Duration
	DoneSecs           time.Duration
	ByteCount          int64
	RemoteAddress      string
	RemotePort         int
	RemoteDomain       string
	ContentLengthBytes int64
}

func TimedGet

func TimedGet(surl string, downloadBytes int64) (info GetInfo, err error)

type HTTPError

type HTTPError struct {
	Err        error
	StatusCode int
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

type Parameters

type Parameters struct {
	Headers               map[string]string
	SkipVerifyCertificate bool
	PrintBody             bool
	Args                  map[string]string
	TimeoutSecs           float64
	UseHTTPS              bool
	Method                string
	ContentType           string
	Body                  []byte
	Reader                io.Reader
	GetErrorFromBody      bool
	Context               context.Context
}

func MakeParameters

func MakeParameters() Parameters

type SSENotificationCenter

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

func SetupSSE

func SetupSSE(pathWithPort string) *SSENotificationCenter

func (*SSENotificationCenter) NotifyWithJson

func (nc *SSENotificationCenter) NotifyWithJson(v interface{}) error

Jump to

Keyboard shortcuts

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