|
4 | 4 | * |
5 | 5 | * https://github.com/j-ulrich/http-status-codes-cpp |
6 | 6 | * |
7 | | - * \version 1.1.0 |
| 7 | + * \version 1.1.1 |
8 | 8 | * \author Jochen Ulrich <[email protected]> |
9 | 9 | * \copyright Licensed under Creative Commons CC0 (http://creativecommons.org/publicdomain/zero/1.0/) |
10 | 10 | */ |
|
25 | 25 | namespace HttpStatus |
26 | 26 | { |
27 | 27 |
|
28 | | -#if (QT_VERSION >= 0x050800) |
| 28 | +#if (QT_VERSION >= QT_VERSION_CHECK(5,8,0)) |
29 | 29 | Q_NAMESPACE |
30 | 30 | #endif // Qt >= 5.8.0 |
31 | 31 |
|
@@ -119,7 +119,7 @@ enum Code |
119 | 119 | NotExtended = 510, //!< The policy for accessing the resource has not been met in the request. [RFC 2774] |
120 | 120 | NetworkAuthenticationRequired = 511 //!< Indicates that the client needs to authenticate to gain network access. |
121 | 121 | }; |
122 | | -#if (QT_VERSION >= 0x050800) |
| 122 | +#if (QT_VERSION >= QT_VERSION_CHECK(5,8,0)) |
123 | 123 | Q_ENUM_NS(Code) |
124 | 124 | #endif // Qt >= 5.8.0 |
125 | 125 |
|
@@ -238,17 +238,21 @@ inline int networkErrorToStatusCode(QNetworkReply::NetworkError error) |
238 | 238 | case QNetworkReply::ContentNotFoundError: return NotFound; // 404 |
239 | 239 | case QNetworkReply::ContentOperationNotPermittedError: return MethodNotAllowed; // 405 |
240 | 240 | case QNetworkReply::ProxyAuthenticationRequiredError: return ProxyAuthenticationRequired; // 407 |
| 241 | +#if QT_VERSION >= QT_VERSION_CHECK(5,3,0) |
241 | 242 | case QNetworkReply::ContentConflictError: return Conflict; // 409 |
242 | 243 | case QNetworkReply::ContentGoneError: return Gone; // 410 |
243 | 244 | case QNetworkReply::InternalServerError: return InternalServerError; // 500 |
244 | 245 | case QNetworkReply::OperationNotImplementedError: return NotImplemented; // 501 |
245 | 246 | case QNetworkReply::ServiceUnavailableError: return ServiceUnavailable; // 503 |
| 247 | +#endif // Qt >= 5.3.0 |
246 | 248 |
|
247 | 249 | // Mapping error codes matching multiple HTTP status codes to a best matching "base" code |
248 | 250 | case QNetworkReply::NoError: return OK; // 200 |
249 | 251 | case QNetworkReply::ProtocolInvalidOperationError: return BadRequest; // 400 |
250 | 252 | case QNetworkReply::UnknownContentError: return BadRequest; // 400 |
| 253 | +#if QT_VERSION >= QT_VERSION_CHECK(5,3,0) |
251 | 254 | case QNetworkReply::UnknownServerError: return InternalServerError; // 500 |
| 255 | +#endif // Qt >= 5.3.0 |
252 | 256 |
|
253 | 257 | /* Other errors do not match any HTTP status code. |
254 | 258 | * Therefore, we return an invalid code. |
@@ -287,21 +291,27 @@ inline QNetworkReply::NetworkError statusCodeToNetworkError(int code) |
287 | 291 | case NotFound: return QNetworkReply::ContentNotFoundError; // 404 |
288 | 292 | case MethodNotAllowed: return QNetworkReply::ContentOperationNotPermittedError; // 405 |
289 | 293 | case ProxyAuthenticationRequired: return QNetworkReply::ProxyAuthenticationRequiredError; // 407 |
| 294 | +#if QT_VERSION >= QT_VERSION_CHECK(5,3,0) |
290 | 295 | case Conflict: return QNetworkReply::ContentConflictError; // 409 |
291 | 296 | case Gone: return QNetworkReply::ContentGoneError; // 410 |
| 297 | +#endif // Qt >= 5.3.0 |
292 | 298 | case ImATeapot: return QNetworkReply::ProtocolInvalidOperationError; // 418 |
| 299 | +#if QT_VERSION >= QT_VERSION_CHECK(5,3,0) |
293 | 300 | case InternalServerError: return QNetworkReply::InternalServerError; // 500 |
294 | 301 | case NotImplemented: return QNetworkReply::OperationNotImplementedError; // 501 |
295 | 302 | case ServiceUnavailable: return QNetworkReply::ServiceUnavailableError; // 503 |
| 303 | +#endif // Qt >= 5.3.0 |
296 | 304 |
|
297 | 305 | default: |
298 | 306 | break; |
299 | 307 | } |
300 | 308 |
|
301 | 309 | if (isClientError(code)) // 4xx |
302 | 310 | return QNetworkReply::UnknownContentError; |
| 311 | +#if QT_VERSION >= QT_VERSION_CHECK(5,3,0) |
303 | 312 | if (isServerError(code)) // 5xx |
304 | 313 | return QNetworkReply::UnknownServerError; |
| 314 | +#endif // Qt >= 5.3.0 |
305 | 315 |
|
306 | 316 | // 600 or above |
307 | 317 | return QNetworkReply::ProtocolFailure; |
|
0 commit comments