Skip to content

Commit d906946

Browse files
committed
Adds NewPreemptiveAuth Authenticator
1 parent dfeae7f commit d906946

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

auth.go

+17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type authorizer struct {
3333
defAuth Authenticator
3434
}
3535

36+
type preemptiveAuthorizer struct {
37+
auth Authenticator
38+
}
39+
3640
// authShim structure that wraps the real Authenticator
3741
type authShim struct {
3842
factory AuthFactory
@@ -66,6 +70,11 @@ func NewEmptyAuth() Authorizer {
6670
return az
6771
}
6872

73+
// NewPreemptiveAuth creates a preemptive Authenticator
74+
func NewPreemptiveAuth(auth Authenticator) Authorizer {
75+
return &preemptiveAuthorizer{auth}
76+
}
77+
6978
// NewAuthenticator creates an Authenticator (Shim) per request
7079
func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) {
7180
var retryBuf io.Reader = body
@@ -205,3 +214,11 @@ func (n *nullAuth) Clone() Authenticator {
205214
func (n *nullAuth) String() string {
206215
return "NullAuth"
207216
}
217+
218+
func (b *preemptiveAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) {
219+
return b.auth.Clone(), body
220+
}
221+
222+
func (b *preemptiveAuthorizer) AddAuthenticator(key string, fn AuthFactory) {
223+
panic("not implemented")
224+
}

basicAuth.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gowebdav
22

33
import (
44
"fmt"
5-
"io"
65
"net/http"
76
)
87

@@ -46,17 +45,5 @@ func (b *BasicAuth) String() string {
4645
// no fancy body buffering, no magic at all
4746
// just dump as if it were on tag 8
4847
func NewBasicAuth(login, secret string) Authorizer {
49-
return &basicAuthAuthorizer{&BasicAuth{login, secret}}
50-
}
51-
52-
type basicAuthAuthorizer struct {
53-
auth *BasicAuth
54-
}
55-
56-
func (b *basicAuthAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) {
57-
return b.auth, body
58-
}
59-
60-
func (b *basicAuthAuthorizer) AddAuthenticator(key string, fn AuthFactory) {
61-
panic("not implemented")
48+
return &preemptiveAuthorizer{&BasicAuth{login, secret}}
6249
}

0 commit comments

Comments
 (0)