eexit / mirror-http-server

A dummy HTTP server that responds whatever you told it to
https://mirror-http-server.web.app
MIT License
38 stars 7 forks source link

Internal server error when setting access control headers #14

Closed EwanRoycroft closed 2 years ago

EwanRoycroft commented 3 years ago

I'm getting a 500 response when I try to mirror the Access-Control-Allow-Origin header.

$ docker run -ditp 8000:80 eexit/mirror-http-server
f7023a922ac60cea9c580abb3898a6f4536a7001a5720f06ab0fa8b62809833f
$ wget -Sq http://localhost:8000
  HTTP/1.1 200 OK
  X-Powered-By: Express
  Date: Wed, 10 Nov 2021 14:25:09 GMT
  Connection: keep-alive
  Content-Length: 0
$ wget -Sq http://localhost:8000 --header='X-Mirror-Access-Control-Allow-Origin: *'
  HTTP/1.1 500 Internal Server Error
  X-Powered-By: Express
  Content-Type: application/json; charset=utf-8
  Content-Length: 33
  ETag: W/"21-3errh/Cxu3miebVOHFA5cuyn784"
  Date: Wed, 10 Nov 2021 14:25:37 GMT
  Connection: keep-alive
EwanRoycroft commented 3 years ago

It seems it's misinterpreting the header and replacing dashes with spaces somewhere.

[2021-11-10T14:25:37.346Z]  INFO: mirror-http-server/27 on f7023a922ac6:
    request: {
      "ip": "172.17.0.1",
      "ips": [],
      "method": "GET",
      "url": "/",
      "headers": {
        "user-agent": "Wget/1.21.1",
        "accept": "*/*",
        "accept-encoding": "identity",
        "host": "localhost:8000",
        "connection": "Keep-Alive",
        "x-mirror-access-control-allow-origin": "*"
      },
      "body": {}
    }
[2021-11-10T14:25:37.347Z] FATAL: mirror-http-server/27 on f7023a922ac6: Header name must be a valid HTTP token ["Access-Control Allow Origin"] (err.code=ERR_INVALID_HTTP_TOKEN)
    TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["Access-Control Allow Origin"]
        at ServerResponse.setHeader (_http_outgoing.js:520:3)
        at ServerResponse.header (/app/node_modules/express/lib/response.js:771:10)
        at ServerResponse.header (/app/node_modules/express/lib/response.js:774:12)
        at /app/server.js:67:28
        at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
        at next (/app/node_modules/express/lib/router/route.js:137:13)
        at next (/app/node_modules/express/lib/router/route.js:131:14)
        at next (/app/node_modules/express/lib/router/route.js:131:14)
        at next (/app/node_modules/express/lib/router/route.js:131:14)
        at next (/app/node_modules/express/lib/router/route.js:131:14)