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