Skip to content

Commit

Permalink
add Allow header to server responses with status code 405
Browse files Browse the repository at this point in the history
Furthermore, a response to requests using the OPTIONS method is
implemented.
  • Loading branch information
striezel committed Nov 30, 2023
1 parent b5b4e32 commit 423632f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
11 changes: 11 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ Since [Plotly.js](https://plotly.com/javascript/) is the main dependency of this
application, major version changes in Plotly.js will also trigger a major
version change in this application.

## Version 4.5.4 (2023-11-30)

* __[improvement]__
Whenever the server responds to an unallowed method with HTTP status code 405,
it will now also send an `Allow` HTTP header to indicate the allowed methods.
This behaviour is required by [RFC 9110](https://httpwg.org/specs/rfc9110.html#status.405),
so it should be implemented.

Furthermore, any HTTP request to the server root using the OPTIONS method will
now return the allowed options via an `Allow` HTTP header.

## Version 4.5.3 (2023-11-29)

* __[bug fix]__
Expand Down
4 changes: 2 additions & 2 deletions export-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion export-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plotly-node-export-server",
"version": "4.5.3",
"version": "4.5.4",
"description": "Plotly.js Node.js export server",
"repository": {
"url": "https://gitlab.com/striezel/plotly-node-export-server.git",
Expand Down
7 changes: 7 additions & 0 deletions export-server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ const server = http.createServer(function(req, res) {

// ---- Handle plot generation requests ----

if (req.method === 'OPTIONS') {
res.statusCode = 204; // 204 == No content
res.setHeader('Allow', 'POST');
res.end();
return;
}
// Only post request shall be allowed.
if (req.method !== 'POST') {
res.statusCode = 405; // 405 == Method not allowed
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Allow', 'POST');
res.end('Only POST requests are allowed!\n');
return;
}
Expand Down

0 comments on commit 423632f

Please sign in to comment.