Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy forwarding results in 421 Misdirected Request error #1897

Open
jawacompu10 opened this issue Aug 15, 2024 · 0 comments
Open

Proxy forwarding results in 421 Misdirected Request error #1897

jawacompu10 opened this issue Aug 15, 2024 · 0 comments

Comments

@jawacompu10
Copy link

Describe the issue
I am trying to configure mock-server to act as a proxy, and just at the time of running my tests respond with some mock response. But, the forwarding seems to have some problem, and results in a 421 Misdirected Request

What you are trying to do
I am trying to configure mock-server to act as a proxy, and just at the time of running my tests respond with some mock response. But, the forwarding seems to have some problem, and results in a 421 Misdirected Request

MockServer version
5.15.0 (latest)

To Reproduce
Steps to reproduce the issue:

  1. I am running the docker image using the command docker run -d -p 1080:1080 mockserver/mockserver
  2. I tried with both of the following so far:
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
    "httpRequest": {
        "path": ".*",
        "method": ".*"
    },
    "httpForward": {
        "host": "api.vapi.ai",
        "port": 443,
        "scheme": "HTTPS"
    },
    "times": {
        "unlimited": true
    },
    "timeToLive": {
        "unlimited": true
    }
}'

and

curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
    "httpRequest": {
        "path": ".*",
        "method": ".*"
    },
    "httpOverrideForwardedRequest": {
        "httpRequest": {
            "headers": {
                "Host": ["api.vapi.ai"]
            }
        }
    }
}'
  1. What error you saw
image

Expected behaviour
image

MockServer Log

2024-08-15 12:36:45 2024-08-15 08:36:45 5.15.0 INFO 1080 request:
2024-08-15 12:36:45 
2024-08-15 12:36:45   {
2024-08-15 12:36:45     "method" : "GET",
2024-08-15 12:36:45     "path" : "/call/b5ca1105-a1b2-43e1-97d5-19126cf31d85",
2024-08-15 12:36:45     "headers" : {
2024-08-15 12:36:45       "content-length" : [ "0" ],
2024-08-15 12:36:45       "User-Agent" : [ "PostmanRuntime/7.40.0" ],
2024-08-15 12:36:45       "Postman-Token" : [ "fc49a123-1a32-4762-b4c9-a7b7eff1e6da" ],
2024-08-15 12:36:45       "Host" : [ "localhost:1080" ],
2024-08-15 12:36:45       "Connection" : [ "keep-alive" ],
2024-08-15 12:36:45       "Authorization" : [ "Bearer ******" ],
2024-08-15 12:36:45       "Accept-Encoding" : [ "gzip, deflate, br" ],
2024-08-15 12:36:45       "Accept" : [ "*/*" ]
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "keepAlive" : true,
2024-08-15 12:36:45     "secure" : true,
2024-08-15 12:36:45     "protocol" : "HTTP_1_1",
2024-08-15 12:36:45     "localAddress" : "172.17.0.2:1080",
2024-08-15 12:36:45     "remoteAddress" : "192.168.65.1:65229"
2024-08-15 12:36:45   }
2024-08-15 12:36:45 
2024-08-15 12:36:45  matched expectation:
2024-08-15 12:36:45 
2024-08-15 12:36:45   {
2024-08-15 12:36:45     "httpForward" : {
2024-08-15 12:36:45       "host" : "api.vapi.ai",
2024-08-15 12:36:45       "port" : 443,
2024-08-15 12:36:45       "scheme" : "HTTPS"
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "httpRequest" : {
2024-08-15 12:36:45       "method" : ".*",
2024-08-15 12:36:45       "path" : ".*"
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "id" : "efacad0d-594c-4995-9785-164a4fc6648e",
2024-08-15 12:36:45     "priority" : 0,
2024-08-15 12:36:45     "timeToLive" : {
2024-08-15 12:36:45       "unlimited" : true
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "times" : {
2024-08-15 12:36:45       "unlimited" : true
2024-08-15 12:36:45     }
2024-08-15 12:36:45   }
2024-08-15 12:36:45  
2024-08-15 12:36:45 2024-08-15 08:36:45 5.15.0 INFO 1080 returning response:
2024-08-15 12:36:45 
2024-08-15 12:36:45   {
2024-08-15 12:36:45     "statusCode" : 421,
2024-08-15 12:36:45     "reasonPhrase" : "Misdirected Request",
2024-08-15 12:36:45     "headers" : {
2024-08-15 12:36:45       "Server" : [ "cloudflare" ],
2024-08-15 12:36:45       "Date" : [ "Thu, 15 Aug 2024 08:36:45 GMT" ],
2024-08-15 12:36:45       "Content-Type" : [ "text/html" ],
2024-08-15 12:36:45       "CF-RAY" : [ "8b37dbd8e94f99ab-CDG" ]
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "body" : "<html>\r\n<head><title>421 Misdirected Request</title></head>\r\n<body>\r\n<center><h1>421 Misdirected Request</h1></center>\r\n<hr><center>cloudflare</center>\r\n</body>\r\n</html>\r\n"
2024-08-15 12:36:45   }
2024-08-15 12:36:45 
2024-08-15 12:36:45  for forwarded request
2024-08-15 12:36:45 
2024-08-15 12:36:45  in json:
2024-08-15 12:36:45 
2024-08-15 12:36:45   {
2024-08-15 12:36:45     "method" : "GET",
2024-08-15 12:36:45     "path" : "/call/b5ca1105-a1b2-43e1-97d5-19126cf31d85",
2024-08-15 12:36:45     "headers" : {
2024-08-15 12:36:45       "content-length" : [ "0" ],
2024-08-15 12:36:45       "User-Agent" : [ "PostmanRuntime/7.40.0" ],
2024-08-15 12:36:45       "Postman-Token" : [ "fc49a123-1a32-4762-b4c9-a7b7eff1e6da" ],
2024-08-15 12:36:45       "Host" : [ "localhost:1080" ],
2024-08-15 12:36:45       "Connection" : [ "keep-alive" ],
2024-08-15 12:36:45       "Authorization" : [ "Bearer ******" ],
2024-08-15 12:36:45       "Accept-Encoding" : [ "gzip, deflate, br" ],
2024-08-15 12:36:45       "Accept" : [ "*/*" ]
2024-08-15 12:36:45     },
2024-08-15 12:36:45     "keepAlive" : true,
2024-08-15 12:36:45     "secure" : true,
2024-08-15 12:36:45     "protocol" : "HTTP_1_1",
2024-08-15 12:36:45     "localAddress" : "172.17.0.2:1080",
2024-08-15 12:36:45     "remoteAddress" : "192.168.65.1:65229"
2024-08-15 12:36:45   }
2024-08-15 12:36:45 
2024-08-15 12:36:45  
2024-08-15 12:36:45 
2024-08-15 12:36:45  in curl:
2024-08-15 12:36:45 
2024-08-15 12:36:45   curl -v 'https://localhost:1080/call/b5ca1105-a1b2-43e1-97d5-19126cf31d85' -H 'Authorization: Bearer ******' -H 'User-Agent: PostmanRuntime/7.40.0' -H 'Accept: */*' -H 'Postman-Token: fc49a123-1a32-4762-b4c9-a7b7eff1e6da' -H 'Host: localhost:1080' -H 'Accept-Encoding: gzip, deflate, br' --compress -H 'Connection: keep-alive' -H 'content-length: 0'
2024-08-15 12:36:45 
2024-08-15 12:36:45  for action:
2024-08-15 12:36:45 
2024-08-15 12:36:45   {
2024-08-15 12:36:45     "host" : "api.vapi.ai",
2024-08-15 12:36:45     "port" : 443,
2024-08-15 12:36:45     "scheme" : "HTTPS"
2024-08-15 12:36:45   }
2024-08-15 12:36:45 
2024-08-15 12:36:45  from expectation:
2024-08-15 12:36:45 
2024-08-15 12:36:45   efacad0d-594c-4995-9785-164a4fc6648e
2024-08-15 12:36:45  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant