Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

yet you need to process HTML forms data (say POST data). You can use the power of Ajax Forms (javascript library) in order to have your POST data being sent as JSON, which you can read with io:read('*') back to your Lua script.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top