requestdecorator

package
v1.4.2-0...-e4855ee Latest Latest
Warning

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

Go to latest
Published: May 14, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

README

This package provides helper functions for decorating a request with user agent versions, auth, meta headers.

Documentation

Overview

Package requestdecorator provides helper functions to decorate a request with user agent versions, auth, meta headers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilRequest = errors.New("request cannot be nil")
)

Functions

This section is empty.

Types

type AuthDecorator

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

func (*AuthDecorator) ChangeRequest

func (self *AuthDecorator) ChangeRequest(req *http.Request) (*http.Request, error)

type Decorator

type Decorator interface {
	// ChangeRequest() changes the request accordingly.
	// The changed request will be returned or err will be non-nil
	// if an error occur.
	ChangeRequest(req *http.Request) (newReq *http.Request, err error)
}

Decorator is used to change an instance of http.Request. It could be used to add more header fields, change body, etc.

func NewAuthDecorator

func NewAuthDecorator(login, password string) Decorator

type MetaHeadersDecorator

type MetaHeadersDecorator struct {
	Headers map[string][]string
}

func (*MetaHeadersDecorator) ChangeRequest

func (h *MetaHeadersDecorator) ChangeRequest(req *http.Request) (*http.Request, error)

type RequestFactory

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

RequestFactory creates an HTTP request and applies a list of decorators on the request.

func NewRequestFactory

func NewRequestFactory(d ...Decorator) *RequestFactory

func (*RequestFactory) AddDecorator

func (f *RequestFactory) AddDecorator(d ...Decorator)

func (*RequestFactory) GetDecorators

func (f *RequestFactory) GetDecorators() []Decorator

func (*RequestFactory) NewRequest

func (h *RequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...Decorator) (*http.Request, error)

NewRequest() creates a new *http.Request, applies all decorators in the Factory on the request, then applies decorators provided by d on the request.

type UAVersionInfo

type UAVersionInfo struct {
	Name    string
	Version string
}

UAVersionInfo is used to model UserAgent versions.

func NewUAVersionInfo

func NewUAVersionInfo(name, version string) UAVersionInfo

type UserAgentDecorator

type UserAgentDecorator struct {
	Versions []UAVersionInfo
}

UserAgentDecorator appends the product/version to the user agent field of a request.

func (*UserAgentDecorator) ChangeRequest

func (h *UserAgentDecorator) ChangeRequest(req *http.Request) (*http.Request, error)

Jump to

Keyboard shortcuts

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