Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Add PATCH method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Jun 28, 2018
1 parent 59d3369 commit ed112b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ cc_library(
],
)

cc_binary(
name = "example-handlers",
copts = ["-Isrc",],
srcs = [
"src/examples/handlers/main.cpp",
],
deps = [ "//:served" ],
)

cc_test(
name = "served-test",
copts = ["-Isrc",],
Expand Down
11 changes: 10 additions & 1 deletion src/examples/handlers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <served/served.hpp>
#include <served/request_error.hpp>
#include <served/status.hpp>
#include <served/methods.hpp>

#include <iostream>

Expand All @@ -49,7 +50,15 @@ int main(int, char const**)
res << ", number: ";
res << req.params["number"];

std::cout << req.body() << std::endl;
std::cout << "POST: " << req.body() << std::endl;
})
.method(served::method::PATCH, [](served::response & res, const served::request & req) {
res << "id: ";
res << req.params["id"];
res << ", number: ";
res << req.params["number"];

std::cout << "PATCH: " << req.body() << std::endl;
});

// GET /handlers/{id}
Expand Down
7 changes: 6 additions & 1 deletion src/served/methods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace served {
* HTTP method enum
*/
enum method {
GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT, BREW
GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT, BREW, PATCH
};

/*
Expand Down Expand Up @@ -65,6 +65,8 @@ method_to_string(enum method m)
return "CONNECT";
case method::BREW:
return "BREW";
case method::PATCH:
return "PATCH";
}
return "";
}
Expand Down Expand Up @@ -106,6 +108,9 @@ method_from_string(const std::string & str)
if ( "BREW" == str ) {
return method::BREW;
}
if ( "PATCH" == str ) {
return method::PATCH;
}
throw std::runtime_error("method string not recognised");
}

Expand Down
1 change: 1 addition & 0 deletions src/served/request_parser_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ request_parser_impl::expecting_body()
{
case method::PUT:
case method::POST:
case method::PATCH:
{
std::string type = _request.header("content-type");
std::string length = _request.header("content-length");
Expand Down

0 comments on commit ed112b6

Please sign in to comment.