MCPcopy Create free account
hub / github.com/archlinux-de/pkgstats-cli / handleSubmit

Function handleSubmit

cmd/testhelper_server_test.go:52–78  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

50}
51
52func 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
80func handlePackages(w http.ResponseWriter, r *http.Request) {
81 w.Header().Set("Content-Type", "application/json")

Callers

nothing calls this directly

Calls 2

validateSubmitRequestFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected