package zhttputil
import "zgo.at/zstd/zhttputil"
Package zhttputil provides HTTP utility functions.
Index ¶
- func DumpBody(r *http.Request, maxSize int64) ([]byte, error)
- func Fetch(url string) ([]byte, error)
- func SafeClient() *http.Client
- func SafeTransport(ports []int) *http.Transport
- func Save(url string, dir string, filename string) (string, error)
- type ErrNotOK
- type NopWriter
Functions ¶
func DumpBody ¶
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 ¶
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 SafeClient ¶
SafeClient returns a HTTP client that is only allowed to connect on the given ports to non-private addresses.
This also sets the Timeout to 30 seconds, instead of the no timeout.
See: https://www.agwa.name/blog/post/preventing_server_side_request_forgery_in_golang
Also see SafeTransport() and znet.SafeDialer().
func SafeTransport ¶
SafeTransport returns a HTTP transport that is only allowed to connect on the given ports to non-private addresses.
Port 80 and 443 are used if the list is empty.
Also see SafeClient() and znet.SafeDialer().
func Save ¶
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 ¶
ErrNotOK is used when the status code is not 200 OK.
func (ErrNotOK) Error ¶
type NopWriter ¶
type NopWriter struct{ http.ResponseWriter }
NopWriter is a http.ResponseWriter that doesn't write any body content.
func (*NopWriter) Write ¶
Write is a no-op.
Source Files ¶
zhttputil.go
- Version
- v0.0.0-20240930202209-a63c3335042a (latest)
- Published
- Sep 30, 2024
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 2 days ago –
Tools for package owners.