MCPcopy
hub / github.com/harness/harness / DownloadPackageFile

Method DownloadPackageFile

registry/app/api/handler/python/download.go:28–76  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

26)
27
28func (h *handler) DownloadPackageFile(w http.ResponseWriter, r *http.Request) {
29 ctx := r.Context()
30 info, ok := request.ArtifactInfoFrom(ctx).(*pythontype.ArtifactInfo)
31 if !ok {
32 h.HandleErrors(ctx, []error{fmt.Errorf("failed to fetch info from context")}, w)
33 return
34 }
35
36 response := h.controller.DownloadPackageFile(ctx, *info)
37 if response == nil {
38 h.HandleErrors(ctx, []error{fmt.Errorf("failed to get response from controller")}, w)
39 return
40 }
41
42 defer func() {
43 if response.Body != nil {
44 err := response.Body.Close()
45 if err != nil {
46 log.Ctx(ctx).Error().Msgf("Failed to close body: %v", err)
47 }
48 }
49
50 if response.ReadCloser != nil {
51 err := response.ReadCloser.Close()
52 if err != nil {
53 log.Ctx(ctx).Error().Msgf("Failed to close read closer: %v", err)
54 }
55 }
56 }()
57
58 if response.GetError() != nil {
59 h.HandleError(ctx, w, response.GetError())
60 return
61 }
62
63 if response.RedirectURL != "" {
64 http.Redirect(w, r, response.RedirectURL, http.StatusTemporaryRedirect)
65 return
66 }
67
68 w.WriteHeader(http.StatusOK)
69 err := commons.ServeContent(w, r, response.Body, info.Filename, response.ReadCloser)
70 if err != nil {
71 log.Ctx(ctx).Error().Msgf("Failed to serve content: %v", err)
72 h.HandleError(ctx, w, err)
73 return
74 }
75 response.ResponseHeaders.WriteToResponse(w)
76}

Callers

nothing calls this directly

Calls 12

HandleErrorsMethod · 0.95
HandleErrorMethod · 0.95
ArtifactInfoFromFunction · 0.92
ServeContentFunction · 0.92
MsgfMethod · 0.80
WriteToResponseMethod · 0.80
DownloadPackageFileMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
GetErrorMethod · 0.65
ErrorfMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected