Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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>
share|improve this answer
add comment

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.