netutils

package
v0.0.0-...-a5469ec Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2015 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Overview

Network related utilities

Index

Constants

View Source
const (
	DefaultMemBufferBytes = 1048576
	DefaultMaxSizeBytes   = -1
)

Variables

This section is empty.

Functions

func CopyHeaders

func CopyHeaders(dst, src http.Header)

Copies http headers from source to destination does not overide, but adds multiple headers

func CopyUrl

func CopyUrl(in *url.URL) *url.URL

Provides update safe copy by avoiding shallow copying certain fields (like user data)

func HasHeaders

func HasHeaders(names []string, headers http.Header) bool

Determines whether any of the header names is present in the http headers

func MustParseUrl

func MustParseUrl(inUrl string) *url.URL

func NewHttpResponse

func NewHttpResponse(request *http.Request, statusCode int, body []byte, contentType string) *http.Response

func NewJsonResponse

func NewJsonResponse(request *http.Request, statusCode int, message interface{}) *http.Response

func NewMultiReaderSeeker

func NewMultiReaderSeeker(length int64, cleanup CleanupFunc, readers ...io.ReadSeeker) *multiReaderSeek

func NewTextResponse

func NewTextResponse(request *http.Request, statusCode int, body string) *http.Response

func ParseUrl

func ParseUrl(inUrl string) (*url.URL, error)

Standard parse url is very generous, parseUrl wrapper makes it more strict and demands scheme and host to be set

func RemoveHeaders

func RemoveHeaders(names []string, headers http.Header)

Removes the header with the given names from the headers map

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

func ParseAuthHeader

func ParseAuthHeader(header string) (*BasicAuth, error)

func (*BasicAuth) String

func (ba *BasicAuth) String() string

type BodyBufferOptions

type BodyBufferOptions struct {
	// MemBufferBytes sets up the size of the memory buffer for this request.
	// If the data size exceeds the limit, the remaining request part will be saved on the file system.
	MemBufferBytes int64
	// Max size bytes, ignored if set to value <= 0, if request exceeds the specified limit, the reader will fail.
	MaxSizeBytes int64
}

type CleanupFunc

type CleanupFunc func() error

type MaxReader

type MaxReader struct {
	R   io.Reader // underlying reader
	N   int64     // bytes read
	Max int64     // max bytes to read
}

MaxReader does not allow to read more than Max bytes and returns error if this limit has been exceeded.

func (*MaxReader) Read

func (r *MaxReader) Read(p []byte) (int, error)

type MaxSizeReachedError

type MaxSizeReachedError struct {
	MaxSize int64
}

func (*MaxSizeReachedError) Error

func (e *MaxSizeReachedError) Error() string

type MultiReader

type MultiReader interface {
	io.Reader
	io.Seeker
	io.Closer

	// TotalSize calculates and returns the total size of the reader and not the length remaining.
	TotalSize() (int64, error)
}

MultiReader provides Read, Close and Seek and TotalSize methods.

func NewBodyBuffer

func NewBodyBuffer(input io.Reader) (MultiReader, error)

func NewBodyBufferWithOptions

func NewBodyBufferWithOptions(input io.Reader, o BodyBufferOptions) (MultiReader, error)

Jump to

Keyboard shortcuts

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