feat(http): implements doublelinked list for middlewares
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
enum HttpMethods {
|
||||
head('HEAD'),
|
||||
get('GET'),
|
||||
post('POST'),
|
||||
put('PUT'),
|
||||
patch('PATCH'),
|
||||
delete('DELETE');
|
||||
|
||||
final String method;
|
||||
|
||||
const HttpMethods(this.method);
|
||||
}
|
||||
@@ -1,83 +1,123 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// Status codes for HTTP responses. Extracted from dart:io
|
||||
abstract class HttpStatus {
|
||||
static const int continue_ = 100;
|
||||
static const int switchingProtocols = 101;
|
||||
static const int processing = 102;
|
||||
static const int ok = 200;
|
||||
static const int created = 201;
|
||||
static const int accepted = 202;
|
||||
static const int nonAuthoritativeInformation = 203;
|
||||
static const int noContent = 204;
|
||||
static const int resetContent = 205;
|
||||
static const int partialContent = 206;
|
||||
static const int multiStatus = 207;
|
||||
static const int alreadyReported = 208;
|
||||
static const int imUsed = 226;
|
||||
static const int multipleChoices = 300;
|
||||
static const int movedPermanently = 301;
|
||||
static const int found = 302;
|
||||
static const int movedTemporarily = 302; // Common alias for found.
|
||||
static const int seeOther = 303;
|
||||
static const int notModified = 304;
|
||||
static const int useProxy = 305;
|
||||
static const int temporaryRedirect = 307;
|
||||
static const int permanentRedirect = 308;
|
||||
static const int badRequest = 400;
|
||||
static const int unauthorized = 401;
|
||||
static const int paymentRequired = 402;
|
||||
static const int forbidden = 403;
|
||||
static const int notFound = 404;
|
||||
static const int methodNotAllowed = 405;
|
||||
static const int notAcceptable = 406;
|
||||
static const int proxyAuthenticationRequired = 407;
|
||||
static const int requestTimeout = 408;
|
||||
static const int conflict = 409;
|
||||
static const int gone = 410;
|
||||
static const int lengthRequired = 411;
|
||||
static const int preconditionFailed = 412;
|
||||
static const int requestEntityTooLarge = 413;
|
||||
static const int requestUriTooLong = 414;
|
||||
static const int unsupportedMediaType = 415;
|
||||
static const int requestedRangeNotSatisfiable = 416;
|
||||
static const int expectationFailed = 417;
|
||||
static const int misdirectedRequest = 421;
|
||||
static const int unprocessableEntity = 422;
|
||||
static const int locked = 423;
|
||||
static const int failedDependency = 424;
|
||||
static const int upgradeRequired = 426;
|
||||
static const int preconditionRequired = 428;
|
||||
static const int tooManyRequests = 429;
|
||||
static const int requestHeaderFieldsTooLarge = 431;
|
||||
static const int connectionClosedWithoutResponse = 444;
|
||||
static const int unavailableForLegalReasons = 451;
|
||||
static const int clientClosedRequest = 499;
|
||||
static const int internalServerError = 500;
|
||||
static const int notImplemented = 501;
|
||||
static const int badGateway = 502;
|
||||
static const int serviceUnavailable = 503;
|
||||
static const int gatewayTimeout = 504;
|
||||
static const int httpVersionNotSupported = 505;
|
||||
static const int variantAlsoNegotiates = 506;
|
||||
static const int insufficientStorage = 507;
|
||||
static const int loopDetected = 508;
|
||||
static const int notExtended = 510;
|
||||
static const int networkAuthenticationRequired = 511;
|
||||
enum HttpStatus {
|
||||
continue_(100),
|
||||
switchingProtocols(101),
|
||||
processing(102),
|
||||
ok(200),
|
||||
created(201),
|
||||
accepted(202),
|
||||
nonAuthoritativeInformation(203),
|
||||
noContent(204),
|
||||
resetContent(205),
|
||||
partialContent(206),
|
||||
multiStatus(207),
|
||||
alreadyReported(208),
|
||||
imUsed(226),
|
||||
multipleChoices(300),
|
||||
movedPermanently(301),
|
||||
found(302),
|
||||
movedTemporarily(302), // Common alias for found.
|
||||
seeOther(303),
|
||||
notModified(304),
|
||||
useProxy(305),
|
||||
temporaryRedirect(307),
|
||||
permanentRedirect(308),
|
||||
badRequest(400),
|
||||
unauthorized(401),
|
||||
paymentRequired(402),
|
||||
forbidden(403),
|
||||
notFound(404),
|
||||
methodNotAllowed(405),
|
||||
notAcceptable(406),
|
||||
proxyAuthenticationRequired(407),
|
||||
requestTimeout(408),
|
||||
conflict(409),
|
||||
gone(410),
|
||||
lengthRequired(411),
|
||||
preconditionFailed(412),
|
||||
requestEntityTooLarge(413),
|
||||
requestUriTooLong(414),
|
||||
unsupportedMediaType(415),
|
||||
requestedRangeNotSatisfiable(416),
|
||||
expectationFailed(417),
|
||||
misdirectedRequest(421),
|
||||
unprocessableEntity(422),
|
||||
locked(423),
|
||||
failedDependency(424),
|
||||
upgradeRequired(426),
|
||||
preconditionRequired(428),
|
||||
tooManyRequests(429),
|
||||
requestHeaderFieldsTooLarge(431),
|
||||
connectionClosedWithoutResponse(444),
|
||||
unavailableForLegalReasons(451),
|
||||
clientClosedRequest(499),
|
||||
internalServerError(500),
|
||||
notImplemented(501),
|
||||
badGateway(502),
|
||||
serviceUnavailable(503),
|
||||
gatewayTimeout(504),
|
||||
httpVersionNotSupported(505),
|
||||
variantAlsoNegotiates(506),
|
||||
insufficientStorage(507),
|
||||
loopDetected(508),
|
||||
notExtended(510),
|
||||
networkAuthenticationRequired(511),
|
||||
// Client generated status code.
|
||||
static const int networkConnectTimeoutError = 599;
|
||||
networkConnectTimeoutError(599);
|
||||
|
||||
final int statusCode;
|
||||
|
||||
const HttpStatus(this.statusCode);
|
||||
|
||||
bool equals(Object other) {
|
||||
if (other is HttpStatus) {
|
||||
return statusCode == other.statusCode;
|
||||
}
|
||||
if (other is int) {
|
||||
return statusCode == other;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isInfo() {
|
||||
return statusCode >= 100 && statusCode < 200;
|
||||
}
|
||||
|
||||
bool isSuccess() {
|
||||
return statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
|
||||
bool isRedirection() {
|
||||
return statusCode >= 300 && statusCode < 400;
|
||||
}
|
||||
|
||||
bool isClientError() {
|
||||
return statusCode >= 400 && statusCode < 500;
|
||||
}
|
||||
|
||||
bool isServerError() {
|
||||
return statusCode >= 500 && statusCode < 600;
|
||||
}
|
||||
|
||||
factory HttpStatus.from(int status) {
|
||||
return HttpStatus.values
|
||||
.firstWhere((element) => element.statusCode == status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user