(w http.ResponseWriter, r *http.Request)
| 50 | } |
| 51 | |
| 52 | func handleSubmit(w http.ResponseWriter, r *http.Request) { |
| 53 | if r.Header.Get("User-Agent") != build.UserAgent { |
| 54 | http.Error(w, fmt.Sprintf("Invalid user agent %s", r.Header.Get("User-Agent")), http.StatusBadRequest) |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | if r.URL.Query().Get("redirect") == "" { |
| 59 | w.Header().Set("Location", "/api/submit?redirect=1") |
| 60 | w.WriteHeader(http.StatusPermanentRedirect) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | body, err := io.ReadAll(r.Body) |
| 65 | if err != nil { |
| 66 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 67 | return |
| 68 | } |
| 69 | defer r.Body.Close() |
| 70 | |
| 71 | var request submit.Request |
| 72 | if err := json.Unmarshal(body, &request); err != nil { |
| 73 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 74 | return |
| 75 | } |
| 76 | |
| 77 | validateSubmitRequest(w, &request) |
| 78 | } |
| 79 | |
| 80 | func handlePackages(w http.ResponseWriter, r *http.Request) { |
| 81 | w.Header().Set("Content-Type", "application/json") |
nothing calls this directly
no test coverage detected