Skip to content

Commit

Permalink
Add missing status code constructor methods on HttpResponse (#3042)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyqsimon committed Jul 20, 2023
1 parent d22c9f9 commit 1040bc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add `HttpServer::{bind, listen}_auto_h2c()` method behind new `http2` crate feature.
- Add `Resource::{get, post, etc...}` methods for more concisely adding routes that don't need additional guards.
- Add several missing convenience methods on `HttpResponse` for their respective status codes.

### Changed

Expand Down
16 changes: 13 additions & 3 deletions actix-web/src/response/http_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ impl HttpResponse {
NonAuthoritativeInformation,
StatusCode::NON_AUTHORITATIVE_INFORMATION
);

static_resp!(NoContent, StatusCode::NO_CONTENT);
static_resp!(ResetContent, StatusCode::RESET_CONTENT);
static_resp!(PartialContent, StatusCode::PARTIAL_CONTENT);
static_resp!(MultiStatus, StatusCode::MULTI_STATUS);
static_resp!(AlreadyReported, StatusCode::ALREADY_REPORTED);
static_resp!(ImUsed, StatusCode::IM_USED);

static_resp!(MultipleChoices, StatusCode::MULTIPLE_CHOICES);
static_resp!(MovedPermanently, StatusCode::MOVED_PERMANENTLY);
Expand All @@ -42,10 +42,10 @@ impl HttpResponse {
static_resp!(PermanentRedirect, StatusCode::PERMANENT_REDIRECT);

static_resp!(BadRequest, StatusCode::BAD_REQUEST);
static_resp!(NotFound, StatusCode::NOT_FOUND);
static_resp!(Unauthorized, StatusCode::UNAUTHORIZED);
static_resp!(PaymentRequired, StatusCode::PAYMENT_REQUIRED);
static_resp!(Forbidden, StatusCode::FORBIDDEN);
static_resp!(NotFound, StatusCode::NOT_FOUND);
static_resp!(MethodNotAllowed, StatusCode::METHOD_NOT_ALLOWED);
static_resp!(NotAcceptable, StatusCode::NOT_ACCEPTABLE);
static_resp!(
Expand All @@ -57,13 +57,18 @@ impl HttpResponse {
static_resp!(Gone, StatusCode::GONE);
static_resp!(LengthRequired, StatusCode::LENGTH_REQUIRED);
static_resp!(PreconditionFailed, StatusCode::PRECONDITION_FAILED);
static_resp!(PreconditionRequired, StatusCode::PRECONDITION_REQUIRED);
static_resp!(PayloadTooLarge, StatusCode::PAYLOAD_TOO_LARGE);
static_resp!(UriTooLong, StatusCode::URI_TOO_LONG);
static_resp!(UnsupportedMediaType, StatusCode::UNSUPPORTED_MEDIA_TYPE);
static_resp!(RangeNotSatisfiable, StatusCode::RANGE_NOT_SATISFIABLE);
static_resp!(ExpectationFailed, StatusCode::EXPECTATION_FAILED);
static_resp!(ImATeapot, StatusCode::IM_A_TEAPOT);
static_resp!(MisdirectedRequest, StatusCode::MISDIRECTED_REQUEST);
static_resp!(UnprocessableEntity, StatusCode::UNPROCESSABLE_ENTITY);
static_resp!(Locked, StatusCode::LOCKED);
static_resp!(FailedDependency, StatusCode::FAILED_DEPENDENCY);
static_resp!(UpgradeRequired, StatusCode::UPGRADE_REQUIRED);
static_resp!(PreconditionRequired, StatusCode::PRECONDITION_REQUIRED);
static_resp!(TooManyRequests, StatusCode::TOO_MANY_REQUESTS);
static_resp!(
RequestHeaderFieldsTooLarge,
Expand All @@ -83,6 +88,11 @@ impl HttpResponse {
static_resp!(VariantAlsoNegotiates, StatusCode::VARIANT_ALSO_NEGOTIATES);
static_resp!(InsufficientStorage, StatusCode::INSUFFICIENT_STORAGE);
static_resp!(LoopDetected, StatusCode::LOOP_DETECTED);
static_resp!(NotExtended, StatusCode::NOT_EXTENDED);
static_resp!(
NetworkAuthenticationRequired,
StatusCode::NETWORK_AUTHENTICATION_REQUIRED
);
}

#[cfg(test)]
Expand Down

0 comments on commit 1040bc3

Please sign in to comment.