cashttp

package
v0.0.0-...-c9fddc1 Latest Latest
Warning

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

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

Documentation

Overview

Package cashttp implement HTTP cache based on CAS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header http.Header

Header represents an HTTP header or trailer.

func (Header) Get

func (h Header) Get(key string) string

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(p []byte) error

type Request

type Request struct {
	Method  string         `json:"method"`
	URL     URL            `json:"url"`
	Header  Header         `json:"header,omitempty"`
	Body    types.SizedRef `json:"body,omitempty"`
	Trailer Header         `json:"trailer,omitempty"`
}

Request represents an HTTP request.

func (*Request) References

func (r *Request) References() []types.Ref

type Response

type Response struct {
	Status  int            `json:"status"`
	Header  Header         `json:"header,omitempty"`
	Body    types.SizedRef `json:"body,omitempty"`
	Trailer Header         `json:"trailer,omitempty"`
}

Response represents an HTTP response.

func (*Response) References

func (r *Response) References() []types.Ref

type Session

type Session struct {
	Request  types.Ref `json:"request"`
	Response types.Ref `json:"response"`
}

Session binds a response to a specific request.

func (*Session) References

func (r *Session) References() []types.Ref

type Transport

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

func NewTransport

func NewTransport(s *cas.Storage) *Transport

NewTransport creates an HTTP transport based on CAS that will store all the requests and responses and will replay them if request is sent again.

Requests will be matched against the cache based on exact URL match and on match of well-known headers (like Accept). See MatchHeaders for more details.

func (*Transport) MatchHeaders

func (t *Transport) MatchHeaders(list ...string)

MatchHeaders adds additional headers that will be used to match requests versus cache entries.

func (*Transport) RequestFilter

func (t *Transport) RequestFilter(fnc func(*http.Request) bool)

RequestFilter allows to ignore some requests so they are not stored in CAS. Caller should not inspect the body, or should replace it with a new copy.

func (*Transport) ResponseFilter

func (t *Transport) ResponseFilter(fnc func(*http.Response) bool)

ResponseFilter allows to ignore some responses so they are not stored in CAS. Caller should not inspect the body, or should replace it with a new copy.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

func (*Transport) SetTransport

func (t *Transport) SetTransport(tr http.RoundTripper)

SetTransport sets an underlying transport that is used to fill the cache.

type URL

type URL url.URL

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

func (URL) String

func (u URL) String() string

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(p []byte) error

Jump to

Keyboard shortcuts

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