4

I'm trying to use tcpserver from ucspi-tcp to launch a script that returns a simple web page. My script (hello.lua) is as follows:

#!/usr/bin/env lua
print([[HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>Hello in big font</h1>
</body>
</html>]])

I launch it with tcpserver -v -rh 0 9000 /path/to/hello.lua

When I use tcpcat myserver 9000, I get the expected return:
HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head>
<title>My title</title>
</head>
<body>
<h1> Hello in big font</h1>
</body>
</html>

However, when I try to use a webbrowser and point to http:\\myserver:9000, I get a browser error (in Chrome) Error 101 (net::ERR_CONNECTION_RESET): Unknown error, even though the tcpserver logging shows a transaction:
tcpserver: status 1/40
tcpserver: pid 21672 from <ip address of browser>
tcpserver: ok 21672 <server hostname>::::ffff:<server ip>:9000 <client hostname>::::ffff:<client ip>::3133
tcpserver: end 21672 status 0

I know I'm missing something basic here, but I can't put the pieces of the puzzle together. Any insight is appreciated! Thanks!

2 Answers 2

6

You need a blank line between the headers and the content:

HTTP/1.1 200 OK
Content-Type: text/html

<html>
<head>
<title>My title</title>
</head>
<body>
<h1>Hello in big font</h1>
</body>
</html>
4

RFC2616 specifies that the status line and header lines of an HTTP response must each be terminated with CRLF. If you composed your lua script on a non-Windows machine, then you likely do not have the proper CRLF line-terminators. Also, you need to separate the message headers from the body with a blank line (a CRLF on its own).

You must log in to answer this question.

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