Skip to content

Commit 5ebe7f5

Browse files
committed
add patch support
1 parent 817f2d2 commit 5ebe7f5

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ test_g
77
TAGS
88
a.out
99
.DS_Store
10+
lib/http-parser.jar

src/impl/http_parser/HTTPMethod.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum HTTPMethod {
88
, HTTP_HEAD("HEAD")
99
, HTTP_POST("POST")
1010
, HTTP_PUT("PUT")
11+
, HTTP_PATCH("PATCH")
1112
/* pathological */
1213
, HTTP_CONNECT("CONNECT")
1314
, HTTP_OPTIONS("OPTIONS")
@@ -28,7 +29,7 @@ public enum HTTPMethod {
2829
, HTTP_NOTIFY("NOTIFY")
2930
, HTTP_SUBSCRIBE("SUBSCRIBE")
3031
, HTTP_UNSUBSCRIBE("UNSUBSCRIBE")
31-
32+
3233
;
3334

3435
private static Charset ASCII;
@@ -38,7 +39,7 @@ public enum HTTPMethod {
3839
public byte[] bytes;
3940

4041
HTTPMethod(String name) {
41-
// good grief, Charlie Brown, the following is necessary because
42+
// good grief, Charlie Brown, the following is necessary because
4243
// java is retarded:
4344
// illegal reference to static field from initializer
4445
// this.bytes = name.getBytes(ASCII);
@@ -57,6 +58,8 @@ public static HTTPMethod parse(String s) {
5758
else if ("POST".equalsIgnoreCase(s)) {return HTTP_POST;}
5859
else if ("HTTP_PUT".equalsIgnoreCase(s)) {return HTTP_PUT;}
5960
else if ("PUT".equalsIgnoreCase(s)) {return HTTP_PUT;}
61+
else if ("HTTP_PATCH".equalsIgnoreCase(s)) {return HTTP_PATCH;}
62+
else if ("PATCH".equalsIgnoreCase(s)) {return HTTP_PATCH;}
6063
else if ("HTTP_CONNECT".equalsIgnoreCase(s)) {return HTTP_CONNECT;}
6164
else if ("CONNECT".equalsIgnoreCase(s)) {return HTTP_CONNECT;}
6265
else if ("HTTP_OPTIONS".equalsIgnoreCase(s)) {return HTTP_OPTIONS;}
@@ -94,7 +97,7 @@ public static HTTPMethod parse(String s) {
9497
else if ("HTTP_UNSUBSCRIBE".equalsIgnoreCase(s)) {return HTTP_UNSUBSCRIBE;}
9598
else if ("UNSUBSCRIBE".equalsIgnoreCase(s)) {return HTTP_UNSUBSCRIBE;}
9699
else {return null;}
97-
}
100+
}
98101
void init (String name) {
99102
ASCII = null == ASCII ? Charset.forName("US-ASCII") : ASCII;
100103
this.bytes = name.getBytes(ASCII);

src/impl/http_parser/lolevel/HTTPParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ public int execute(ParserSettings settings, ByteBuffer data) {
441441
method = HTTPMethod.HTTP_PROPFIND;
442442
} else if (1 == index && HTTPMethod.HTTP_POST == method && U == ch) {
443443
method = HTTPMethod.HTTP_PUT;
444+
} else if (1 == index && HTTPMethod.HTTP_POST == method && A == ch) {
445+
method = HTTPMethod.HTTP_PATCH;
444446
} else if (2 == index && HTTPMethod.HTTP_UNLOCK == method && S == ch) {
445447
method = HTTPMethod.HTTP_UNSUBSCRIBE;
446448
} else if (4 == index && HTTPMethod.HTTP_PROPFIND == method && P == ch) {
@@ -1503,7 +1505,7 @@ HTTPMethod start_req_method_assign(byte c){
15031505
case M: return HTTPMethod.HTTP_MKCOL; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH */
15041506
case N: return HTTPMethod.HTTP_NOTIFY;
15051507
case O: return HTTPMethod.HTTP_OPTIONS;
1506-
case P: return HTTPMethod.HTTP_POST; /* or PROPFIND, PROPPATH, PUT */
1508+
case P: return HTTPMethod.HTTP_POST; /* or PROPFIND, PROPPATH, PUT, PATCH */
15071509
case R: return HTTPMethod.HTTP_REPORT;
15081510
case S: return HTTPMethod.HTTP_SUBSCRIBE;
15091511
case T: return HTTPMethod.HTTP_TRACE;

0 commit comments

Comments
 (0)