@adonisjs/http-server 7.0.3 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2050,6 +2050,72 @@ var E_HTTP_REQUEST_ABORTED = class AbortException extends E_HTTP_EXCEPTION {
2050
2050
  }
2051
2051
  };
2052
2052
 
2053
+ // src/response_status.ts
2054
+ var ResponseStatus = {
2055
+ Continue: 100,
2056
+ SwitchingProtocols: 101,
2057
+ Processing: 102,
2058
+ EarlyHints: 103,
2059
+ Ok: 200,
2060
+ Created: 201,
2061
+ Accepted: 202,
2062
+ NonAuthoritativeInformation: 203,
2063
+ NoContent: 204,
2064
+ ResetContent: 205,
2065
+ PartialContent: 206,
2066
+ MultiStatus: 207,
2067
+ AlreadyReported: 208,
2068
+ IMUsed: 226,
2069
+ MultipleChoices: 300,
2070
+ MovedPermanently: 301,
2071
+ Found: 302,
2072
+ SeeOther: 303,
2073
+ NotModified: 304,
2074
+ UseProxy: 305,
2075
+ TemporaryRedirect: 307,
2076
+ PermanentRedirect: 308,
2077
+ BadRequest: 400,
2078
+ Unauthorized: 401,
2079
+ PaymentRequired: 402,
2080
+ Forbidden: 403,
2081
+ NotFound: 404,
2082
+ MethodNotAllowed: 405,
2083
+ NotAcceptable: 406,
2084
+ ProxyAuthenticationRequired: 407,
2085
+ RequestTimeout: 408,
2086
+ Conflict: 409,
2087
+ Gone: 410,
2088
+ LengthRequired: 411,
2089
+ PreconditionFailed: 412,
2090
+ PayloadTooLarge: 413,
2091
+ URITooLong: 414,
2092
+ UnsupportedMediaType: 415,
2093
+ RangeNotSatisfiable: 416,
2094
+ ExpectationFailed: 417,
2095
+ ImATeapot: 418,
2096
+ MisdirectedRequest: 421,
2097
+ UnprocessableEntity: 422,
2098
+ Locked: 423,
2099
+ FailedDependency: 424,
2100
+ TooEarly: 425,
2101
+ UpgradeRequired: 426,
2102
+ PreconditionRequired: 428,
2103
+ TooManyRequests: 429,
2104
+ RequestHeaderFieldsTooLarge: 431,
2105
+ UnavailableForLegalReasons: 451,
2106
+ InternalServerError: 500,
2107
+ NotImplemented: 501,
2108
+ BadGateway: 502,
2109
+ ServiceUnavailable: 503,
2110
+ GatewayTimeout: 504,
2111
+ HTTPVersionNotSupported: 505,
2112
+ VariantAlsoNegotiates: 506,
2113
+ InsufficientStorage: 507,
2114
+ LoopDetected: 508,
2115
+ NotExtended: 510,
2116
+ NetworkAuthenticationRequired: 511
2117
+ };
2118
+
2053
2119
  // src/response.ts
2054
2120
  import etag from "etag";
2055
2121
  import vary from "vary";
@@ -2303,7 +2369,7 @@ var Response = class extends Macroable6 {
2303
2369
  this.safeStatus(204);
2304
2370
  }
2305
2371
  const statusCode = this.response.statusCode;
2306
- if (statusCode && (statusCode < 200 || statusCode === 204 || statusCode === 304)) {
2372
+ if (statusCode && (statusCode < ResponseStatus.Ok || statusCode === ResponseStatus.NoContent || statusCode === ResponseStatus.NotModified)) {
2307
2373
  this.removeHeader("Content-Type");
2308
2374
  this.removeHeader("Content-Length");
2309
2375
  this.removeHeader("Transfer-Encoding");
@@ -2334,7 +2400,7 @@ var Response = class extends Macroable6 {
2334
2400
  this.removeHeader("Content-Type");
2335
2401
  this.removeHeader("Content-Length");
2336
2402
  this.removeHeader("Transfer-Encoding");
2337
- this.#endResponse(null, 304);
2403
+ this.#endResponse(null, ResponseStatus.NotModified);
2338
2404
  return;
2339
2405
  }
2340
2406
  this.header("Content-Length", Buffer.byteLength(content));
@@ -2383,7 +2449,7 @@ var Response = class extends Macroable6 {
2383
2449
  } else {
2384
2450
  this.#endResponse(
2385
2451
  error.code === "ENOENT" ? "File not found" : "Cannot process file",
2386
- error.code === "ENOENT" ? 404 : 500
2452
+ error.code === "ENOENT" ? ResponseStatus.NotFound : ResponseStatus.InternalServerError
2387
2453
  );
2388
2454
  }
2389
2455
  } else {
@@ -2420,11 +2486,14 @@ var Response = class extends Macroable6 {
2420
2486
  this.setEtag(stats, true);
2421
2487
  }
2422
2488
  if (this.request.method === "HEAD") {
2423
- this.#endResponse(null, generateEtag && this.fresh() ? 304 : 200);
2489
+ this.#endResponse(
2490
+ null,
2491
+ generateEtag && this.fresh() ? ResponseStatus.NotModified : ResponseStatus.Ok
2492
+ );
2424
2493
  return;
2425
2494
  }
2426
2495
  if (generateEtag && this.fresh()) {
2427
- this.#endResponse(null, 304);
2496
+ this.#endResponse(null, ResponseStatus.NotModified);
2428
2497
  return;
2429
2498
  }
2430
2499
  this.header("Content-length", stats.size);
@@ -2437,7 +2506,7 @@ var Response = class extends Macroable6 {
2437
2506
  } else {
2438
2507
  this.#endResponse(
2439
2508
  error.code === "ENOENT" ? "File not found" : "Cannot process file",
2440
- error.code === "ENOENT" ? 404 : 500
2509
+ error.code === "ENOENT" ? ResponseStatus.NotFound : ResponseStatus.InternalServerError
2441
2510
  );
2442
2511
  }
2443
2512
  }
@@ -2634,7 +2703,7 @@ var Response = class extends Macroable6 {
2634
2703
  return false;
2635
2704
  }
2636
2705
  const status = this.response.statusCode;
2637
- if (status >= 200 && status < 300 || status === 304) {
2706
+ if (status >= ResponseStatus.Ok && status < ResponseStatus.MultipleChoices || status === ResponseStatus.NotModified) {
2638
2707
  return fresh2(this.request.headers, this.#headers);
2639
2708
  }
2640
2709
  return false;
@@ -2761,7 +2830,7 @@ var Response = class extends Macroable6 {
2761
2830
  this.header("Location", url);
2762
2831
  return this;
2763
2832
  }
2764
- redirect(path, forwardQueryString = false, statusCode = 302) {
2833
+ redirect(path, forwardQueryString = false, statusCode = ResponseStatus.Found) {
2765
2834
  const handler = new Redirect(this.request, this, this.#router, this.#qs);
2766
2835
  if (forwardQueryString) {
2767
2836
  handler.withQs();
@@ -2779,7 +2848,7 @@ var Response = class extends Macroable6 {
2779
2848
  * used when status is not defined
2780
2849
  */
2781
2850
  abort(body, status) {
2782
- throw E_HTTP_REQUEST_ABORTED.invoke(body, status || 400);
2851
+ throw E_HTTP_REQUEST_ABORTED.invoke(body, status || ResponseStatus.BadRequest);
2783
2852
  }
2784
2853
  /**
2785
2854
  * Abort the request with custom body and a status code when
@@ -2877,294 +2946,294 @@ var Response = class extends Macroable6 {
2877
2946
  * Shorthand method to finish request with "100" status code
2878
2947
  */
2879
2948
  continue() {
2880
- this.status(100);
2949
+ this.status(ResponseStatus.Continue);
2881
2950
  return this.send(null, false);
2882
2951
  }
2883
2952
  /**
2884
2953
  * Shorthand method to finish request with "101" status code
2885
2954
  */
2886
2955
  switchingProtocols() {
2887
- this.status(101);
2956
+ this.status(ResponseStatus.SwitchingProtocols);
2888
2957
  return this.send(null, false);
2889
2958
  }
2890
2959
  /**
2891
2960
  * Shorthand method to finish request with "200" status code
2892
2961
  */
2893
2962
  ok(body, generateEtag) {
2894
- this.status(200);
2963
+ this.status(ResponseStatus.Ok);
2895
2964
  return this.send(body, generateEtag);
2896
2965
  }
2897
2966
  /**
2898
2967
  * Shorthand method to finish request with "201" status code
2899
2968
  */
2900
2969
  created(body, generateEtag) {
2901
- this.status(201);
2970
+ this.status(ResponseStatus.Created);
2902
2971
  return this.send(body, generateEtag);
2903
2972
  }
2904
2973
  /**
2905
2974
  * Shorthand method to finish request with "202" status code
2906
2975
  */
2907
2976
  accepted(body, generateEtag) {
2908
- this.status(202);
2977
+ this.status(ResponseStatus.Accepted);
2909
2978
  return this.send(body, generateEtag);
2910
2979
  }
2911
2980
  /**
2912
2981
  * Shorthand method to finish request with "203" status code
2913
2982
  */
2914
2983
  nonAuthoritativeInformation(body, generateEtag) {
2915
- this.status(203);
2984
+ this.status(ResponseStatus.NonAuthoritativeInformation);
2916
2985
  return this.send(body, generateEtag);
2917
2986
  }
2918
2987
  /**
2919
2988
  * Shorthand method to finish request with "204" status code
2920
2989
  */
2921
2990
  noContent() {
2922
- this.status(204);
2991
+ this.status(ResponseStatus.NoContent);
2923
2992
  return this.send(null, false);
2924
2993
  }
2925
2994
  /**
2926
2995
  * Shorthand method to finish request with "205" status code
2927
2996
  */
2928
2997
  resetContent() {
2929
- this.status(205);
2998
+ this.status(ResponseStatus.ResetContent);
2930
2999
  return this.send(null, false);
2931
3000
  }
2932
3001
  /**
2933
3002
  * Shorthand method to finish request with "206" status code
2934
3003
  */
2935
3004
  partialContent(body, generateEtag) {
2936
- this.status(206);
3005
+ this.status(ResponseStatus.PartialContent);
2937
3006
  return this.send(body, generateEtag);
2938
3007
  }
2939
3008
  /**
2940
3009
  * Shorthand method to finish request with "300" status code
2941
3010
  */
2942
3011
  multipleChoices(body, generateEtag) {
2943
- this.status(300);
3012
+ this.status(ResponseStatus.MultipleChoices);
2944
3013
  return this.send(body, generateEtag);
2945
3014
  }
2946
3015
  /**
2947
3016
  * Shorthand method to finish request with "301" status code
2948
3017
  */
2949
3018
  movedPermanently(body, generateEtag) {
2950
- this.status(301);
3019
+ this.status(ResponseStatus.MovedPermanently);
2951
3020
  return this.send(body, generateEtag);
2952
3021
  }
2953
3022
  /**
2954
3023
  * Shorthand method to finish request with "302" status code
2955
3024
  */
2956
3025
  movedTemporarily(body, generateEtag) {
2957
- this.status(302);
3026
+ this.status(ResponseStatus.Found);
2958
3027
  return this.send(body, generateEtag);
2959
3028
  }
2960
3029
  /**
2961
3030
  * Shorthand method to finish request with "303" status code
2962
3031
  */
2963
3032
  seeOther(body, generateEtag) {
2964
- this.status(303);
3033
+ this.status(ResponseStatus.SeeOther);
2965
3034
  return this.send(body, generateEtag);
2966
3035
  }
2967
3036
  /**
2968
3037
  * Shorthand method to finish request with "304" status code
2969
3038
  */
2970
3039
  notModified(body, generateEtag) {
2971
- this.status(304);
3040
+ this.status(ResponseStatus.NotModified);
2972
3041
  return this.send(body, generateEtag);
2973
3042
  }
2974
3043
  /**
2975
3044
  * Shorthand method to finish request with "305" status code
2976
3045
  */
2977
3046
  useProxy(body, generateEtag) {
2978
- this.status(305);
3047
+ this.status(ResponseStatus.UseProxy);
2979
3048
  return this.send(body, generateEtag);
2980
3049
  }
2981
3050
  /**
2982
3051
  * Shorthand method to finish request with "307" status code
2983
3052
  */
2984
3053
  temporaryRedirect(body, generateEtag) {
2985
- this.status(307);
3054
+ this.status(ResponseStatus.TemporaryRedirect);
2986
3055
  return this.send(body, generateEtag);
2987
3056
  }
2988
3057
  /**
2989
3058
  * Shorthand method to finish request with "400" status code
2990
3059
  */
2991
3060
  badRequest(body, generateEtag) {
2992
- this.status(400);
3061
+ this.status(ResponseStatus.BadRequest);
2993
3062
  return this.send(body, generateEtag);
2994
3063
  }
2995
3064
  /**
2996
3065
  * Shorthand method to finish request with "401" status code
2997
3066
  */
2998
3067
  unauthorized(body, generateEtag) {
2999
- this.status(401);
3068
+ this.status(ResponseStatus.Unauthorized);
3000
3069
  return this.send(body, generateEtag);
3001
3070
  }
3002
3071
  /**
3003
3072
  * Shorthand method to finish request with "402" status code
3004
3073
  */
3005
3074
  paymentRequired(body, generateEtag) {
3006
- this.status(402);
3075
+ this.status(ResponseStatus.PaymentRequired);
3007
3076
  return this.send(body, generateEtag);
3008
3077
  }
3009
3078
  /**
3010
3079
  * Shorthand method to finish request with "403" status code
3011
3080
  */
3012
3081
  forbidden(body, generateEtag) {
3013
- this.status(403);
3082
+ this.status(ResponseStatus.Forbidden);
3014
3083
  return this.send(body, generateEtag);
3015
3084
  }
3016
3085
  /**
3017
3086
  * Shorthand method to finish request with "404" status code
3018
3087
  */
3019
3088
  notFound(body, generateEtag) {
3020
- this.status(404);
3089
+ this.status(ResponseStatus.NotFound);
3021
3090
  return this.send(body, generateEtag);
3022
3091
  }
3023
3092
  /**
3024
3093
  * Shorthand method to finish request with "405" status code
3025
3094
  */
3026
3095
  methodNotAllowed(body, generateEtag) {
3027
- this.status(405);
3096
+ this.status(ResponseStatus.MethodNotAllowed);
3028
3097
  return this.send(body, generateEtag);
3029
3098
  }
3030
3099
  /**
3031
3100
  * Shorthand method to finish request with "406" status code
3032
3101
  */
3033
3102
  notAcceptable(body, generateEtag) {
3034
- this.status(406);
3103
+ this.status(ResponseStatus.NotAcceptable);
3035
3104
  return this.send(body, generateEtag);
3036
3105
  }
3037
3106
  /**
3038
3107
  * Shorthand method to finish request with "407" status code
3039
3108
  */
3040
3109
  proxyAuthenticationRequired(body, generateEtag) {
3041
- this.status(407);
3110
+ this.status(ResponseStatus.ProxyAuthenticationRequired);
3042
3111
  return this.send(body, generateEtag);
3043
3112
  }
3044
3113
  /**
3045
3114
  * Shorthand method to finish request with "408" status code
3046
3115
  */
3047
3116
  requestTimeout(body, generateEtag) {
3048
- this.status(408);
3117
+ this.status(ResponseStatus.RequestTimeout);
3049
3118
  return this.send(body, generateEtag);
3050
3119
  }
3051
3120
  /**
3052
3121
  * Shorthand method to finish request with "409" status code
3053
3122
  */
3054
3123
  conflict(body, generateEtag) {
3055
- this.status(409);
3124
+ this.status(ResponseStatus.Conflict);
3056
3125
  return this.send(body, generateEtag);
3057
3126
  }
3058
3127
  /**
3059
3128
  * Shorthand method to finish request with "401" status code
3060
3129
  */
3061
3130
  gone(body, generateEtag) {
3062
- this.status(410);
3131
+ this.status(ResponseStatus.Gone);
3063
3132
  return this.send(body, generateEtag);
3064
3133
  }
3065
3134
  /**
3066
3135
  * Shorthand method to finish request with "411" status code
3067
3136
  */
3068
3137
  lengthRequired(body, generateEtag) {
3069
- this.status(411);
3138
+ this.status(ResponseStatus.LengthRequired);
3070
3139
  return this.send(body, generateEtag);
3071
3140
  }
3072
3141
  /**
3073
3142
  * Shorthand method to finish request with "412" status code
3074
3143
  */
3075
3144
  preconditionFailed(body, generateEtag) {
3076
- this.status(412);
3145
+ this.status(ResponseStatus.PreconditionFailed);
3077
3146
  return this.send(body, generateEtag);
3078
3147
  }
3079
3148
  /**
3080
3149
  * Shorthand method to finish request with "413" status code
3081
3150
  */
3082
3151
  requestEntityTooLarge(body, generateEtag) {
3083
- this.status(413);
3152
+ this.status(ResponseStatus.PayloadTooLarge);
3084
3153
  return this.send(body, generateEtag);
3085
3154
  }
3086
3155
  /**
3087
3156
  * Shorthand method to finish request with "414" status code
3088
3157
  */
3089
3158
  requestUriTooLong(body, generateEtag) {
3090
- this.status(414);
3159
+ this.status(ResponseStatus.URITooLong);
3091
3160
  return this.send(body, generateEtag);
3092
3161
  }
3093
3162
  /**
3094
3163
  * Shorthand method to finish request with "415" status code
3095
3164
  */
3096
3165
  unsupportedMediaType(body, generateEtag) {
3097
- this.status(415);
3166
+ this.status(ResponseStatus.UnsupportedMediaType);
3098
3167
  return this.send(body, generateEtag);
3099
3168
  }
3100
3169
  /**
3101
3170
  * Shorthand method to finish request with "416" status code
3102
3171
  */
3103
3172
  requestedRangeNotSatisfiable(body, generateEtag) {
3104
- this.status(416);
3173
+ this.status(ResponseStatus.RangeNotSatisfiable);
3105
3174
  return this.send(body, generateEtag);
3106
3175
  }
3107
3176
  /**
3108
3177
  * Shorthand method to finish request with "417" status code
3109
3178
  */
3110
3179
  expectationFailed(body, generateEtag) {
3111
- this.status(417);
3180
+ this.status(ResponseStatus.ExpectationFailed);
3112
3181
  return this.send(body, generateEtag);
3113
3182
  }
3114
3183
  /**
3115
3184
  * Shorthand method to finish request with "422" status code
3116
3185
  */
3117
3186
  unprocessableEntity(body, generateEtag) {
3118
- this.status(422);
3187
+ this.status(ResponseStatus.UnprocessableEntity);
3119
3188
  return this.send(body, generateEtag);
3120
3189
  }
3121
3190
  /**
3122
3191
  * Shorthand method to finish request with "429" status code
3123
3192
  */
3124
3193
  tooManyRequests(body, generateEtag) {
3125
- this.status(429);
3194
+ this.status(ResponseStatus.TooManyRequests);
3126
3195
  return this.send(body, generateEtag);
3127
3196
  }
3128
3197
  /**
3129
3198
  * Shorthand method to finish request with "500" status code
3130
3199
  */
3131
3200
  internalServerError(body, generateEtag) {
3132
- this.status(500);
3201
+ this.status(ResponseStatus.InternalServerError);
3133
3202
  return this.send(body, generateEtag);
3134
3203
  }
3135
3204
  /**
3136
3205
  * Shorthand method to finish request with "501" status code
3137
3206
  */
3138
3207
  notImplemented(body, generateEtag) {
3139
- this.status(501);
3208
+ this.status(ResponseStatus.NotImplemented);
3140
3209
  return this.send(body, generateEtag);
3141
3210
  }
3142
3211
  /**
3143
3212
  * Shorthand method to finish request with "502" status code
3144
3213
  */
3145
3214
  badGateway(body, generateEtag) {
3146
- this.status(502);
3215
+ this.status(ResponseStatus.BadGateway);
3147
3216
  return this.send(body, generateEtag);
3148
3217
  }
3149
3218
  /**
3150
3219
  * Shorthand method to finish request with "503" status code
3151
3220
  */
3152
3221
  serviceUnavailable(body, generateEtag) {
3153
- this.status(503);
3222
+ this.status(ResponseStatus.ServiceUnavailable);
3154
3223
  return this.send(body, generateEtag);
3155
3224
  }
3156
3225
  /**
3157
3226
  * Shorthand method to finish request with "504" status code
3158
3227
  */
3159
3228
  gatewayTimeout(body, generateEtag) {
3160
- this.status(504);
3229
+ this.status(ResponseStatus.GatewayTimeout);
3161
3230
  return this.send(body, generateEtag);
3162
3231
  }
3163
3232
  /**
3164
3233
  * Shorthand method to finish request with "505" status code
3165
3234
  */
3166
3235
  httpVersionNotSupported(body, generateEtag) {
3167
- this.status(505);
3236
+ this.status(ResponseStatus.HTTPVersionNotSupported);
3168
3237
  return this.send(body, generateEtag);
3169
3238
  }
3170
3239
  };
@@ -4435,6 +4504,7 @@ export {
4435
4504
  E_HTTP_EXCEPTION,
4436
4505
  E_HTTP_REQUEST_ABORTED,
4437
4506
  exceptions_exports,
4507
+ ResponseStatus,
4438
4508
  Response,
4439
4509
  Qs,
4440
4510
  Router,
@@ -4442,4 +4512,4 @@ export {
4442
4512
  Server,
4443
4513
  defineConfig
4444
4514
  };
4445
- //# sourceMappingURL=chunk-KYYKTJYU.js.map
4515
+ //# sourceMappingURL=chunk-CLGQYYS7.js.map