1

I'm testing HTTP pipelining with nc,

So I've create a input file that contains the following lines,

GET / HTTP/1.1
Host: localhost

GET / HTTP/1.1
Host: localhost

Now I submit it with nc,

nc localhost 80 < test

But I got only one HTTP response, what's wrong with it? And nc is just here waiting for something, it doesn't return to console.

2 Answers 2

2

If you want to be able to submit multiple requests in one connection, you need keep-alive:

GET / HTTP/1.1
Host: localhost
Connection: keep-alive

Unfortunately, the server doesn't always have to comply with your request. It may reply with Connection: close or Connection: keep-alive. If it replies with the former, you can't pipeline your requests and you'll need to use two connections. Since piping something to netcat can't make decisions like that, you might want to just stay on the safe side and use two connections.

1
  • You do not need explicit keep-alive with HTTP/1.1.
    – ArtemGr
    Commented Jun 8, 2013 at 21:28
0

The problem might be in your HTTP server. Not every server supports the pipelining. Libevent does not, for example (and libevhtp is being fixed for it).

I have no trouble with nc and pipelining using the nginx HTTP server:

$ echo -en "GET / HTTP/1.1\r\nHost: fropl.com\r\n\r\nGET / HTTP/1.1\r\nHost: fropl.com\r\n\r\n" | nc localhost 80
HTTP/1.1 401 Unauthorized
Server: nginx/1.2.1
Date: Sat, 08 Jun 2013 21:38:59 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
WWW-Authenticate: Basic realm="frople"

HTTP/1.1 401 Unauthorized
Server: nginx/1.2.1
Date: Sat, 08 Jun 2013 21:38:59 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
WWW-Authenticate: Basic realm="frople"

P.S. You can use telnet or Perl if you doubt nc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .