net

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Copyright 2023 Christopher Briscoe. All rights reserved.

Copyright 2023 Christopher Briscoe. All rights reserved.

Copyright 2023 Christopher Briscoe. All rights reserved.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("404 not found")

ErrNotFound is returned when the response status is 404 Status Not Found

Functions

func GetIP

func GetIP(req *http.Request) string

GetIP will first try to get proxy IP headers in case the server is running behind a reverse proxy. Otherwise, just use the http.Request.RemoteAddr with the port stripped.

func GetRequestParams

func GetRequestParams(key string) ([]string, string)

GetRequestParams splits off the preferrend encoding from the request keys

func SetPreferredEncoding

func SetPreferredEncoding(w http.ResponseWriter, r *http.Request)

SetPreferredEncoding will default to using BR compression if the client accepts that encoding. Otherwise, use GZIP.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an http client

func (*Client) ClearHeaders

func (c *Client) ClearHeaders()

ClearHeaders deletes the headers map

func (*Client) Fetch

func (c *Client) Fetch(url string) (*http.Response, []byte, error)

Fetch will load a network url and return the response in []byte

func (*Client) GetHeader

func (c *Client) GetHeader(k string) string

GetHeader retrieves an already set header

func (*Client) SetHeader

func (c *Client) SetHeader(k, v string)

SetHeader sets a request header

func (*Client) SetTimeout

func (c *Client) SetTimeout(d time.Duration)

SetTimeout sets the network timeout of the request

Jump to

Keyboard shortcuts

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