Skip to content

Multiple forward slashes in request URL cause unexpected issues #6

@ImranR-TI

Description

@ImranR-TI

When the request being proxied has multiple consecutive forward slashes, the proxy seems to break and cut off the rest of the URL.

For example, given the following backend server:

// server.js

const express = require('express')
let port = 3004

const app = express()

app.get('/', (req, res) => {
    res.send('Hello World!')
})

app.get('/test', (req, res) => {
    res.send('Test Page!')
})

const server = app.listen(port, () => {
    console.log(`Server listening on port ${port}`)
})

And the following proxy usage:

// proxy.js

const http = require('http')
const httpProxy = require('http-proxy-3')

const proxy = httpProxy.createProxyServer({})

proxy.on('error', (err, req, res) => {
    console.error('Proxy error:', err)
    res.end('Something went wrong.')
})

const server = http.createServer((req, res) => {
    const target = 'http://localhost:3004'
    proxy.web(req, res, { target })
})

const port = 3005
server.listen(port, () => {
    console.log(`Proxy server listening on port ${port}`)
})

When I visit http://localhost:3005/test, I get the Test Page! response as expected. But when I visit http://localhost:3005//test (double forward slash //), it returns the Hello World! response (almost like like the //test part of the request URL was cut off, not sure if that's what's actually happening).

This doesn't happen with the latest (2018) version of the old http-proxy module, so that might be a clue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions