You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2023/04/30 03:32:39 UTC
[mina] 07/07: Updated the HTTP various constantsé
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch 2.2.X
in repository https://gitbox.apache.org/repos/asf/mina.git
commit 9770d2ad5db0fe277adb4917103e960ddef8b9a4
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Sun Apr 30 05:31:47 2023 +0200
Updated the HTTP various constantsé
---
.../java/org/apache/mina/http/api/HttpMethod.java | 58 +++++++++++++++-------
.../java/org/apache/mina/http/api/HttpStatus.java | 40 ++++++++++++++-
.../java/org/apache/mina/http/api/HttpVersion.java | 51 ++++++++++++++-----
3 files changed, 117 insertions(+), 32 deletions(-)
diff --git a/mina-http/src/main/java/org/apache/mina/http/api/HttpMethod.java b/mina-http/src/main/java/org/apache/mina/http/api/HttpMethod.java
index 252c32f1d..04dc6ee26 100644
--- a/mina-http/src/main/java/org/apache/mina/http/api/HttpMethod.java
+++ b/mina-http/src/main/java/org/apache/mina/http/api/HttpMethod.java
@@ -25,9 +25,7 @@ package org.apache.mina.http.api;
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public enum HttpMethod {
- /** The OPTIONS method */
- OPTIONS,
-
+ // HTTP 1.0 official methods
/** The GET method */
GET,
@@ -37,33 +35,55 @@ public enum HttpMethod {
/** The POST method */
POST,
- /** The PUT method */
- PUT,
+ // HTTP 1.1 official methods
+ /** The CONNECT method */
+ CONNECT,
- /** The PATCH method */
- PATCH,
+ /** The DELETE method */
+ DELETE,
- /** The COPY method */
- COPY,
+ /** The OPTIONS method */
+ OPTIONS,
- /** The MOVE method */
- MOVE,
+ /** The PUT method */
+ PUT,
- /** The DELETE method */
- DELETE,
+ /** The TRACE method */
+ TRACE,
+ // Additional HTTP 1.0 methods
/** The LINK method */
LINK,
/** The UNLINK method */
UNLINK,
-
- /** The TRACE method */
- TRACE,
- /** The WRAPPED method */
+ // Additional HTTP 1.1 methods
+ /** The PATCH method, RFC 5789 */
+ PATCH,
+
+ // Other methods
+ /** The COPY method, RFC 4918*/
+ COPY,
+
+ /** The MOVE method, RFC 5789 */
+ MOVE,
+
+ /** The LOCK method, RFC 5789 */
+ LOCK,
+
+ /** The UNLOCK method, RFC 5789 */
+ UNLOCK,
+
+ /** The WRAPPED method ??? */
WRAPPED,
- /** The CONNECT method */
- CONNECT
+ /** Unknown method */
+ UNKNOWN;
+
+ String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
diff --git a/mina-http/src/main/java/org/apache/mina/http/api/HttpStatus.java b/mina-http/src/main/java/org/apache/mina/http/api/HttpStatus.java
index a8af90996..aee07c47e 100644
--- a/mina-http/src/main/java/org/apache/mina/http/api/HttpStatus.java
+++ b/mina-http/src/main/java/org/apache/mina/http/api/HttpStatus.java
@@ -26,6 +26,7 @@ package org.apache.mina.http.api;
*/
public enum HttpStatus {
+ // 1xx - Information
/**
* 100 - Continue
*/
@@ -33,7 +34,17 @@ public enum HttpStatus {
/**
* 101 - Switching Protocols
*/
- INFORMATIONAL_SWITCHING_PROTOCOLS(101, "HTTP/1.1 101 Swtiching Protocols"),
+ INFORMATIONAL_SWITCHING_PROTOCOLS(101, "HTTP/1.1 101 Switching Protocols"),
+ /**
+ * 102 - Proxessing, RFC 2518
+ */
+ //PROCESSING(102, "HTTP/1.1 102 Processing"),
+ /**
+ * 103 - Early Hints, RFC 8297
+ */
+ //EARLY_HINTS(103, "HTTP/1.1 103 Early Hints"),
+
+ // 2xx - Succes
/**
* 200 - OK
*/
@@ -63,6 +74,7 @@ public enum HttpStatus {
*/
SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
+ // 3xx - Redirection
/**
* 300 - Multiple Choices
*/
@@ -91,7 +103,12 @@ public enum HttpStatus {
* 307 - Temporary Redirect
*/
REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
+ /**
+ * 308 - Permanent Redirect
+ */
+ PERMANENT_REDIRECT(308, "HTTP/1.1 308 Permanent Redirect"),
+ // 4xx - Client Error
/**
* 400 - Bad Request
*/
@@ -160,7 +177,28 @@ public enum HttpStatus {
* 417 - Expectation Failed
*/
CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
+
+ /**
+ * 418 - Unused (RFC2324 was an April 1 RFC that lampooned the various ways HTTP was abused)
+ */
+ CLIENT_ERROR_UNUSED(418, "HTTP¨/1.1 418 - Unused"),
+
+ /**
+ * 421 - Misdirected Request
+ */
+ CLIENT_ERROR_MISDIRECTED_REQUEST(421, "HTTP¨/1.1 421 Misdirected Request"),
+
+ /**
+ * 422 - Unprocessable Content
+ */
+ CLIENT_ERROR_UNPROCESSABLE_CONTENT(422, "HTTP¨/1.1 422 Unprocessable Content"),
+
+ /**
+ * 426 - Upgrade Required
+ */
+ CLIENT_ERROR_UPGRADE_REQUIRED(426, "HTTP/1.1 426 Upgrade Required"),
+ // 5xx - Server Error
/**
* 500 - Internal Server Error
*/
diff --git a/mina-http/src/main/java/org/apache/mina/http/api/HttpVersion.java b/mina-http/src/main/java/org/apache/mina/http/api/HttpVersion.java
index 98fd69537..6d5d913ba 100644
--- a/mina-http/src/main/java/org/apache/mina/http/api/HttpVersion.java
+++ b/mina-http/src/main/java/org/apache/mina/http/api/HttpVersion.java
@@ -20,20 +20,37 @@
package org.apache.mina.http.api;
/**
- * Type safe enumeration representing HTTP protocol version
+ * Type safe enumeration representing HTTP protocol version. Must be
+ * one of :
+ * <ul>
+ * <li>HTTP 1.0</li>
+ * <li>HTTP 1.1</li>
+ * <li>HTTP 1.2</li>
+ * <li>HTTP 1.3</li>
+ * </ul>
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public enum HttpVersion {
+ /**
+ * HTTP 1/0
+ */
+ HTTP_1_0("HTTP/1.0"),
+
/**
* HTTP 1/1
*/
HTTP_1_1("HTTP/1.1"),
/**
- * HTTP 1/0
+ * HTTP 1/2
*/
- HTTP_1_0("HTTP/1.0");
+ HTTP_1_2("HTTP/1.2"),
+
+ /**
+ * HTTP 1/3
+ */
+ HTTP_1_3("HTTP/1.3");
private final String value;
@@ -47,16 +64,27 @@ public enum HttpVersion {
* @param string The String contaoning the HTTP version
* @return The version, or <code>null</code> if no version is found
*/
- public static HttpVersion fromString(String string) {
- if (HTTP_1_1.toString().equalsIgnoreCase(string)) {
- return HTTP_1_1;
+ public static HttpVersion fromString(String httpVersion) {
+ if (httpVersion == null) {
+ return null;
}
-
- if (HTTP_1_0.toString().equalsIgnoreCase(string)) {
- return HTTP_1_0;
+
+ switch (httpVersion.toUpperCase()) {
+ case "HTTP/1.0":
+ return HTTP_1_0;
+
+ case "HTTP/1.1":
+ return HTTP_1_1;
+
+ case "HTTP/1.2":
+ return HTTP_1_2;
+
+ case "HTTP/1.3":
+ return HTTP_1_3;
+
+ default:
+ return null;
}
-
- return null;
}
/**
@@ -66,5 +94,4 @@ public enum HttpVersion {
public String toString() {
return value;
}
-
}