package httputilx

import "github.com/teamwork/utils/httputilx"

Package httputilx provides HTTP utility functions.

Index

Functions

func DumpBody

func DumpBody(r *http.Request, maxSize int64) ([]byte, error)

DumpBody reads the body of a HTTP request without consuming it, so it can be read again later. It will read at most maxSize of bytes. Use -1 to read everything.

It's based on httputil.DumpRequest.

Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file: https://golang.org/LICENSE

func Fetch

func Fetch(url string) ([]byte, error)

Fetch the contents of an HTTP URL.

This is not intended to cover all possible use cases for fetching files, only the most common ones. Use the net/http package for more advanced usage.

func Save

func Save(url string, dir string, filename string) (string, error)

Save an HTTP URL to the directory dir with the filename. The filename can be generated from the URL if empty.

It will return the full path to the save file. Note that it may create both a file *and* return an error (e.g. in cases of non-200 status codes).

This is not intended to cover all possible use cases for fetching files, only the most common ones. Use the net/http package for more advanced usage.

Types

type ErrNotOK

type ErrNotOK struct {
	URL string
	Err string
}

ErrNotOK is used when the status code is not 200 OK.

func (ErrNotOK) Error

func (e ErrNotOK) Error() string

Source Files

httputilx.go

Directories

PathSynopsis
httputilx/headerPackage header provides functions for parsing and setting HTTP headers.
Version
v1.0.0 (latest)
Published
Mar 14, 2022
Platform
darwin/amd64
Imports
12 packages
Last checked
1 hour ago

Tools for package owners.