LUA Networking Extension Library

LUA is a small scripting language designed to be embedded inside your application to provide extensibility.

It is also possible to extend the Lua scripting language itself via the use of extensions written in C. This page describes such an extension which provides a small number of basic networking and filesystem primitives.

By installing this extension you will be able to write networking applications in the Lua!

About Lua-httpd

The code is made up of several distinct parts:

libhttpd.c

This is Lua extension library which provides several networking and filesystem primitives to your Lua scripts.

The name is misleading as the primitives are not restricted to HTTP use - however changing the name now would be confusing - and the name LuaSocket is already used!

The primitives exported are described more fully in the lua-httpd documentation:

If you're interested in more filesystem primitive then you might wish to examine my Lua Filesystem Primitives Extension.

httpd.lua

This is a HTTP server written entirely in Lua.

It serves as both a complete example of using the library, and a complete HTTP server in its own right.

The server supports multiple virtual hosts, binary files, MIME type parsing from /etc/mime.types, directory indexes, and logging in the Apache common log format. See the source for more details.

client.lua

This is a very simple HTTP client, added for completeness. It will fetch and dump the contents of http://localhost:80/ - both the HTTP response headers, and the actual page contents.

Download lua-httpd

You can download the source of the extension and the sample webserver from the following link:

Compilation of lua-httpd

To compile this code you'll need the LUA 5.1 development headers and libraries installed upon your system.

Compilation has only been tested upon x86, running Debian's Sarge distribution. If you manage to compile the code upon another Distribution, or version, then please let me know.

Compilation should be as simple as running "make", install the library with "make install" - to remove the library you can run "make uninstall".

To start the sample webserver listening upon port 4444 run "make test" or "lua httpd.lua".