pico-engine icon indicating copy to clipboard operation
pico-engine copied to clipboard

The HTTP headers passed into rule and function seem to be incomplete

Open b1conrad opened this issue 1 year ago • 2 comments

We've gotten along without this for some time, but when using a pico to host a web application it would be useful to know some more things about the HTTP requests coming in. For instance, what is the HTTP method (GET or POST, etc.)?

b1conrad avatar Aug 03 '23 12:08 b1conrad

Hm. The code doesn't do anything to remove anything from the headers provided by express, which are quite slim compared to those provided by the Common Gateway Interface (CGI). Generate a current list from my status.pl CGI script (which shows a REQUEST_METHOD header among many other CGI headers).

Turns out that express does provide the information, in req.method which could be added to the _headers map.

b1conrad avatar Aug 03 '23 14:08 b1conrad

A request_method header can be added by changing this line

    return _.assign({}, req.query, req.body, { _headers: req.headers });

to look like this line

    return _.assign({}, req.query, req.body, { _headers: _.assign(req.headers, { request_method: req.method }) });

b1conrad avatar Aug 03 '23 14:08 b1conrad