Skip to content

Commit

Permalink
add missing features - HTTP PATCH support, HTTP 202 response code (#163)
Browse files Browse the repository at this point in the history
* allow PATCH method to send data in body of request

* allow HTTP 202 ACCEPTED status code

* update package info
  • Loading branch information
juxe authored and cjus committed Nov 16, 2017
1 parent b0e0deb commit a2edbc4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ class Hydra extends EventEmitter {
method: parsedRoute.httpMethod.toUpperCase()
};
let preHeaders = {};
if (options.method === 'POST' || options.method === 'PUT') {
if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') {
preHeaders['content-type'] = 'application/json';
}
options.headers = Object.assign(preHeaders, umfmsg.headers);
Expand Down
2 changes: 1 addition & 1 deletion lib/server-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ServerRequest {
*/
send(options) {
return new Promise((resolve, reject) => {
if (options.method === 'POST' || options.method === 'PUT') {
if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') {
options.headers = options.headers || {};
options.headers['content-length'] = Buffer.byteLength(options.body, 'utf8');
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/server-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class ServerResponse {
*/
ServerResponse.HTTP_OK = 200;
ServerResponse.HTTP_CREATED = 201;
ServerResponse.HTTP_ACCEPTED = 202;
ServerResponse.HTTP_MOVED_PERMANENTLY = 301;
ServerResponse.HTTP_FOUND = 302;
ServerResponse.HTTP_NOT_MODIFIED = 304;
Expand All @@ -294,6 +295,7 @@ ServerResponse.STATUSDESCRIPTION = 1;
ServerResponse.STATUS = {
'200': ['OK', 'Request succeeded without error'],
'201': ['Created', 'Resource created'],
'202': ['Accepted', 'Request accepted'],
'301': ['Moved Permanently', 'Resource has been permanently moved'],
'302': ['Found', 'Resource was found under another URI'],
'304': ['Not Modified', 'Resource has not been modified'],
Expand Down

0 comments on commit a2edbc4

Please sign in to comment.