Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic CGI with Lua

Tags:

http

cgi

lua

uwsgi

I need a very light web solution to run on a Linux appliance to handle HTML forms, so intend to use uwsgi and Lua.

In the CGI script, this article uses the following code:

print ("Content-type: Text/html\n")
print ("Hello, world!")

However, this works too:

print("Status: 200 OK\r\n\r\nHello, world!\r\n")

I'd like to know what CGI scripts are really required to return to the web server.

Thank you.

like image 271
Gulbahar Avatar asked Jun 06 '26 02:06

Gulbahar


1 Answers

You don't need a header at all, the only thing you really need is the blank line that ends the header and starts the body:

print ("\nHello, World")

should work as well.

However, you should at least include the Content-type including the character set, since browsers should default to iso-8859-1, but the user may override this, and you should use utf-8 to avoid being restricted in what characters you can display.

print("Content-type: text/html; charset=utf-8")

Also, if you're programming an appliance, you probably want to avoid caching, so i'd spend an extra

print("Cache-control: no-cache")
print("Pragma: no-cache")

which prevents browsers and proxies from caching your page.

like image 51
Guntram Blohm Avatar answered Jun 07 '26 22:06

Guntram Blohm