Skip to content

Commit 3a68a93

Browse files
committed
perf(http): replace HttpStatusCode enum with constant object for better tree-shaking
The HttpStatusCode enum has been replaced with a constant object using `as const` to enable better tree-shaking and reduce bundle size. Type compatibility is maintained through a type alias, ensuring no breaking changes for existing code. Fixes angular#64767
1 parent 07b8e95 commit 3a68a93

File tree

2 files changed

+131
-197
lines changed

2 files changed

+131
-197
lines changed

goldens/public-api/common/http/index.api.md

Lines changed: 64 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,134 +3130,70 @@ export interface HttpSentEvent {
31303130
}
31313131

31323132
// @public
3133-
export enum HttpStatusCode {
3134-
// (undocumented)
3135-
Accepted = 202,
3136-
// (undocumented)
3137-
AlreadyReported = 208,
3138-
// (undocumented)
3139-
BadGateway = 502,
3140-
// (undocumented)
3141-
BadRequest = 400,
3142-
// (undocumented)
3143-
Conflict = 409,
3144-
// (undocumented)
3145-
Continue = 100,
3146-
// (undocumented)
3147-
Created = 201,
3148-
// (undocumented)
3149-
EarlyHints = 103,
3150-
// (undocumented)
3151-
ExpectationFailed = 417,
3152-
// (undocumented)
3153-
FailedDependency = 424,
3154-
// (undocumented)
3155-
Forbidden = 403,
3156-
// (undocumented)
3157-
Found = 302,
3158-
// (undocumented)
3159-
GatewayTimeout = 504,
3160-
// (undocumented)
3161-
Gone = 410,
3162-
// (undocumented)
3163-
HttpVersionNotSupported = 505,
3164-
// (undocumented)
3165-
ImATeapot = 418,
3166-
// (undocumented)
3167-
ImUsed = 226,
3168-
// (undocumented)
3169-
InsufficientStorage = 507,
3170-
// (undocumented)
3171-
InternalServerError = 500,
3172-
// (undocumented)
3173-
LengthRequired = 411,
3174-
// (undocumented)
3175-
Locked = 423,
3176-
// (undocumented)
3177-
LoopDetected = 508,
3178-
// (undocumented)
3179-
MethodNotAllowed = 405,
3180-
// (undocumented)
3181-
MisdirectedRequest = 421,
3182-
// (undocumented)
3183-
MovedPermanently = 301,
3184-
// (undocumented)
3185-
MultipleChoices = 300,
3186-
// (undocumented)
3187-
MultiStatus = 207,
3188-
// (undocumented)
3189-
NetworkAuthenticationRequired = 511,
3190-
// (undocumented)
3191-
NoContent = 204,
3192-
// (undocumented)
3193-
NonAuthoritativeInformation = 203,
3194-
// (undocumented)
3195-
NotAcceptable = 406,
3196-
// (undocumented)
3197-
NotExtended = 510,
3198-
// (undocumented)
3199-
NotFound = 404,
3200-
// (undocumented)
3201-
NotImplemented = 501,
3202-
// (undocumented)
3203-
NotModified = 304,
3204-
// (undocumented)
3205-
Ok = 200,
3206-
// (undocumented)
3207-
PartialContent = 206,
3208-
// (undocumented)
3209-
PayloadTooLarge = 413,
3210-
// (undocumented)
3211-
PaymentRequired = 402,
3212-
// (undocumented)
3213-
PermanentRedirect = 308,
3214-
// (undocumented)
3215-
PreconditionFailed = 412,
3216-
// (undocumented)
3217-
PreconditionRequired = 428,
3218-
// (undocumented)
3219-
Processing = 102,
3220-
// (undocumented)
3221-
ProxyAuthenticationRequired = 407,
3222-
// (undocumented)
3223-
RangeNotSatisfiable = 416,
3224-
// (undocumented)
3225-
RequestHeaderFieldsTooLarge = 431,
3226-
// (undocumented)
3227-
RequestTimeout = 408,
3228-
// (undocumented)
3229-
ResetContent = 205,
3230-
// (undocumented)
3231-
SeeOther = 303,
3232-
// (undocumented)
3233-
ServiceUnavailable = 503,
3234-
// (undocumented)
3235-
SwitchingProtocols = 101,
3236-
// (undocumented)
3237-
TemporaryRedirect = 307,
3238-
// (undocumented)
3239-
TooEarly = 425,
3240-
// (undocumented)
3241-
TooManyRequests = 429,
3242-
// (undocumented)
3243-
Unauthorized = 401,
3244-
// (undocumented)
3245-
UnavailableForLegalReasons = 451,
3246-
// (undocumented)
3247-
UnprocessableEntity = 422,
3248-
// (undocumented)
3249-
UnsupportedMediaType = 415,
3250-
// (undocumented)
3251-
Unused = 306,
3252-
// (undocumented)
3253-
UpgradeRequired = 426,
3254-
// (undocumented)
3255-
UriTooLong = 414,
3256-
// (undocumented)
3257-
UseProxy = 305,
3258-
// (undocumented)
3259-
VariantAlsoNegotiates = 506
3260-
}
3133+
export const HttpStatusCode: {
3134+
readonly Continue: 100;
3135+
readonly SwitchingProtocols: 101;
3136+
readonly Processing: 102;
3137+
readonly EarlyHints: 103;
3138+
readonly Ok: 200;
3139+
readonly Created: 201;
3140+
readonly Accepted: 202;
3141+
readonly NonAuthoritativeInformation: 203;
3142+
readonly NoContent: 204;
3143+
readonly ResetContent: 205;
3144+
readonly PartialContent: 206;
3145+
readonly MultiStatus: 207;
3146+
readonly AlreadyReported: 208;
3147+
readonly ImUsed: 226;
3148+
readonly MultipleChoices: 300;
3149+
readonly MovedPermanently: 301;
3150+
readonly Found: 302;
3151+
readonly SeeOther: 303;
3152+
readonly NotModified: 304;
3153+
readonly UseProxy: 305;
3154+
readonly TemporaryRedirect: 307;
3155+
readonly PermanentRedirect: 308;
3156+
readonly BadRequest: 400;
3157+
readonly Unauthorized: 401;
3158+
readonly PaymentRequired: 402;
3159+
readonly Forbidden: 403;
3160+
readonly NotFound: 404;
3161+
readonly MethodNotAllowed: 405;
3162+
readonly NotAcceptable: 406;
3163+
readonly ProxyAuthenticationRequired: 407;
3164+
readonly RequestTimeout: 408;
3165+
readonly Conflict: 409;
3166+
readonly Gone: 410;
3167+
readonly LengthRequired: 411;
3168+
readonly PreconditionFailed: 412;
3169+
readonly PayloadTooLarge: 413;
3170+
readonly UriTooLong: 414;
3171+
readonly UnsupportedMediaType: 415;
3172+
readonly RangeNotSatisfiable: 416;
3173+
readonly ExpectationFailed: 417;
3174+
readonly ImATeapot: 418;
3175+
readonly MisdirectedRequest: 421;
3176+
readonly UnprocessableEntity: 422;
3177+
readonly Locked: 423;
3178+
readonly FailedDependency: 424;
3179+
readonly TooEarly: 425;
3180+
readonly UpgradeRequired: 426;
3181+
readonly PreconditionRequired: 428;
3182+
readonly TooManyRequests: 429;
3183+
readonly RequestHeaderFieldsTooLarge: 431;
3184+
readonly UnavailableForLegalReasons: 451;
3185+
readonly InternalServerError: 500;
3186+
readonly NotImplemented: 501;
3187+
readonly BadGateway: 502;
3188+
readonly ServiceUnavailable: 503;
3189+
readonly GatewayTimeout: 504;
3190+
readonly HttpVersionNotSupported: 505;
3191+
readonly VariantAlsoNegotiates: 506;
3192+
readonly InsufficientStorage: 507;
3193+
readonly LoopDetected: 508;
3194+
readonly NotExtended: 510;
3195+
readonly NetworkAuthenticationRequired: 511;
3196+
};
32613197

32623198
// @public
32633199
export type HttpTransferCacheOptions = {

packages/common/http/src/response.ts

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -446,73 +446,71 @@ export const HTTP_STATUS_CODE_NO_CONTENT = 204;
446446
* Http status codes.
447447
* As per https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
448448
* @publicApi
449+
* @object-literal-as-enum
449450
*/
450-
export enum HttpStatusCode {
451-
Continue = 100,
452-
SwitchingProtocols = 101,
453-
Processing = 102,
454-
EarlyHints = 103,
455-
456-
Ok = HTTP_STATUS_CODE_OK,
457-
Created = 201,
458-
Accepted = 202,
459-
NonAuthoritativeInformation = 203,
460-
NoContent = HTTP_STATUS_CODE_NO_CONTENT,
461-
ResetContent = 205,
462-
PartialContent = 206,
463-
MultiStatus = 207,
464-
AlreadyReported = 208,
465-
ImUsed = 226,
466-
467-
MultipleChoices = 300,
468-
MovedPermanently = 301,
469-
Found = 302,
470-
SeeOther = 303,
471-
NotModified = 304,
472-
UseProxy = 305,
473-
Unused = 306,
474-
TemporaryRedirect = 307,
475-
PermanentRedirect = 308,
476-
477-
BadRequest = 400,
478-
Unauthorized = 401,
479-
PaymentRequired = 402,
480-
Forbidden = 403,
481-
NotFound = 404,
482-
MethodNotAllowed = 405,
483-
NotAcceptable = 406,
484-
ProxyAuthenticationRequired = 407,
485-
RequestTimeout = 408,
486-
Conflict = 409,
487-
Gone = 410,
488-
LengthRequired = 411,
489-
PreconditionFailed = 412,
490-
PayloadTooLarge = 413,
491-
UriTooLong = 414,
492-
UnsupportedMediaType = 415,
493-
RangeNotSatisfiable = 416,
494-
ExpectationFailed = 417,
495-
ImATeapot = 418,
496-
MisdirectedRequest = 421,
497-
UnprocessableEntity = 422,
498-
Locked = 423,
499-
FailedDependency = 424,
500-
TooEarly = 425,
501-
UpgradeRequired = 426,
502-
PreconditionRequired = 428,
503-
TooManyRequests = 429,
504-
RequestHeaderFieldsTooLarge = 431,
505-
UnavailableForLegalReasons = 451,
506-
507-
InternalServerError = 500,
508-
NotImplemented = 501,
509-
BadGateway = 502,
510-
ServiceUnavailable = 503,
511-
GatewayTimeout = 504,
512-
HttpVersionNotSupported = 505,
513-
VariantAlsoNegotiates = 506,
514-
InsufficientStorage = 507,
515-
LoopDetected = 508,
516-
NotExtended = 510,
517-
NetworkAuthenticationRequired = 511,
518-
}
451+
export const HttpStatusCode = {
452+
Continue: 100,
453+
SwitchingProtocols: 101,
454+
Processing: 102,
455+
EarlyHints: 103,
456+
Ok: HTTP_STATUS_CODE_OK,
457+
Created: 201,
458+
Accepted: 202,
459+
NonAuthoritativeInformation: 203,
460+
NoContent: HTTP_STATUS_CODE_NO_CONTENT,
461+
ResetContent: 205,
462+
PartialContent: 206,
463+
MultiStatus: 207,
464+
AlreadyReported: 208,
465+
ImUsed: 226,
466+
MultipleChoices: 300,
467+
MovedPermanently: 301,
468+
Found: 302,
469+
SeeOther: 303,
470+
NotModified: 304,
471+
UseProxy: 305,
472+
TemporaryRedirect: 307,
473+
PermanentRedirect: 308,
474+
BadRequest: 400,
475+
Unauthorized: 401,
476+
PaymentRequired: 402,
477+
Forbidden: 403,
478+
NotFound: 404,
479+
MethodNotAllowed: 405,
480+
NotAcceptable: 406,
481+
ProxyAuthenticationRequired: 407,
482+
RequestTimeout: 408,
483+
Conflict: 409,
484+
Gone: 410,
485+
LengthRequired: 411,
486+
PreconditionFailed: 412,
487+
PayloadTooLarge: 413,
488+
UriTooLong: 414,
489+
UnsupportedMediaType: 415,
490+
RangeNotSatisfiable: 416,
491+
ExpectationFailed: 417,
492+
ImATeapot: 418,
493+
MisdirectedRequest: 421,
494+
UnprocessableEntity: 422,
495+
Locked: 423,
496+
FailedDependency: 424,
497+
TooEarly: 425,
498+
UpgradeRequired: 426,
499+
PreconditionRequired: 428,
500+
TooManyRequests: 429,
501+
RequestHeaderFieldsTooLarge: 431,
502+
UnavailableForLegalReasons: 451,
503+
InternalServerError: 500,
504+
NotImplemented: 501,
505+
BadGateway: 502,
506+
ServiceUnavailable: 503,
507+
GatewayTimeout: 504,
508+
HttpVersionNotSupported: 505,
509+
VariantAlsoNegotiates: 506,
510+
InsufficientStorage: 507,
511+
LoopDetected: 508,
512+
NotExtended: 510,
513+
NetworkAuthenticationRequired: 511,
514+
} as const;
515+
516+
export type HttpStatusCodeType = (typeof HttpStatusCode)[keyof typeof HttpStatusCode];

0 commit comments

Comments
 (0)