Skip to content

Commit 8462858

Browse files
committed
fix acme: some clients incorrectly sends content-type application/x-www-form-urlencoded, which confuses default unmarshaler
Signed-off-by: Vladimir Ermakov <[email protected]>
1 parent 39fc4cd commit 8462858

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

internal/server/server.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"log/slog"
66
"net"
7+
"net/http"
78
"net/netip"
89
"slices"
910

@@ -153,23 +154,27 @@ func RegisterEndpoints(srv *fuego.Server, htp htpasswd.HTPasswd, zctl zone.Contr
153154
option.QueryBool("offline", "Not supported, a no-op for compatibility."),
154155
)
155156

156-
fuego.Post(srv, "/acme/update",
157-
func(ctx fuego.ContextWithBody[ACMEUpdateRequest]) (*ACMEUpdateResponse, error) {
157+
fuego.PostStd(srv, "/acme/update",
158+
func(w http.ResponseWriter, r *http.Request) {
158159

160+
ctx := r.Context()
159161
lg := slog.Default()
162+
defer r.Body.Close() // nolint: errcheck
160163

161-
req, err := ctx.Body()
164+
req, err := fuego.ReadJSON[ACMEUpdateRequest](ctx, r.Body)
162165
if err != nil {
163166
lg.ErrorContext(ctx, "Failed to parse body", "error", err)
164-
return nil, err
167+
fuego.SendError(w, r, err)
168+
return
165169
}
166170

167171
err = zctl.UpdateACMEChallenge(ctx, req.Subdomain, req.TXT)
168172
if err != nil {
169-
return nil, err
173+
fuego.SendError(w, r, err)
174+
return
170175
}
171176

172-
return &ACMEUpdateResponse{TXT: req.TXT}, nil
177+
fuego.SendJSON(w, r, &ACMEUpdateResponse{TXT: req.TXT}) // nolint: errcheck
173178
},
174179
option.Summary("update acme"),
175180
option.Description("Update ACME challenge TXT record"),
@@ -183,5 +188,16 @@ func RegisterEndpoints(srv *fuego.Server, htp htpasswd.HTPasswd, zctl zone.Contr
183188
"basicAuth": []string{},
184189
},
185190
),
191+
option.RequestBody(
192+
fuego.RequestBody{
193+
Type: new(ACMEUpdateRequest),
194+
ContentTypes: []string{"application/json"},
195+
},
196+
),
197+
option.AddResponse(http.StatusOK, "Record updated",
198+
fuego.Response{
199+
Type: new(ACMEUpdateResponse),
200+
},
201+
),
186202
)
187203
}

0 commit comments

Comments
 (0)