(w http.ResponseWriter, r *http.Request)
| 26 | ) |
| 27 | |
| 28 | func (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 | } |
nothing calls this directly
no test coverage detected