From 9ea248973d61523e547bab337c29d30f86136848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 14 Sep 2021 09:51:56 +0200 Subject: [PATCH] Use `deprecated` to deprecate enum members in :http. Note that the deprecated enum members in vibe.data.bson/json cannot realistically be marked as deprecated, as that triggers thousands of deprecation warnings in Phobos when to!T is used together with Json.Type or Bson.Type. --- http/vibe/http/client.d | 2 +- http/vibe/http/common.d | 2 +- http/vibe/http/fileserver.d | 8 ++-- http/vibe/http/server.d | 48 +++++++-------------- http/vibe/http/status.d | 84 ++++++++++++++++++------------------- web/vibe/web/common.d | 14 +++---- 6 files changed, 69 insertions(+), 89 deletions(-) diff --git a/http/vibe/http/client.d b/http/vibe/http/client.d index df2175d11f..8d0bb2473b 100644 --- a/http/vibe/http/client.d +++ b/http/vibe/http/client.d @@ -510,7 +510,7 @@ final class HTTPClient { if (res.headers.get("Proxy-Authenticate", null) !is null){ res.dropBody(); - throw new HTTPStatusException(HTTPStatus.ProxyAuthenticationRequired, "Proxy Authentication Failed."); + throw new HTTPStatusException(HTTPStatus.proxyAuthenticationRequired, "Proxy Authentication Failed."); } } diff --git a/http/vibe/http/common.d b/http/vibe/http/common.d index 988a22ac9f..19cdd0e9c9 100644 --- a/http/vibe/http/common.d +++ b/http/vibe/http/common.d @@ -286,7 +286,7 @@ class HTTPResponse { HTTPVersion httpVersion = HTTPVersion.HTTP_1_1; /// The status code of the response, 200 by default - int statusCode = HTTPStatus.OK; + int statusCode = HTTPStatus.ok; /** The status phrase of the response diff --git a/http/vibe/http/fileserver.d b/http/vibe/http/fileserver.d index bfa59b8812..f6afad029f 100644 --- a/http/vibe/http/fileserver.d +++ b/http/vibe/http/fileserver.d @@ -282,14 +282,14 @@ private void sendFileImpl(scope HTTPServerRequest req, scope HTTPServerResponse // return if the file does not exist if (!existsFile(pathstr)){ if (settings.options & HTTPFileServerOption.failIfNotFound) - throw new HTTPStatusException(HTTPStatus.NotFound); + throw new HTTPStatusException(HTTPStatus.notFound); return; } FileInfo dirent; try dirent = getFileInfo(pathstr); catch(Exception){ - throw new HTTPStatusException(HTTPStatus.InternalServerError, "Failed to get information for the file due to a file system error."); + throw new HTTPStatusException(HTTPStatus.internalServerError, "Failed to get information for the file due to a file system error."); } if (dirent.isDirectory) { @@ -297,7 +297,7 @@ private void sendFileImpl(scope HTTPServerRequest req, scope HTTPServerResponse return sendFileImpl(req, res, path ~ "index.html", settings); logDebugV("Hit directory when serving files, ignoring: %s", pathstr); if (settings.options & HTTPFileServerOption.failIfNotFound) - throw new HTTPStatusException(HTTPStatus.NotFound); + throw new HTTPStatusException(HTTPStatus.notFound); return; } @@ -341,7 +341,7 @@ private void sendFileImpl(scope HTTPServerRequest req, scope HTTPServerResponse try dirent = getFileInfo(encodedFilepath); catch(Exception){ - throw new HTTPStatusException(HTTPStatus.InternalServerError, "Failed to get information for the file due to a file system error."); + throw new HTTPStatusException(HTTPStatus.internalServerError, "Failed to get information for the file due to a file system error."); } // encoded file must be younger than original else warn diff --git a/http/vibe/http/server.d b/http/vibe/http/server.d index 2bf8c39da5..784153b6e6 100644 --- a/http/vibe/http/server.d +++ b/http/vibe/http/server.d @@ -555,16 +555,6 @@ enum TestHTTPResponseMode { } -private enum HTTPServerOptionImpl { - none = 0, - errorStackTraces = 1<<7, - reusePort = 1<<8, - distribute = 1<<9, // deprecated - reuseAddress = 1<<10, - defaults = reuseAddress -} - -// TODO: Should be turned back into an enum once the deprecated symbols can be removed /** Specifies optional features of the HTTP server. @@ -574,8 +564,8 @@ private enum HTTPServerOptionImpl { will also drain the `HTTPServerRequest.bodyReader` stream whenever a request body with form or JSON data is encountered. */ -struct HTTPServerOption { - static enum none = HTTPServerOptionImpl.none; +enum HTTPServerOption { + none = 0, /** Enables stack traces (`HTTPServerErrorInfo.debugMessage`). Note that generating the stack traces are generally a costly @@ -584,28 +574,19 @@ struct HTTPServerOption { the application, such as function addresses, which can help an attacker to abuse possible security holes. */ - static enum errorStackTraces = HTTPServerOptionImpl.errorStackTraces; + errorStackTraces = 1<<7, /// Enable port reuse in `listenTCP()` - static enum reusePort = HTTPServerOptionImpl.reusePort; + reusePort = 1<<8, /// Enable address reuse in `listenTCP()` - static enum reuseAddress = HTTPServerOptionImpl.reuseAddress; - + reuseAddress = 1<<10, /** The default set of options. Includes all parsing options, as well as the `errorStackTraces` option if the code is compiled in debug mode. */ - static enum defaults = () { - HTTPServerOptionImpl ops = HTTPServerOptionImpl.defaults; - debug ops |= HTTPServerOptionImpl.errorStackTraces; - return ops; - } ().HTTPServerOption; - - deprecated("None has been renamed to none.") - static enum None = none; + defaults = () { auto ret = reuseAddress; debug ret |= errorStackTraces; return ret; } (), - HTTPServerOptionImpl x; - alias x this; + deprecated("None has been renamed to none.") None = none } @@ -655,7 +636,7 @@ final class HTTPServerSettings { load in case of invalid or unwanted requests (DoS). By default, HTTPServerOption.defaults is used. */ - HTTPServerOptionImpl options = HTTPServerOption.defaults; + HTTPServerOption options = HTTPServerOption.defaults; /** Time of a request after which the connection is closed with an error; not supported yet @@ -1504,7 +1485,7 @@ final class HTTPServerResponse : HTTPResponse { url = The URL to redirect to status = The HTTP redirect status (3xx) to send - by default this is $(D HTTPStatus.found) */ - void redirect(string url, int status = HTTPStatus.Found) + void redirect(string url, int status = HTTPStatus.found) @safe { // Disallow any characters that may influence the header parsing enforce(!url.representation.canFind!(ch => ch < 0x20), @@ -1515,7 +1496,7 @@ final class HTTPServerResponse : HTTPResponse { writeBody("redirecting..."); } /// ditto - void redirect(URL url, int status = HTTPStatus.Found) + void redirect(URL url, int status = HTTPStatus.found) @safe { redirect(url.toString(), status); } @@ -1551,7 +1532,7 @@ final class HTTPServerResponse : HTTPResponse { */ ConnectionStream switchProtocol(string protocol) @safe { - statusCode = HTTPStatus.SwitchingProtocols; + statusCode = HTTPStatus.switchingProtocols; if (protocol.length) headers["Upgrade"] = protocol; writeVoidBody(); m_requiresConnectionClose = true; @@ -1561,7 +1542,7 @@ final class HTTPServerResponse : HTTPResponse { /// ditto void switchProtocol(string protocol, scope void delegate(scope ConnectionStream) @safe del) @safe { - statusCode = HTTPStatus.SwitchingProtocols; + statusCode = HTTPStatus.switchingProtocols; if (protocol.length) headers["Upgrade"] = protocol; writeVoidBody(); m_requiresConnectionClose = true; @@ -2022,7 +2003,7 @@ private final class TimeoutHTTPInputStream : InputStream { @safe { auto curr = Clock.currStdTime(); auto diff = curr - m_timeref; - if (diff > m_timeleft) throw new HTTPStatusException(HTTPStatus.RequestTimeout); + if (diff > m_timeleft) throw new HTTPStatusException(HTTPStatus.requestTimeout); m_timeleft -= diff; m_timeref = curr; } @@ -2052,7 +2033,7 @@ private HTTPListener listenHTTPPlain(HTTPServerSettings settings, HTTPServerRequ import vibe.core.core : runWorkerTaskDist; import std.algorithm : canFind, find; - static TCPListener doListen(HTTPServerContext listen_info, bool dist, bool reusePort, bool reuseAddress, bool is_tls) + static TCPListener doListen(HTTPServerContext listen_info, bool reusePort, bool reuseAddress, bool is_tls) @safe { try { TCPListenOptions options = TCPListenOptions.defaults; @@ -2095,7 +2076,6 @@ private HTTPListener listenHTTPPlain(HTTPServerSettings settings, HTTPServerRequ else { auto li = new HTTPServerContext(addr, settings.port); if (auto tcp_lst = doListen(li, - (settings.options & HTTPServerOptionImpl.distribute) != 0, (settings.options & HTTPServerOption.reusePort) != 0, (settings.options & HTTPServerOption.reuseAddress) != 0, settings.tlsContext !is null)) // DMD BUG 2043 diff --git a/http/vibe/http/status.d b/http/vibe/http/status.d index d2252e6248..cc90b711a6 100644 --- a/http/vibe/http/status.d +++ b/http/vibe/http/status.d @@ -61,47 +61,47 @@ enum HTTPStatus { failedDependency = 424, insufficientStorage = 507, - requestedrangenotsatisfiable = rangeNotSatisfiable, /// deprecated - Continue = continue_, /// deprecated - SwitchingProtocols = switchingProtocols, /// deprecated - OK = ok, /// deprecated - Created = created, /// deprecated - Accepted = accepted, /// deprecated - NonAuthoritativeInformation = nonAuthoritativeInformation, /// deprecated - NoContent = noContent, /// deprecated - ResetContent = resetContent, /// deprecated - PartialContent = partialContent, /// deprecated - MultipleChoices = multipleChoices, /// deprecated - MovedPermanently = movedPermanently, /// deprecated - Found = found, /// deprecated - SeeOther = seeOther, /// deprecated - NotModified = notModified, /// deprecated - UseProxy = useProxy, /// deprecated - TemporaryRedirect = temporaryRedirect, /// deprecated - BadRequest = badRequest, /// deprecated - Unauthorized = unauthorized, /// deprecated - PaymentRequired = paymentRequired, /// deprecated - Forbidden = forbidden, /// deprecated - NotFound = notFound, /// deprecated - MethodNotAllowed = methodNotAllowed, /// deprecated - NotAcceptable = notAcceptable, /// deprecated - ProxyAuthenticationRequired = proxyAuthenticationRequired, /// deprecated - RequestTimeout = requestTimeout, /// deprecated - Conflict = conflict, /// deprecated - Gone = gone, /// deprecated - LengthRequired = lengthRequired, /// deprecated - PreconditionFailed = preconditionFailed, /// deprecated - RequestEntityTooLarge = requestEntityTooLarge, /// deprecated - RequestURITooLarge = requestURITooLarge, /// deprecated - UnsupportedMediaType = unsupportedMediaType, /// deprecated - Requestedrangenotsatisfiable = requestedrangenotsatisfiable, /// deprecated - ExpectationFailed = expectationFailed, /// deprecated - InternalServerError = internalServerError, /// deprecated - NotImplemented = notImplemented, /// deprecated - BadGateway = badGateway, /// deprecated - ServiceUnavailable = serviceUnavailable, /// deprecated - GatewayTimeout = gatewayTimeout, /// deprecated - HTTPVersionNotSupported = httpVersionNotSupported, /// deprecated + deprecated("Use `rangeNotSatisfiable` instead") requestedrangenotsatisfiable = rangeNotSatisfiable, + deprecated("Use `continue_` instead") Continue = continue_, + deprecated("Use `switchingProtocols` instead") SwitchingProtocols = switchingProtocols, + deprecated("Use `ok` instead") OK = ok, + deprecated("Use `created` instead") Created = created, + deprecated("Use `accepted` instead") Accepted = accepted, + deprecated("Use `nonAuthoritativeInformation` instead") NonAuthoritativeInformation = nonAuthoritativeInformation, + deprecated("Use `noContent` instead") NoContent = noContent, + deprecated("Use `resetContent` instead") ResetContent = resetContent, + deprecated("Use `partialContent` instead") PartialContent = partialContent, + deprecated("Use `multipleChoices` instead") MultipleChoices = multipleChoices, + deprecated("Use `movedPermanently` instead") MovedPermanently = movedPermanently, + deprecated("Use `found` instead") Found = found, + deprecated("Use `seeOther` instead") SeeOther = seeOther, + deprecated("Use `notModified` instead") NotModified = notModified, + deprecated("Use `useProxy` instead") UseProxy = useProxy, + deprecated("Use `temporaryRedirect` instead") TemporaryRedirect = temporaryRedirect, + deprecated("Use `badRequest` instead") BadRequest = badRequest, + deprecated("Use `unauthorized` instead") Unauthorized = unauthorized, + deprecated("Use `paymentRequired` instead") PaymentRequired = paymentRequired, + deprecated("Use `forbidden` instead") Forbidden = forbidden, + deprecated("Use `notFound` instead") NotFound = notFound, + deprecated("Use `methodNotAllowed` instead") MethodNotAllowed = methodNotAllowed, + deprecated("Use `notAcceptable` instead") NotAcceptable = notAcceptable, + deprecated("Use `proxyAuthenticationRequired` instead") ProxyAuthenticationRequired = proxyAuthenticationRequired, + deprecated("Use `requestTimeout` instead") RequestTimeout = requestTimeout, + deprecated("Use `conflict` instead") Conflict = conflict, + deprecated("Use `gone` instead") Gone = gone, + deprecated("Use `lengthRequired` instead") LengthRequired = lengthRequired, + deprecated("Use `preconditionFailed` instead") PreconditionFailed = preconditionFailed, + deprecated("Use `requestEntityTooLarge` instead") RequestEntityTooLarge = requestEntityTooLarge, + deprecated("Use `requestURITooLarge` instead") RequestURITooLarge = requestURITooLarge, + deprecated("Use `unsupportedMediaType` instead") UnsupportedMediaType = unsupportedMediaType, + deprecated("Use `requestedrangenotsatisfiable` instead") Requestedrangenotsatisfiable = rangeNotSatisfiable, + deprecated("Use `expectationFailed` instead") ExpectationFailed = expectationFailed, + deprecated("Use `internalServerError` instead") InternalServerError = internalServerError, + deprecated("Use `notImplemented` instead") NotImplemented = notImplemented, + deprecated("Use `badGateway` instead") BadGateway = badGateway, + deprecated("Use `serviceUnavailable` instead") ServiceUnavailable = serviceUnavailable, + deprecated("Use `gatewayTimeout` instead") GatewayTimeout = gatewayTimeout, + deprecated("Use `httpVersionNotSupported` instead") HTTPVersionNotSupported = httpVersionNotSupported, } @@ -147,7 +147,7 @@ string httpStatusText(int code) case HTTPStatus.requestEntityTooLarge : return "Request Entity Too Large"; case HTTPStatus.requestURITooLarge : return "Request-URI Too Large"; case HTTPStatus.unsupportedMediaType : return "Unsupported Media Type"; - case HTTPStatus.requestedrangenotsatisfiable : return "Requested range not satisfiable"; + case HTTPStatus.rangeNotSatisfiable : return "Requested range not satisfiable"; case HTTPStatus.expectationFailed : return "Expectation Failed"; case HTTPStatus.unavailableForLegalReasons : return "Unavailable For Legal Reasons"; case HTTPStatus.internalServerError : return "Internal Server Error"; diff --git a/web/vibe/web/common.d b/web/vibe/web/common.d index 6d9130c2ea..8985287780 100644 --- a/web/vibe/web/common.d +++ b/web/vibe/web/common.d @@ -850,19 +850,19 @@ enum MethodStyle /// UPPER-CASE-NAMING upperDashed, - /// deprecated + deprecated Unaltered = unaltered, - /// deprecated + deprecated CamelCase = camelCase, - /// deprecated + deprecated PascalCase = pascalCase, - /// deprecated + deprecated LowerCase = lowerCase, - /// deprecated + deprecated UpperCase = upperCase, - /// deprecated + deprecated LowerUnderscored = lowerUnderscored, - /// deprecated + deprecated UpperUnderscored = upperUnderscored, }