MCPcopy
hub / github.com/cloudflare/cloudflared / updateHandler

Function updateHandler

cmd/cloudflared/updater/workers_service_test.go:47–84  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

45const expectedUserMsg = "This message is expected when running a known buggy version"
46
47func updateHandler(w http.ResponseWriter, r *http.Request) {
48 version := mostRecentVersion
49 host := fmt.Sprintf("http://%s", r.Host)
50 url := host + "/download"
51
52 query := r.URL.Query()
53
54 if query.Get(BetaKeyName) == "true" {
55 version = mostRecentBetaVersion
56 url = host + "/beta"
57 }
58
59 requestedVersion := query.Get(VersionKeyName)
60 if requestedVersion != "" {
61 version = requestedVersion
62 url = fmt.Sprintf("%s?version=%s", url, requestedVersion)
63 }
64
65 if query.Get(ArchitectureKeyName) != runtime.GOARCH || query.Get(OSKeyName) != runtime.GOOS {
66 respondWithJSON(w, VersionResponse{Error: "unsupported os and architecture"}, http.StatusBadRequest)
67 return
68 }
69
70 h := sha256.New()
71 fmt.Fprint(h, version)
72 checksum := fmt.Sprintf("%x", h.Sum(nil))
73
74 var userMessage = ""
75 if query.Get(ClientVersionName) == knownBuggyVersion {
76 userMessage = expectedUserMsg
77 }
78 shouldUpdate := requestedVersion != "" || IsNewerVersion(query.Get(ClientVersionName), version)
79
80 v := VersionResponse{
81 URL: url, Version: version, Checksum: checksum, UserMessage: userMessage, ShouldUpdate: shouldUpdate,
82 }
83 respondWithJSON(w, v, http.StatusOK)
84}
85
86func gzipUpdateHandler(w http.ResponseWriter, r *http.Request) {
87 log.Println("got a request!")

Callers

nothing calls this directly

Calls 3

IsNewerVersionFunction · 0.85
GetMethod · 0.80
respondWithJSONFunction · 0.70

Tested by

no test coverage detected