diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d99f809..51ac99b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,9 +25,13 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Incorrect `Content-Type` header value in `POST /control/version.json` and `GET + /control/dhcp/interfaces` HTTP APIs ([#5716]). - Provided bootstrap servers are now used to resolve the hostnames of plain UDP/TCP upstream servers. +[#5716]: https://github.com/AdguardTeam/AdGuardHome/issues/5716 + diff --git a/internal/dhcpd/http_unix.go b/internal/dhcpd/http_unix.go index 6430afdc..23e7fe81 100644 --- a/internal/dhcpd/http_unix.go +++ b/internal/dhcpd/http_unix.go @@ -350,8 +350,10 @@ type netInterfaceJSON struct { Addrs6 []netip.Addr `json:"ipv6_addresses"` } +// handleDHCPInterfaces is the handler for the GET /control/dhcp/interfaces HTTP +// API. func (s *server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { - response := map[string]netInterfaceJSON{} + resp := map[string]netInterfaceJSON{} ifaces, err := net.Interfaces() if err != nil { @@ -424,20 +426,11 @@ func (s *server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) { } if len(jsonIface.Addrs4)+len(jsonIface.Addrs6) != 0 { jsonIface.GatewayIP = aghnet.GatewayIP(iface.Name) - response[iface.Name] = jsonIface + resp[iface.Name] = jsonIface } } - err = json.NewEncoder(w).Encode(response) - if err != nil { - aghhttp.Error( - r, - w, - http.StatusInternalServerError, - "Failed to marshal json with available interfaces: %s", - err, - ) - } + _ = aghhttp.WriteJSONResponse(w, r, resp) } // dhcpSearchOtherResult contains information about other DHCP server for diff --git a/internal/home/control.go b/internal/home/control.go index 9c48d5bc..ae83507c 100644 --- a/internal/home/control.go +++ b/internal/home/control.go @@ -180,7 +180,7 @@ func registerControlHandlers() { httpRegister(http.MethodGet, "/control/status", handleStatus) httpRegister(http.MethodPost, "/control/i18n/change_language", handleI18nChangeLanguage) httpRegister(http.MethodGet, "/control/i18n/current_language", handleI18nCurrentLanguage) - Context.mux.HandleFunc("/control/version.json", postInstall(optionalAuth(handleGetVersionJSON))) + Context.mux.HandleFunc("/control/version.json", postInstall(optionalAuth(handleVersionJSON))) httpRegister(http.MethodPost, "/control/update", handleUpdate) httpRegister(http.MethodGet, "/control/profile", handleGetProfile) httpRegister(http.MethodPut, "/control/profile/update", handlePutProfile) diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index 1cea1d14..f7e56208 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -26,15 +26,14 @@ type temporaryError interface { Temporary() (ok bool) } -// Get the latest available version from the Internet -func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { +// 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. +func handleVersionJSON(w http.ResponseWriter, r *http.Request) { resp := &versionResponse{} if Context.disableUpdate { resp.Disabled = true - err := json.NewEncoder(w).Encode(resp) - if err != nil { - aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) - } + _ = aghhttp.WriteJSONResponse(w, r, resp) return } diff --git a/openapi/CHANGELOG.md b/openapi/CHANGELOG.md index 922788bb..d499cae9 100644 --- a/openapi/CHANGELOG.md +++ b/openapi/CHANGELOG.md @@ -4,6 +4,16 @@ ## v0.108.0: API changes +## v0.107.30: API changes + +### `POST /control/version.json` and `GET /control/dhcp/interfaces` content type + +* The value of the `Content-Type` header in the `POST /control/version.json` and + `GET /control/dhcp/interfaces` HTTP APIs is now correctly set to + `application/json` as opposed to `text/plain`. + + + ## v0.107.29: API changes ### `GET /control/clients` And `GET /control/clients/find` @@ -16,6 +26,8 @@ set AdGuard Home will use default value (false). It can be changed in the future versions. + + ## v0.107.27: API changes ### The new optional fields `"edns_cs_use_custom"` and `"edns_cs_custom_ip"` in `DNSConfig`