Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: use rw.WriteHeader to write responses without bodies #13870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (api *API) deleteAPIKey(rw http.ResponseWriter, r *http.Request) {
return
}

httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}

// @Summary Get token config
Expand Down
2 changes: 1 addition & 1 deletion coderd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ

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

Expand Down
2 changes: 1 addition & 1 deletion coderd/externalauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (api *API) postExternalAuthDeviceByID(rw http.ResponseWriter, r *http.Reque
return
}
}
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}

// @Summary Get external auth device by ID.
Expand Down
2 changes: 1 addition & 1 deletion coderd/identityprovider/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func RevokeApp(db database.Store) http.HandlerFunc {
httpapi.InternalServerError(rw, err)
return
}
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}
}
4 changes: 2 additions & 2 deletions coderd/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (api *API) deleteOAuth2ProviderApp(rw http.ResponseWriter, r *http.Request)
})
return
}
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}

// @Summary Get OAuth2 application secrets.
Expand Down Expand Up @@ -324,7 +324,7 @@ func (api *API) deleteOAuth2ProviderAppSecret(rw http.ResponseWriter, r *http.Re
})
return
}
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}

// @Summary OAuth2 authorization request.
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {

if updated.UpdatedAt.IsZero() {
aReq.New = template
httpapi.Write(ctx, rw, http.StatusNotModified, nil)
rw.WriteHeader(http.StatusNotModified)
return
}
aReq.New = updated
Expand Down
9 changes: 3 additions & 6 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,9 @@ func (api *API) postUser(rw http.ResponseWriter, r *http.Request) {
// @Summary Delete user
// @ID delete-user
// @Security CoderSessionToken
// @Produce json
// @Tags Users
// @Param user path string true "User ID, name, or me"
// @Success 200 {object} codersdk.User
// @Success 204
// @Router /users/{user} [delete]
func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand Down Expand Up @@ -558,9 +557,7 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
}
user.Deleted = true
aReq.New = user
httpapi.Write(ctx, rw, http.StatusOK, codersdk.Response{
Message: "User has been deleted!",
})
rw.WriteHeader(http.StatusNoContent)
}

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

httpapi.Write(ctx, rw, http.StatusNoContent, nil)
rw.WriteHeader(http.StatusNoContent)
}

// @Summary Get user roles
Expand Down
4 changes: 1 addition & 3 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,7 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {

// If the workspace is already in the desired state do nothing!
if workspace.DormantAt.Valid == req.Dormant {
httpapi.Write(ctx, rw, http.StatusNotModified, codersdk.Response{
Message: "Nothing to do!",
})
rw.WriteHeader(http.StatusNotModified)
return
}

Expand Down
2 changes: 1 addition & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (c *Client) DeleteUser(ctx context.Context, id uuid.UUID) error {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
if res.StatusCode != http.StatusNoContent {
return ReadBodyAsError(res)
}
return nil
Expand Down
34 changes: 3 additions & 31 deletions docs/api/users.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading