File size: 684 Bytes
7107f0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gowebdav

import (
	"encoding/base64"
	"net/http"
)

// BasicAuth structure holds our credentials
type BasicAuth struct {
	user string
	pw   string
}

// Type identifies the BasicAuthenticator
func (b *BasicAuth) Type() string {
	return "BasicAuth"
}

// User holds the BasicAuth username
func (b *BasicAuth) User() string {
	return b.user
}

// Pass holds the BasicAuth password
func (b *BasicAuth) Pass() string {
	return b.pw
}

// Authorize the current request
func (b *BasicAuth) Authorize(req *http.Request, method string, path string) {
	a := b.user + ":" + b.pw
	auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
	req.Header.Set("Authorization", auth)
}