Authorization: Scope-Probe token=<token>

This commit is contained in:
Peter Bourgon
2015-08-07 17:21:44 +02:00
parent 7d51f173ea
commit edf0ceb212
2 changed files with 8 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ func (p HTTPPublisher) Publish(rpt report.Report) error {
if err != nil {
return err
}
req.Header.Set("Authorization", p.token)
req.Header.Set("Authorization", AuthorizationHeader(p.token))
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
@@ -64,6 +64,12 @@ func (p HTTPPublisher) Publish(rpt report.Report) error {
return nil
}
// AuthorizationHeader returns a value suitable for an HTTP Authorization
// header, based on the passed token string.
func AuthorizationHeader(token string) string {
return fmt.Sprintf("Scope-Probe token=%s", token)
}
// MultiPublisher implements Publisher over a set of publishers.
type MultiPublisher struct {
mtx sync.RWMutex

View File

@@ -19,7 +19,7 @@ func TestHTTPPublisher(t *testing.T) {
)
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if want, have := token, r.Header.Get("Authorization"); want != have {
if want, have := xfer.AuthorizationHeader(token), r.Header.Get("Authorization"); want != have {
t.Errorf("want %q, have %q", want, have)
}
var have report.Report