mastercontroller 1.3.26 → 1.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MasterAction.js CHANGED
@@ -109,7 +109,12 @@ class MasterAction{
109
109
  return;
110
110
  }
111
111
 
112
- this.__response.writeHead(HTTP_STATUS.OK, {
112
+ // Use status field from data as HTTP status code if it's a valid 4xx/5xx code
113
+ const httpStatus = (data && typeof data.status === 'number' && data.status >= 400 && data.status <= 599)
114
+ ? data.status
115
+ : HTTP_STATUS.OK;
116
+
117
+ this.__response.writeHead(httpStatus, {
113
118
  'Content-Type': 'application/json',
114
119
  'Content-Length': byteSize
115
120
  });
package/MasterRouter.js CHANGED
@@ -37,7 +37,9 @@ const HTTP_METHODS = {
37
37
  GET: 'get',
38
38
  POST: 'post',
39
39
  PUT: 'put',
40
+ PATCH: 'patch',
40
41
  DELETE: 'delete',
42
+ HEAD: 'head',
41
43
  OPTIONS: 'options'
42
44
  };
43
45
 
@@ -239,7 +241,10 @@ const ROUTER_CONFIG = {
239
241
  const pathObj = normalizePaths(requestObject.pathName, route.path, testParams);
240
242
 
241
243
  // if we find the route that matches the request
242
- if(pathObj.requestPath === pathObj.routePath && route.type === requestObject.type){
244
+ // HEAD requests match GET routes per HTTP spec (RFC 9110 §9.3.2)
245
+ const methodMatches = route.type === requestObject.type
246
+ || (requestObject.type === HTTP_METHODS.HEAD && route.type === HTTP_METHODS.GET);
247
+ if(pathObj.requestPath === pathObj.routePath && methodMatches){
243
248
  // Only commit the extracted params if this route actually matches
244
249
  requestObject.params = testParams;
245
250
 
@@ -848,7 +853,12 @@ class MasterRouter {
848
853
  }
849
854
  return value;
850
855
  });
851
- requestObject.response.writeHead(200, {
856
+ // Use status field from return value as HTTP status code if it's a valid 4xx/5xx code
857
+ const httpStatus = (returnValue && typeof returnValue.status === 'number' && returnValue.status >= 400 && returnValue.status <= 599)
858
+ ? returnValue.status
859
+ : 200;
860
+
861
+ requestObject.response.writeHead(httpStatus, {
852
862
  'Content-Type': 'application/json',
853
863
  'Content-Length': Buffer.byteLength(json, 'utf8')
854
864
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastercontroller",
3
- "version": "1.3.26",
3
+ "version": "1.3.28",
4
4
  "description": "Fortune 500 ready Node.js MVC framework with enterprise security, monitoring, and horizontal scaling",
5
5
  "main": "MasterControl.js",
6
6
  "license": "MIT",