httpx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package httpx provides some types and function helping when working with the HTTP package.

Index

Constants

View Source
const (
	HeaderAccept      = "Accept"
	HeaderContentType = "Content-Type"

	ContentTypePlain      = "text/plain"
	ContentTypeHTML       = "text/html"
	ContentTypeXML        = "application/xml"
	ContentTypeJSON       = "application/json"
	ContentTypeURLEncoded = "application/x-www-form-urlencoded"
)

Headers fields and values.

Variables

This section is empty.

Functions

func AcceptsContentType

func AcceptsContentType(h http.Header, contentType string) bool

AcceptsContentType checks a request header accepts a given content type.

func ContainsContentType

func ContainsContentType(h http.Header, contentType string) bool

ContainsContentType checks if the header contains the given content type.

func IsValidMethod

func IsValidMethod(method string) bool

IsValidMethod returns true if the passed method is valid.

func MarshalBody

func MarshalBody(w io.Writer, h http.Header, v interface{}) error

MarshalBody allows to directly marshal a value into a writer depending on the content type.

func PathAt

func PathAt(r *http.Request, n int) (string, bool)

PathAt returns the nth part of the request path and true if it exists. Otherwise an empty string and false.

func PathParts

func PathParts(r *http.Request) []string

PathParts splits the request path into its parts.

func ReadBody

func ReadBody(r io.ReadCloser) ([]byte, error)

ReadBody retrieves the whole body out of a HTTP request or response and returns it as byte slice.

func UnmarshalBody

func UnmarshalBody(r io.ReadCloser, h http.Header, v interface{}) error

UnmarshalBody parses the body data of a request or response based on the content type header stores the result in the value pointed by v. Conten types JSON and XML expect the according types as arguments, all text types expect a string, and all others too, but the data is encoded in BASE64.

func WriteBody

func WriteBody(w io.Writer, data []byte) error

WriteBody writes the whole body into a HTTP request or response.

Types

This section is empty.

Source Files

  • body.go
  • doc.go
  • header.go
  • method.go
  • path.go

Jump to

Keyboard shortcuts

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