Esempio n. 1
0
// NewDownloadHandler returns a new HTTP handler for the given args.
func NewDownloadHandler(args apihttp.NewHandlerArgs) http.Handler {
	extractor := &httpDownloadRequestExtractor{
		connect: args.Connect,
	}
	deps := internalserver.NewLegacyHTTPHandlerDeps(extractor)
	return internalserver.NewLegacyHTTPHandler(deps)
}
Esempio n. 2
0
func (s *LegacyHTTPHandlerSuite) TestIntegration(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
	s.opener.ReturnOpenResource = opened
	s.deps.ReturnNewResourceOpener = s.opener
	deps := server.NewLegacyHTTPHandlerDeps(s.deps)
	h := server.NewLegacyHTTPHandler(deps)
	req, err := api.NewHTTPDownloadRequest("spam")
	c.Assert(err, jc.ErrorIsNil)
	req.URL, err = url.ParseRequestURI("https://api:17018/units/eggs/1/resources/spam?:resource=spam")
	c.Assert(err, jc.ErrorIsNil)
	resp := &fakeResponseWriter{
		stubResponseWriter: s.resp,
	}

	c.Logf("%#v", opened.ReadCloser)
	h.ServeHTTP(resp, req)

	resp.checkWritten(c, "some data", http.Header{
		"Content-Type":   []string{api.ContentTypeRaw},
		"Content-Length": []string{"9"}, // len("some data")
		"Content-Sha384": []string{opened.Fingerprint.String()},
	})
}