Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deprecated to deprecate enum members in :http #2604

Merged
merged 1 commit into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion http/vibe/http/client.d
Expand Up @@ -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.");
}

}
Expand Down
2 changes: 1 addition & 1 deletion http/vibe/http/common.d
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions http/vibe/http/fileserver.d
Expand Up @@ -282,22 +282,22 @@ 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) {
if (settings.options & HTTPFileServerOption.serveIndexHTML)
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;
}

Expand Down Expand Up @@ -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
Expand Down
48 changes: 14 additions & 34 deletions http/vibe/http/server.d
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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
}


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
84 changes: 42 additions & 42 deletions http/vibe/http/status.d
Expand Up @@ -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,
}


Expand Down Expand Up @@ -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";
Expand Down
14 changes: 7 additions & 7 deletions web/vibe/web/common.d
Expand Up @@ -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,
}

Expand Down