Skip to content

Commit

Permalink
Authorization: Scope-Probe <token>
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbourgon committed Aug 7, 2015
1 parent 7d51f17 commit a8d3fdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion xfer/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 %s", token)
}

// MultiPublisher implements Publisher over a set of publishers.
type MultiPublisher struct {
mtx sync.RWMutex
Expand Down
2 changes: 1 addition & 1 deletion xfer/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8d3fdf

Please sign in to comment.