1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
13
"github.com/juju/juju/resource"
16
// NewHTTPDownloadRequest creates a new HTTP download request
17
// for the given resource.
19
// Intended for use on the client side.
20
func NewHTTPDownloadRequest(resourceName string) (*http.Request, error) {
21
return http.NewRequest("GET", "/resources/"+resourceName, nil)
24
// ExtractDownloadRequest pulls the download request info out of the
25
// given HTTP request.
27
// Intended for use on the server side.
28
func ExtractDownloadRequest(req *http.Request) string {
29
return req.URL.Query().Get(":resource")
32
// UpdateDownloadResponse sets the appropriate headers in the response
33
// to an HTTP download request.
35
// Intended for use on the server side.
36
func UpdateDownloadResponse(resp http.ResponseWriter, resource resource.Resource) {
37
resp.Header().Set("Content-Type", ContentTypeRaw)
38
resp.Header().Set("Content-Length", fmt.Sprint(resource.Size))
39
resp.Header().Set("Content-Sha384", resource.Fingerprint.String())
42
// ExtractDownloadResponse pulls the download size and checksum
43
// from the HTTP response.
44
func ExtractDownloadResponse(resp *http.Response) (int64, charmresource.Fingerprint, error) {
45
var fp charmresource.Fingerprint
47
// TODO(ericsnow) Finish!
48
// See UpdateDownloadResponse for the data to extract.
49
return 0, fp, errors.New("not finished")