httputils

package
v0.0.0-...-38714f9 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2016 The GoStor Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package httputils contains a bunch of HTTP utility code, some generic

Index

Constants

View Source
const APIVersionKey = "api-version"

APIVersionKey is the client's requested API version.

Variables

This section is empty.

Functions

func BoolValue

func BoolValue(r *http.Request, k string) bool

BoolValue transforms a form value in different formats into a boolean type.

func BoolValueOrDefault

func BoolValueOrDefault(r *http.Request, k string, d bool) bool

BoolValueOrDefault returns the default bool passed if the query param is missing, otherwise it's just a proxy to boolValue above

func CheckForJSON

func CheckForJSON(r *http.Request) error

CheckForJSON makes sure that the request's Content-Type is application/json.

func CloseStreams

func CloseStreams(streams ...interface{})

CloseStreams ensures that a list for http streams are properly closed.

func HijackConnection

func HijackConnection(w http.ResponseWriter) (io.ReadCloser, io.Writer, error)

HijackConnection interrupts the http response writer to get the underlying connection and operate with it.

func Int64ValueOrDefault

func Int64ValueOrDefault(r *http.Request, field string, def int64) (int64, error)

Int64ValueOrDefault parses a form value into an int64 type. If there is an error, returns the error. If there is no value returns the default value.

func Int64ValueOrZero

func Int64ValueOrZero(r *http.Request, k string) int64

Int64ValueOrZero parses a form value into an int64 type. It returns 0 if the parsing fails.

func MatchesContentType

func MatchesContentType(contentType, expectedType string) bool

MatchesContentType validates the content type against the expected one

func ParseForm

func ParseForm(r *http.Request) error

ParseForm ensures the request form is parsed even with invalid content types. If we don't do this, POST method without Content-type (even with empty body) will fail.

func ParseMultipartForm

func ParseMultipartForm(r *http.Request) error

ParseMultipartForm ensure the request form is parsed, even with invalid content types.

func VersionFromContext

func VersionFromContext(ctx context.Context) string

VersionFromContext returns an API version from the context using APIVersionKey. It panics if the context value does not have version.Version type.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError decodes a specific docker error and sends it in the response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, code int, v interface{}) error

WriteJSON writes the value v to the http response stream as json with standard json encoding.

Types

type APIFunc

type APIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error

APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints. Any function that has the appropriate signature can be register as a API endpoint (e.g. getVersion).

type ArchiveOptions

type ArchiveOptions struct {
	Name string
	Path string
}

ArchiveOptions stores archive information for different operations.

func ArchiveFormValues

func ArchiveFormValues(r *http.Request, vars map[string]string) (ArchiveOptions, error)

ArchiveFormValues parses form values and turns them into ArchiveOptions. It fails if the archive name and path are not in the request.

Jump to

Keyboard shortcuts

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