Skip to content

Commit de2585b

Browse files
authored
chore: use rw.WriteHeader to write responses without bodies (coder#13870)
1 parent fd10ea1 commit de2585b

File tree

12 files changed

+19
-62
lines changed

12 files changed

+19
-62
lines changed

coderd/apidoc/docs.go

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apikey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (api *API) deleteAPIKey(rw http.ResponseWriter, r *http.Request) {
333333
return
334334
}
335335

336-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
336+
rw.WriteHeader(http.StatusNoContent)
337337
}
338338

339339
// @Summary Get token config

coderd/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
235235

236236
if bytes.Equal(settingsJSON, []byte(currentSettingsJSON)) {
237237
// See: https://www.rfc-editor.org/rfc/rfc7231#section-6.3.5
238-
httpapi.Write(r.Context(), rw, http.StatusNoContent, nil)
238+
rw.WriteHeader(http.StatusNoContent)
239239
return
240240
}
241241

coderd/externalauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (api *API) postExternalAuthDeviceByID(rw http.ResponseWriter, r *http.Reque
197197
return
198198
}
199199
}
200-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
200+
rw.WriteHeader(http.StatusNoContent)
201201
}
202202

203203
// @Summary Get external auth device by ID.

coderd/identityprovider/revoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ func RevokeApp(db database.Store) http.HandlerFunc {
3939
httpapi.InternalServerError(rw, err)
4040
return
4141
}
42-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
42+
rw.WriteHeader(http.StatusNoContent)
4343
}
4444
}

coderd/oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (api *API) deleteOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request)
207207
})
208208
return
209209
}
210-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
210+
rw.WriteHeader(http.StatusNoContent)
211211
}
212212

213213
// @Summary Get OAuth2 application secrets.
@@ -324,7 +324,7 @@ func (api *API) deleteOAuth2ProviderAppSecret(rw http.ResponseWriter, r *http.Re
324324
})
325325
return
326326
}
327-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
327+
rw.WriteHeader(http.StatusNoContent)
328328
}
329329

330330
// @Summary OAuth2 authorization request.

coderd/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
791791

792792
if updated.UpdatedAt.IsZero() {
793793
aReq.New = template
794-
httpapi.Write(ctx, rw, http.StatusNotModified, nil)
794+
rw.WriteHeader(http.StatusNotModified)
795795
return
796796
}
797797
aReq.New = updated

coderd/users.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,9 @@ func (api *API) postUser(rw http.ResponseWriter, r *http.Request) {
501501
// @Summary Delete user
502502
// @ID delete-user
503503
// @Security CoderSessionToken
504-
// @Produce json
505504
// @Tags Users
506505
// @Param user path string true "User ID, name, or me"
507-
// @Success 200 {object} codersdk.User
506+
// @Success 204
508507
// @Router /users/{user} [delete]
509508
func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
510509
ctx := r.Context()
@@ -558,9 +557,7 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
558557
}
559558
user.Deleted = true
560559
aReq.New = user
561-
httpapi.Write(ctx, rw, http.StatusOK, codersdk.Response{
562-
Message: "User has been deleted!",
563-
})
560+
rw.WriteHeader(http.StatusNoContent)
564561
}
565562

566563
// Returns the parameterized user requested. All validation
@@ -1013,7 +1010,7 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
10131010
newUser.HashedPassword = []byte(hashedPassword)
10141011
aReq.New = newUser
10151012

1016-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
1013+
rw.WriteHeader(http.StatusNoContent)
10171014
}
10181015

10191016
// @Summary Get user roles

coderd/workspaces.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,7 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
927927

928928
// If the workspace is already in the desired state do nothing!
929929
if workspace.DormantAt.Valid == req.Dormant {
930-
httpapi.Write(ctx, rw, http.StatusNotModified, codersdk.Response{
931-
Message: "Nothing to do!",
932-
})
930+
rw.WriteHeader(http.StatusNotModified)
933931
return
934932
}
935933

codersdk/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (c *Client) DeleteUser(ctx context.Context, id uuid.UUID) error {
308308
return err
309309
}
310310
defer res.Body.Close()
311-
if res.StatusCode != http.StatusOK {
311+
if res.StatusCode != http.StatusNoContent {
312312
return ReadBodyAsError(res)
313313
}
314314
return nil

docs/api/users.md

Lines changed: 3 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)