Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Support PURGE request method. #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ static const char *method_strings[] =
, "SUBSCRIBE"
, "UNSUBSCRIBE"
, "PATCH"
, "PURGE"
};


Expand Down Expand Up @@ -897,7 +898,7 @@ size_t http_parser_execute (http_parser *parser,
case 'N': parser->method = HTTP_NOTIFY; break;
case 'O': parser->method = HTTP_OPTIONS; break;
case 'P': parser->method = HTTP_POST;
/* or PROPFIND or PROPPATCH or PUT or PATCH */
/* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */
break;
case 'R': parser->method = HTTP_REPORT; break;
case 'S': parser->method = HTTP_SUBSCRIBE; break;
Expand Down Expand Up @@ -951,14 +952,18 @@ size_t http_parser_execute (http_parser *parser,
if (ch == 'R') {
parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */
} else if (ch == 'U') {
parser->method = HTTP_PUT;
parser->method = HTTP_PUT; /* or HTTP_PURGE */
} else if (ch == 'A') {
parser->method = HTTP_PATCH;
} else {
goto error;
}
} else if (parser->index == 2 && parser->method == HTTP_UNLOCK && ch == 'S') {
parser->method = HTTP_UNSUBSCRIBE;
} else if (parser->index == 2) {
if (parser->method == HTTP_PUT) {
if (ch == 'R') parser->method = HTTP_PURGE;
} else if (parser->method == HTTP_UNLOCK) {
if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE;
}
} else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
parser->method = HTTP_PROPPATCH;
} else {
Expand Down
1 change: 1 addition & 0 deletions http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ enum http_method
, HTTP_UNSUBSCRIBE
/* RFC-5789 */
, HTTP_PATCH
, HTTP_PURGE
};


Expand Down
20 changes: 20 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,26 @@ const struct message requests[] =
,.body= "q=42"
}

#define PURGE_REQ 30
, {.name = "PURGE request"
,.type= HTTP_REQUEST
,.raw= "PURGE /file.txt HTTP/1.1\r\n"
"Host: www.example.com\r\n"
"\r\n"
,.should_keep_alive= TRUE
,.message_complete_on_eof= FALSE
,.http_major= 1
,.http_minor= 1
,.method= HTTP_PURGE
,.query_string= ""
,.fragment= ""
,.request_path= "/file.txt"
,.request_url= "/file.txt"
,.num_headers= 1
,.headers= { { "Host", "www.example.com" } }
,.body= ""
}

, {.name= NULL } /* sentinel */
};

Expand Down