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

Add support for WebDAV http methods #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 16 additions & 8 deletions include/httpp/http/Protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ static char const HEADER_BODY_SEP[] = { '\r', '\n', '\r', '\n' };

enum class Method
{
HEAD ,
GET ,
POST ,
PUT ,
DELETE_ , // '_' for msvc workaround
OPTIONS ,
TRACE ,
CONNECT
HEAD,
GET,
POST,
PUT,
DELETE_, // '_' for msvc workaround
OPTIONS,
TRACE,
CONNECT,
// WebDAV specific methods
PROPFIND,
PROPPATCH,
MKCOL,
COPY,
MOVE,
LOCK,
UNLOCK,
};

std::string to_string(Method method);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add those new methods to the to_string and method_from functions

Expand Down
79 changes: 76 additions & 3 deletions src/httpp/http/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ static bool parse_method(Iterator& it, Request& request)
return true;
}
}
else if (*it == 'R')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the stream based parser is deprecated and you'll add many more methods, maybe we can either delete it or simplify it ?

{
if (!expect(it, "ROP"))
{
return false;
}

if (*it == 'F')
{
if (expect(it, "FIND"))
{
request.method = Method::PROPFIND;
return true;
}
}
else if (*it == 'P')
{
if (expect(it, "PATCH"))
{
request.method = Method::PROPPATCH;
return true;
}
}
}
break;
case 'D':
if (expect(it, "DELETE"))
Expand All @@ -123,11 +147,60 @@ static bool parse_method(Iterator& it, Request& request)
return true;
}
break;

case 'M':
++it;
if (*it == 'O')
{
if (expect(it, "OVE"))
{
request.method = Method::MOVE;
return true;
}
}
else if (*it == 'K')
{
if (expect(it, "KCOL"))
{
request.method = Method::MKCOL;
return true;
}
}
break;
case 'C':
if (expect(it, "CONNECT"))
++it;
if (*it != 'O')
{
return false;
}
++it;
if (*it == 'N')
{
if (expect(it, "NNECT"))
{
request.method = Method::CONNECT;
return true;
}
}
else if (*it == 'P')
{
if (expect(it, "PY"))
{
request.method = Method::COPY;
return true;
}
}
break;
case 'L':
if (expect(it, "LOCK"))
{
request.method = Method::LOCK;
return true;
}
break;
case 'U':
if (expect(it, "UNLOCK"))
{
request.method = Method::CONNECT;
request.method = Method::UNLOCK;
return true;
}
break;
Expand Down
7 changes: 7 additions & 0 deletions src/httpp/http/client/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ void Connection::configureRequest(HTTPP::HTTP::Method method)
case HTTPP::HTTP::Method::OPTIONS:
case HTTPP::HTTP::Method::TRACE:
case HTTPP::HTTP::Method::CONNECT:
case HTTPP::HTTP::Method::PROPFIND:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice that you thought of that :)

case HTTPP::HTTP::Method::PROPPATCH:
case HTTPP::HTTP::Method::MKCOL:
case HTTPP::HTTP::Method::COPY:
case HTTPP::HTTP::Method::MOVE:
case HTTPP::HTTP::Method::LOCK:
case HTTPP::HTTP::Method::UNLOCK:
std::string method_str = to_string(method);
conn_setopt(CURLOPT_CUSTOMREQUEST, method_str.data());
break;
Expand Down
2 changes: 1 addition & 1 deletion src/httpp/http/parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool Parser::parse(const char* start,
const char *token_begin, *token_end;

%%{
method = ("GET" | "POST" | "HEAD" | "PUT" | "DELETE" | "OPTIONS" | "TRACE" | "CONNECT");
method = ("GET" | "POST" | "HEAD" | "PUT" | "DELETE" | "OPTIONS" | "TRACE" | "CONNECT" | "PROPFIND" | "PROPPATCH" | "MKCOL" | "COPY" | "MOVE" | "LOCK" | "UNLOCK");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't add the methods in the method_from function, while parsed, you won't get the proper enum in the Request


identifier = (alnum | '-')+;

Expand Down