netutils

package
Version: v0.0.0-...-68da624 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2014 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Network related utilities

Index

Constants

View Source
const (
	DefaultMemBufferBytes = 1048576
	DefaultMaxSizeBytes   = -1
	// Equivalent of bytes.MinRead used in ioutil.ReadAll
	DefaultBufferBytes = 512
)

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 RawPath

func RawPath(in string) (string, error)

RawPath returns escaped url path section

func RawURL

func RawURL(request *http.Request) string

RawURL returns URL built out of the provided request's Request-URI, to avoid un-escaping. Note: it assumes that scheme and host for the provided request's URL are defined.

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
	io.WriterTo

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

MultiReader provides Read, Close, Seek and TotalSize methods. In addition to that it supports WriterTo interface to provide efficient writing schemes, as functions like io.Copy use WriterTo when it's available.

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL