MCPcopy
hub / github.com/AdguardTeam/AdGuardHome / handleVersionJSON

Method handleVersionJSON

internal/home/controlupdate.go:34–77  ·  view source on GitHub ↗

handleVersionJSON is the handler for the POST /control/version.json HTTP API. TODO(a.garipov): Find out if this API used with a GET method by anyone.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

32//
33// TODO(a.garipov): Find out if this API used with a GET method by anyone.
34func (web *webAPI) handleVersionJSON(w http.ResponseWriter, r *http.Request) {
35 ctx := r.Context()
36 l := web.logger
37
38 resp := &versionResponse{}
39 if web.conf.disableUpdate {
40 resp.Disabled = true
41 aghhttp.WriteJSONResponseOK(ctx, l, w, r, resp)
42
43 return
44 }
45
46 req := &struct {
47 Recheck bool `json:"recheck_now"`
48 }{}
49
50 var err error
51 if r.ContentLength != 0 {
52 err = json.NewDecoder(r.Body).Decode(req)
53 if err != nil {
54 aghhttp.ErrorAndLog(ctx, l, r, w, http.StatusBadRequest, "parsing request: %s", err)
55
56 return
57 }
58 }
59
60 err = web.requestVersionInfo(ctx, resp, req.Recheck)
61 if err != nil {
62 // Don't wrap the error, because it's informative enough as is.
63 aghhttp.ErrorAndLog(ctx, l, r, w, http.StatusBadGateway, "%s", err)
64
65 return
66 }
67
68 err = resp.setAllowedToAutoUpdate(ctx, l, web.tlsManager)
69 if err != nil {
70 // Don't wrap the error, because it's informative enough as is.
71 aghhttp.ErrorAndLog(ctx, l, r, w, http.StatusInternalServerError, "%s", err)
72
73 return
74 }
75
76 aghhttp.WriteJSONResponseOK(ctx, l, w, r, resp)
77}
78
79// requestVersionInfo sets the VersionInfo field of resp if it can reach the
80// update server.

Callers

nothing calls this directly

Calls 4

requestVersionInfoMethod · 0.95
WriteJSONResponseOKFunction · 0.92
ErrorAndLogFunction · 0.92

Tested by

no test coverage detected