@adonisjs/http-server 7.0.3 → 7.2.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,11 +2506,21 @@ 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
  }
2444
2513
  }
2514
+ /**
2515
+ * Listen for the event the response is written
2516
+ * to the TCP socket.
2517
+ *
2518
+ * Under the hood the callback is registered with
2519
+ * the "https://github.com/jshttp/on-finished" package
2520
+ */
2521
+ onFinish(callback) {
2522
+ onFinished(this.response, callback);
2523
+ }
2445
2524
  /**
2446
2525
  * Writes headers with the Node.js res object using the
2447
2526
  * response.setHeader method
@@ -2634,7 +2713,7 @@ var Response = class extends Macroable6 {
2634
2713
  return false;
2635
2714
  }
2636
2715
  const status = this.response.statusCode;
2637
- if (status >= 200 && status < 300 || status === 304) {
2716
+ if (status >= ResponseStatus.Ok && status < ResponseStatus.MultipleChoices || status === ResponseStatus.NotModified) {
2638
2717
  return fresh2(this.request.headers, this.#headers);
2639
2718
  }
2640
2719
  return false;
@@ -2761,7 +2840,7 @@ var Response = class extends Macroable6 {
2761
2840
  this.header("Location", url);
2762
2841
  return this;
2763
2842
  }
2764
- redirect(path, forwardQueryString = false, statusCode = 302) {
2843
+ redirect(path, forwardQueryString = false, statusCode = ResponseStatus.Found) {
2765
2844
  const handler = new Redirect(this.request, this, this.#router, this.#qs);
2766
2845
  if (forwardQueryString) {
2767
2846
  handler.withQs();
@@ -2779,7 +2858,7 @@ var Response = class extends Macroable6 {
2779
2858
  * used when status is not defined
2780
2859
  */
2781
2860
  abort(body, status) {
2782
- throw E_HTTP_REQUEST_ABORTED.invoke(body, status || 400);
2861
+ throw E_HTTP_REQUEST_ABORTED.invoke(body, status || ResponseStatus.BadRequest);
2783
2862
  }
2784
2863
  /**
2785
2864
  * Abort the request with custom body and a status code when
@@ -2877,294 +2956,294 @@ var Response = class extends Macroable6 {
2877
2956
  * Shorthand method to finish request with "100" status code
2878
2957
  */
2879
2958
  continue() {
2880
- this.status(100);
2959
+ this.status(ResponseStatus.Continue);
2881
2960
  return this.send(null, false);
2882
2961
  }
2883
2962
  /**
2884
2963
  * Shorthand method to finish request with "101" status code
2885
2964
  */
2886
2965
  switchingProtocols() {
2887
- this.status(101);
2966
+ this.status(ResponseStatus.SwitchingProtocols);
2888
2967
  return this.send(null, false);
2889
2968
  }
2890
2969
  /**
2891
2970
  * Shorthand method to finish request with "200" status code
2892
2971
  */
2893
2972
  ok(body, generateEtag) {
2894
- this.status(200);
2973
+ this.status(ResponseStatus.Ok);
2895
2974
  return this.send(body, generateEtag);
2896
2975
  }
2897
2976
  /**
2898
2977
  * Shorthand method to finish request with "201" status code
2899
2978
  */
2900
2979
  created(body, generateEtag) {
2901
- this.status(201);
2980
+ this.status(ResponseStatus.Created);
2902
2981
  return this.send(body, generateEtag);
2903
2982
  }
2904
2983
  /**
2905
2984
  * Shorthand method to finish request with "202" status code
2906
2985
  */
2907
2986
  accepted(body, generateEtag) {
2908
- this.status(202);
2987
+ this.status(ResponseStatus.Accepted);
2909
2988
  return this.send(body, generateEtag);
2910
2989
  }
2911
2990
  /**
2912
2991
  * Shorthand method to finish request with "203" status code
2913
2992
  */
2914
2993
  nonAuthoritativeInformation(body, generateEtag) {
2915
- this.status(203);
2994
+ this.status(ResponseStatus.NonAuthoritativeInformation);
2916
2995
  return this.send(body, generateEtag);
2917
2996
  }
2918
2997
  /**
2919
2998
  * Shorthand method to finish request with "204" status code
2920
2999
  */
2921
3000
  noContent() {
2922
- this.status(204);
3001
+ this.status(ResponseStatus.NoContent);
2923
3002
  return this.send(null, false);
2924
3003
  }
2925
3004
  /**
2926
3005
  * Shorthand method to finish request with "205" status code
2927
3006
  */
2928
3007
  resetContent() {
2929
- this.status(205);
3008
+ this.status(ResponseStatus.ResetContent);
2930
3009
  return this.send(null, false);
2931
3010
  }
2932
3011
  /**
2933
3012
  * Shorthand method to finish request with "206" status code
2934
3013
  */
2935
3014
  partialContent(body, generateEtag) {
2936
- this.status(206);
3015
+ this.status(ResponseStatus.PartialContent);
2937
3016
  return this.send(body, generateEtag);
2938
3017
  }
2939
3018
  /**
2940
3019
  * Shorthand method to finish request with "300" status code
2941
3020
  */
2942
3021
  multipleChoices(body, generateEtag) {
2943
- this.status(300);
3022
+ this.status(ResponseStatus.MultipleChoices);
2944
3023
  return this.send(body, generateEtag);
2945
3024
  }
2946
3025
  /**
2947
3026
  * Shorthand method to finish request with "301" status code
2948
3027
  */
2949
3028
  movedPermanently(body, generateEtag) {
2950
- this.status(301);
3029
+ this.status(ResponseStatus.MovedPermanently);
2951
3030
  return this.send(body, generateEtag);
2952
3031
  }
2953
3032
  /**
2954
3033
  * Shorthand method to finish request with "302" status code
2955
3034
  */
2956
3035
  movedTemporarily(body, generateEtag) {
2957
- this.status(302);
3036
+ this.status(ResponseStatus.Found);
2958
3037
  return this.send(body, generateEtag);
2959
3038
  }
2960
3039
  /**
2961
3040
  * Shorthand method to finish request with "303" status code
2962
3041
  */
2963
3042
  seeOther(body, generateEtag) {
2964
- this.status(303);
3043
+ this.status(ResponseStatus.SeeOther);
2965
3044
  return this.send(body, generateEtag);
2966
3045
  }
2967
3046
  /**
2968
3047
  * Shorthand method to finish request with "304" status code
2969
3048
  */
2970
3049
  notModified(body, generateEtag) {
2971
- this.status(304);
3050
+ this.status(ResponseStatus.NotModified);
2972
3051
  return this.send(body, generateEtag);
2973
3052
  }
2974
3053
  /**
2975
3054
  * Shorthand method to finish request with "305" status code
2976
3055
  */
2977
3056
  useProxy(body, generateEtag) {
2978
- this.status(305);
3057
+ this.status(ResponseStatus.UseProxy);
2979
3058
  return this.send(body, generateEtag);
2980
3059
  }
2981
3060
  /**
2982
3061
  * Shorthand method to finish request with "307" status code
2983
3062
  */
2984
3063
  temporaryRedirect(body, generateEtag) {
2985
- this.status(307);
3064
+ this.status(ResponseStatus.TemporaryRedirect);
2986
3065
  return this.send(body, generateEtag);
2987
3066
  }
2988
3067
  /**
2989
3068
  * Shorthand method to finish request with "400" status code
2990
3069
  */
2991
3070
  badRequest(body, generateEtag) {
2992
- this.status(400);
3071
+ this.status(ResponseStatus.BadRequest);
2993
3072
  return this.send(body, generateEtag);
2994
3073
  }
2995
3074
  /**
2996
3075
  * Shorthand method to finish request with "401" status code
2997
3076
  */
2998
3077
  unauthorized(body, generateEtag) {
2999
- this.status(401);
3078
+ this.status(ResponseStatus.Unauthorized);
3000
3079
  return this.send(body, generateEtag);
3001
3080
  }
3002
3081
  /**
3003
3082
  * Shorthand method to finish request with "402" status code
3004
3083
  */
3005
3084
  paymentRequired(body, generateEtag) {
3006
- this.status(402);
3085
+ this.status(ResponseStatus.PaymentRequired);
3007
3086
  return this.send(body, generateEtag);
3008
3087
  }
3009
3088
  /**
3010
3089
  * Shorthand method to finish request with "403" status code
3011
3090
  */
3012
3091
  forbidden(body, generateEtag) {
3013
- this.status(403);
3092
+ this.status(ResponseStatus.Forbidden);
3014
3093
  return this.send(body, generateEtag);
3015
3094
  }
3016
3095
  /**
3017
3096
  * Shorthand method to finish request with "404" status code
3018
3097
  */
3019
3098
  notFound(body, generateEtag) {
3020
- this.status(404);
3099
+ this.status(ResponseStatus.NotFound);
3021
3100
  return this.send(body, generateEtag);
3022
3101
  }
3023
3102
  /**
3024
3103
  * Shorthand method to finish request with "405" status code
3025
3104
  */
3026
3105
  methodNotAllowed(body, generateEtag) {
3027
- this.status(405);
3106
+ this.status(ResponseStatus.MethodNotAllowed);
3028
3107
  return this.send(body, generateEtag);
3029
3108
  }
3030
3109
  /**
3031
3110
  * Shorthand method to finish request with "406" status code
3032
3111
  */
3033
3112
  notAcceptable(body, generateEtag) {
3034
- this.status(406);
3113
+ this.status(ResponseStatus.NotAcceptable);
3035
3114
  return this.send(body, generateEtag);
3036
3115
  }
3037
3116
  /**
3038
3117
  * Shorthand method to finish request with "407" status code
3039
3118
  */
3040
3119
  proxyAuthenticationRequired(body, generateEtag) {
3041
- this.status(407);
3120
+ this.status(ResponseStatus.ProxyAuthenticationRequired);
3042
3121
  return this.send(body, generateEtag);
3043
3122
  }
3044
3123
  /**
3045
3124
  * Shorthand method to finish request with "408" status code
3046
3125
  */
3047
3126
  requestTimeout(body, generateEtag) {
3048
- this.status(408);
3127
+ this.status(ResponseStatus.RequestTimeout);
3049
3128
  return this.send(body, generateEtag);
3050
3129
  }
3051
3130
  /**
3052
3131
  * Shorthand method to finish request with "409" status code
3053
3132
  */
3054
3133
  conflict(body, generateEtag) {
3055
- this.status(409);
3134
+ this.status(ResponseStatus.Conflict);
3056
3135
  return this.send(body, generateEtag);
3057
3136
  }
3058
3137
  /**
3059
3138
  * Shorthand method to finish request with "401" status code
3060
3139
  */
3061
3140
  gone(body, generateEtag) {
3062
- this.status(410);
3141
+ this.status(ResponseStatus.Gone);
3063
3142
  return this.send(body, generateEtag);
3064
3143
  }
3065
3144
  /**
3066
3145
  * Shorthand method to finish request with "411" status code
3067
3146
  */
3068
3147
  lengthRequired(body, generateEtag) {
3069
- this.status(411);
3148
+ this.status(ResponseStatus.LengthRequired);
3070
3149
  return this.send(body, generateEtag);
3071
3150
  }
3072
3151
  /**
3073
3152
  * Shorthand method to finish request with "412" status code
3074
3153
  */
3075
3154
  preconditionFailed(body, generateEtag) {
3076
- this.status(412);
3155
+ this.status(ResponseStatus.PreconditionFailed);
3077
3156
  return this.send(body, generateEtag);
3078
3157
  }
3079
3158
  /**
3080
3159
  * Shorthand method to finish request with "413" status code
3081
3160
  */
3082
3161
  requestEntityTooLarge(body, generateEtag) {
3083
- this.status(413);
3162
+ this.status(ResponseStatus.PayloadTooLarge);
3084
3163
  return this.send(body, generateEtag);
3085
3164
  }
3086
3165
  /**
3087
3166
  * Shorthand method to finish request with "414" status code
3088
3167
  */
3089
3168
  requestUriTooLong(body, generateEtag) {
3090
- this.status(414);
3169
+ this.status(ResponseStatus.URITooLong);
3091
3170
  return this.send(body, generateEtag);
3092
3171
  }
3093
3172
  /**
3094
3173
  * Shorthand method to finish request with "415" status code
3095
3174
  */
3096
3175
  unsupportedMediaType(body, generateEtag) {
3097
- this.status(415);
3176
+ this.status(ResponseStatus.UnsupportedMediaType);
3098
3177
  return this.send(body, generateEtag);
3099
3178
  }
3100
3179
  /**
3101
3180
  * Shorthand method to finish request with "416" status code
3102
3181
  */
3103
3182
  requestedRangeNotSatisfiable(body, generateEtag) {
3104
- this.status(416);
3183
+ this.status(ResponseStatus.RangeNotSatisfiable);
3105
3184
  return this.send(body, generateEtag);
3106
3185
  }
3107
3186
  /**
3108
3187
  * Shorthand method to finish request with "417" status code
3109
3188
  */
3110
3189
  expectationFailed(body, generateEtag) {
3111
- this.status(417);
3190
+ this.status(ResponseStatus.ExpectationFailed);
3112
3191
  return this.send(body, generateEtag);
3113
3192
  }
3114
3193
  /**
3115
3194
  * Shorthand method to finish request with "422" status code
3116
3195
  */
3117
3196
  unprocessableEntity(body, generateEtag) {
3118
- this.status(422);
3197
+ this.status(ResponseStatus.UnprocessableEntity);
3119
3198
  return this.send(body, generateEtag);
3120
3199
  }
3121
3200
  /**
3122
3201
  * Shorthand method to finish request with "429" status code
3123
3202
  */
3124
3203
  tooManyRequests(body, generateEtag) {
3125
- this.status(429);
3204
+ this.status(ResponseStatus.TooManyRequests);
3126
3205
  return this.send(body, generateEtag);
3127
3206
  }
3128
3207
  /**
3129
3208
  * Shorthand method to finish request with "500" status code
3130
3209
  */
3131
3210
  internalServerError(body, generateEtag) {
3132
- this.status(500);
3211
+ this.status(ResponseStatus.InternalServerError);
3133
3212
  return this.send(body, generateEtag);
3134
3213
  }
3135
3214
  /**
3136
3215
  * Shorthand method to finish request with "501" status code
3137
3216
  */
3138
3217
  notImplemented(body, generateEtag) {
3139
- this.status(501);
3218
+ this.status(ResponseStatus.NotImplemented);
3140
3219
  return this.send(body, generateEtag);
3141
3220
  }
3142
3221
  /**
3143
3222
  * Shorthand method to finish request with "502" status code
3144
3223
  */
3145
3224
  badGateway(body, generateEtag) {
3146
- this.status(502);
3225
+ this.status(ResponseStatus.BadGateway);
3147
3226
  return this.send(body, generateEtag);
3148
3227
  }
3149
3228
  /**
3150
3229
  * Shorthand method to finish request with "503" status code
3151
3230
  */
3152
3231
  serviceUnavailable(body, generateEtag) {
3153
- this.status(503);
3232
+ this.status(ResponseStatus.ServiceUnavailable);
3154
3233
  return this.send(body, generateEtag);
3155
3234
  }
3156
3235
  /**
3157
3236
  * Shorthand method to finish request with "504" status code
3158
3237
  */
3159
3238
  gatewayTimeout(body, generateEtag) {
3160
- this.status(504);
3239
+ this.status(ResponseStatus.GatewayTimeout);
3161
3240
  return this.send(body, generateEtag);
3162
3241
  }
3163
3242
  /**
3164
3243
  * Shorthand method to finish request with "505" status code
3165
3244
  */
3166
3245
  httpVersionNotSupported(body, generateEtag) {
3167
- this.status(505);
3246
+ this.status(ResponseStatus.HTTPVersionNotSupported);
3168
3247
  return this.send(body, generateEtag);
3169
3248
  }
3170
3249
  };
@@ -4435,6 +4514,7 @@ export {
4435
4514
  E_HTTP_EXCEPTION,
4436
4515
  E_HTTP_REQUEST_ABORTED,
4437
4516
  exceptions_exports,
4517
+ ResponseStatus,
4438
4518
  Response,
4439
4519
  Qs,
4440
4520
  Router,
@@ -4442,4 +4522,4 @@ export {
4442
4522
  Server,
4443
4523
  defineConfig
4444
4524
  };
4445
- //# sourceMappingURL=chunk-KYYKTJYU.js.map
4525
+ //# sourceMappingURL=chunk-MUS67JY5.js.map