digest

package module
Version: v0.0.0-...-1de5ed1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 1

README

GoDoc

Golang HTTP Digest Authentication

Overview

This is a fork of the (unmaintained) code.google.com/p/mlab-ns2/gae/ns/digest package. There's a descriptor leak in the original package, so this fork was created to patch the leak.

Usage

See the godocs for details.

Fork Maintainer

Bob Ziuchkovski (@bobziuchkovski)

Original Authors

Bipasa Chattopadhyay bipasa@cs.unc.edu Eric Gavaletz gavaletz@gmail.com Seon-Wook Park seon.wook@swook.net

License

Apache 2.0

Documentation

Overview

The digest package provides an implementation of http.RoundTripper that takes care of HTTP Digest Authentication (http://www.ietf.org/rfc/rfc2617.txt). This only implements the MD5 and "auth" portions of the RFC, but that covers the majority of avalible server side implementations including apache web server.

Example usage:

t := NewTransport("myUserName", "myP@55w0rd")
req, err := http.NewRequest("GET", "http://notreal.com/path?arg=1", nil)
if err != nil {
	return err
}
resp, err := t.RoundTrip(req)
if err != nil {
	return err
}

OR it can be used as a client:

c, err := t.Client()
if err != nil {
	return err
}
resp, err := c.Get("http://notreal.com/path?arg=1")
if err != nil {
	return err
}

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilTransport      = errors.New("Transport is nil")
	ErrBadChallenge      = errors.New("Challenge is bad")
	ErrAlgNotImplemented = errors.New("Alg not implemented")
)

Functions

This section is empty.

Types

type Transport

type Transport struct {
	Username  string
	Password  string
	Transport http.RoundTripper
}

Transport is an implementation of http.RoundTripper that takes care of http digest authentication.

func NewTransport

func NewTransport(username, password string) *Transport

NewTransport creates a new digest transport using the http.DefaultTransport.

func (*Transport) Client

func (t *Transport) Client() (*http.Client, error)

Client returns an HTTP client that uses the digest transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip makes a request expecting a 401 response that will require digest authentication. It creates the credentials it needs and makes a follow-up request.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL