You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
I believe I've found a bug in the middleware execution flow.
Consider the following simplified example:
constrocky=require('rocky');constexpress=require('express');letsnafu=(port)=>{letapp=express();letproxy=rocky();letmethods=['head','get'];if(port!==1337){methods.reverse();}for(letrouteof['/foo']){for(letmethodofmethods){letmiddlewares=[];if(method==='get'){middlewares.push((request,response,next)=>{console.log(`GET on ${port}.`);returnnext();});}elseif(method==='head'){middlewares.push((request,response,next)=>{console.log(`HEAD on ${port}.`);returnnext();});}proxy[method](route,middlewares).forward('http://localhost:3001');}}app.use(proxy.middleware());app.listen(port,()=>{console.log(`Listening on port ${port}...`);});};snafu(1337);snafu(1338);// --> buggy!
The above function will register two middlewares, one for GET and another one for HEAD requests.
The function is called twice, if the port is 1337 the order of the routes will be:
HEAD /foo
GET /foo
Otherwise (if the port is 1338), the order in which the routes will be defined is:
GET /foo
HEAD /foo
And this is the output of the 4 different cURL calls:
curl -I "http://localhost:1337/foo" = HEAD on 1337
curl -X GET "http://localhost:1337/foo" = GET on 1337
curl -I "http://localhost:1338/foo" = GET on 1338wrong!
curl -X GET "http://localhost:1338/foo" = GET on 1338
Curiously enough, if I change the HEAD to a POST I get the expected behavior in all cases.
Is there a reason for this to happen?
The text was updated successfully, but these errors were encountered:
I believe I've found a bug in the middleware execution flow.
Consider the following simplified example:
The above function will register two middlewares, one for
GET
and another one forHEAD
requests.The function is called twice, if the port is 1337 the order of the routes will be:
HEAD /foo
GET /foo
Otherwise (if the port is 1338), the order in which the routes will be defined is:
GET /foo
HEAD /foo
And this is the output of the 4 different cURL calls:
curl -I "http://localhost:1337/foo"
=HEAD on 1337
curl -X GET "http://localhost:1337/foo"
=GET on 1337
curl -I "http://localhost:1338/foo"
=GET on 1338
wrong!curl -X GET "http://localhost:1338/foo"
=GET on 1338
Curiously enough, if I change the
HEAD
to aPOST
I get the expected behavior in all cases.Is there a reason for this to happen?
The text was updated successfully, but these errors were encountered: