suve

awful: manual: CGI mode

Script languages have many uses, and CGI has a firm place among them. awful's CGI mode is aimed to make life a little bit easier for those brave enough to consider writing such a script in this language.

Syntax

#!/usr/bin/awful-cgi
<?yuk :writeln s"Hello world!" ?>

When run in CGI mode, file parsing differs significantly from the classical approach - but if you ever worked with PHP, you will feel at home. The main difference when using CGI mode is that awful code must be put inside <?yuk ?> tags. Everything outside these tags will be treated as strings to output - which allows you to easily embed awful inside HTML. Note that there is but one minor exception to this rule - if the first line of the script contains a shebang (#!), this line will NOT be output.

HTTP headers

One important thing to remember when creating a CGI script is to correctly output HTTP headers. awful-cgi contains several facilities to make this easier for you.

  • Automatic header printing - you don't have to print headers yourself. awful-cgi will do this for you automatically upon the first call to :write or :writeln. Obviously, this also includes printing raw strings outside the <?yuk ?> tags.
  • The :http-header function, which allows you to control which headers are printed, along with their contents.

wikistrona zmodyfikowana 2014/0601/2317