Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Content-Digest header #31

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ccclient/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewUploader(logger lager.Logger, httpClient *http.Client) Uploader {
}

const contentMD5Header = "Content-MD5"
const contentDigestHeader = "Content-Digest"

func (u *uploader) Upload(uploadURL *url.URL, filename string, r *http.Request, cancelChan <-chan struct{}) (*http.Response, error) {
if r.ContentLength <= 0 {
Expand All @@ -39,6 +40,7 @@ func (u *uploader) Upload(uploadURL *url.URL, filename string, r *http.Request,
}

uploadReq.Header.Set(contentMD5Header, r.Header.Get(contentMD5Header))
uploadReq.Header.Set(contentDigestHeader, r.Header.Get(contentDigestHeader))
uploadReq.URL = uploadURL

var rsp *http.Response
Expand Down
7 changes: 7 additions & 0 deletions ccclient/uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ var _ = Describe("Uploader", func() {
Expect(uploadRequest.Header.Get("Content-MD5")).To(Equal("the-md5"))
})

It("Forwards Content-Digest header onto the upload request", func() {
var uploadRequest *http.Request
Eventually(uploadRequestChan).Should(Receive(&uploadRequest))
Expect(uploadRequest.Header.Get("Content-Digest")).To(Equal("the-digest"))
})

Context("When the upload URL has basic auth credentials", func() {
BeforeEach(func() {
uploadURL.User = url.UserPassword("bob", "cobb")
Expand Down Expand Up @@ -218,6 +224,7 @@ func createValidRequest() *http.Request {
Expect(err).NotTo(HaveOccurred())

request.Header.Set("Content-MD5", "the-md5")
request.Header.Set("Content-Digest", "the-digest")
request.Body = ioutil.NopCloser(bytes.NewBufferString(""))

fmt.Fprintf(GinkgoWriter, "Content-length %d\n", request.ContentLength)
Expand Down
9 changes: 9 additions & 0 deletions handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var _ = Describe("Handlers", func() {
incomingRequest, err = http.NewRequest("POST", "", buffer)
Expect(err).NotTo(HaveOccurred())
incomingRequest.Header.Set("Content-MD5", "the-md5")
incomingRequest.Header.Set("Content-Digest", "the-digest")

fakeCloudController = ghttp.NewServer()

Expand Down Expand Up @@ -128,6 +129,10 @@ var _ = Describe("Handlers", func() {
Expect(uploadedHeaders.Get("Content-MD5")).To(Equal("the-md5"))
})

It("forwards the content-digest header", func() {
Expect(uploadedHeaders.Get("Content-Digest")).To(Equal("the-digest"))
})

It("uploads the correct file", func() {
Expect(uploadedBytes).To(Equal([]byte("the file I'm uploading")))
Expect(uploadedFileName).To(Equal("droplet.tgz"))
Expand Down Expand Up @@ -243,6 +248,10 @@ var _ = Describe("Handlers", func() {
It("forwards the content-md5 header", func() {
Expect(uploadedHeaders.Get("Content-MD5")).To(Equal("the-md5"))
})

It("forwards the content-digest header", func() {
Expect(uploadedHeaders.Get("Content-Digest")).To(Equal("the-digest"))
})
})

Context("uploading the file, when the inbound upload request is missing content length", func() {
Expand Down