ensure host header is set

This commit is contained in:
Ben Lubar 2021-04-07 10:22:27 -05:00
parent d282a50439
commit 042ba2ce5e
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
1 changed files with 4 additions and 1 deletions

View File

@ -5,12 +5,13 @@ import (
"context"
"crypto"
"fmt"
"github.com/go-fed/httpsig"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"github.com/go-fed/httpsig"
)
const (
@ -118,6 +119,7 @@ func (h HttpSigTransport) Dereference(c context.Context, iri *url.URL) ([]byte,
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
req.Header.Add("User-Agent", fmt.Sprintf("%s %s", h.appAgent, h.gofedAgent))
req.Header.Set("Host", iri.Host)
h.getSignerMu.Lock()
err = h.getSigner.SignRequest(h.privKey, h.pubKeyId, req, nil)
h.getSignerMu.Unlock()
@ -146,6 +148,7 @@ func (h HttpSigTransport) Deliver(c context.Context, b []byte, to *url.URL) erro
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
req.Header.Add("User-Agent", fmt.Sprintf("%s %s", h.appAgent, h.gofedAgent))
req.Header.Set("Host", to.Host)
h.postSignerMu.Lock()
err = h.postSigner.SignRequest(h.privKey, h.pubKeyId, req, b)
h.postSignerMu.Unlock()