Search code examples
javascriptnode.jsexpressget

Node.js Express sends 400 in requests when performing a query string containing pipes


With Node 12.0.0 and express 4.16.4 when I make a request containing | (the character pipe) it always answer 400 bad request.

This is a sample server:

var express = require('express');

var app = express();

app.all('*', function(request, response, next) {
    console.log(request)
    next();
});

app.get('/search', function (request, response) {
    response.send("yeah!");
});

var server = app.listen(8000, function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('Server listening at http://%s:%s', host, port);
});

if I perform a GET request like http://localhost:8000/search?q=| There is no log from the middleware and 400 bad request is sent.

I need to handle requests with pipes to preserve old URLs. How can I solve it?


Solution

  • You can use --http-parser=legacy to work around this issue for now.

    node --http-parser=legacy index.js

    I had open a issue about it HTTP response corrupted with status 400 when URL includes pipe character (|)