:rocket: Pegasus.lua is an http server to work with web applications written in Lua language.
468
stars
524
commits
Lua
primary language
Mar 8, 2026
updated
An http server to work with web applications written in Lua language check the site.
To install Pegasus.lua, run:
$ luarocks install pegasus
Follow an example:
local pegasus = require 'pegasus'
local server = pegasus:new({
port='9090',
location='example/root'
})
server:start(function (request, response)
print "It's running..."
end)
Or try the included examples.
host:string Host address where the application will run. By default it uses localhostport:string The port where the application will run. By default it's 9090location:string Path used by Pegasus to search for the files. By default it's the rootplugins:table List with pluginstimeout:number It's a timeout for estabilishing a connection with the serverpath:string A string with the request pathheaders:table A table with all the headers datamethod:function The output is the request method as a string ('GET', 'POST', etc)querystring:string It returns a dictionary with all the GET parametersip:string It returns the client's ipport:number It returns the port where Pegasus is runningaddHeader(string:key, string:value) Adds a new headeraddHeaders(table:headers) It adds news headersstatusCode(number:statusCode, string:statusMessage) It adds a Status CodecontentType(string:value) Adds a value to Content-Type fieldwrite(string:body) It creates the body with the value passed as
parameterwriteDefaultErrorMessage(statusCode: string, message:body) It sets an HTTP status code and writes an error message to the responsewriteFile(string:file) It creates the body with the content of the
file passed as parameterpost():table It returns a dictionary with all the POST parametersredirect(location:string, temporary:boolean): Makes an HTTP redirect to a new location. The status code is set to 302 if temporary is true and false otherwise.local pegasus = require 'pegasus'
local server = pegasus:new({ port='9090' })
server:start(function (req, rep)
rep:addHeader('Date', 'Mon, 15 Jun 2015 14:24:53 GMT'):write('hello pegasus world!')
return rep:close()
end)
local Pegasus = require 'pegasus'
local Compress = require 'pegasus.plugins.compress'
local server = Pegasus:new({
plugins = { Compress:new() }
})
server:start()
local Pegasus = require 'pegasus'
local Downloads = require 'pegasus.plugins.downloads'
local server = Pegasus:new({
plugins = {
Downloads:new {
prefix = "downloads",
stripPrefix = true,
},
}
})
server:start()
local Pegasus = require 'pegasus'
local Files = require 'pegasus.plugins.files'
local server = Pegasus:new({
plugins = {
Files:new {
location = "./",
default = "index.html",
},
}
})
server:start()
local Pegasus = require 'pegasus'
local Tls = require 'pegasus.plugins.tls'
local server = Pegasus:new({
plugins = {
TLS:new {
wrap = {
mode = "server",
protocol = "any",
key = "./serverAkey.pem",
certificate = "./serverA.pem",
cafile = "./rootA.pem",
verify = {"none"},
options = {"all", "no_sslv2", "no_sslv3", "no_tlsv1"},
},
sni = nil,
},,
}
})
server:start()
$ make install_dependencies
$ make unit_test
Lua
98.3%
HTML
1.1%
:rocket: Pegasus.lua is an http server to work with web applications written in Lua language.
468
stars
524
commits
Lua
primary language
Mar 8, 2026
updated
An http server to work with web applications written in Lua language check the site.
To install Pegasus.lua, run:
$ luarocks install pegasus
Follow an example:
local pegasus = require 'pegasus'
local server = pegasus:new({
port='9090',
location='example/root'
})
server:start(function (request, response)
print "It's running..."
end)
Or try the included examples.
host:string Host address where the application will run. By default it uses localhostport:string The port where the application will run. By default it's 9090location:string Path used by Pegasus to search for the files. By default it's the rootplugins:table List with pluginstimeout:number It's a timeout for estabilishing a connection with the serverpath:string A string with the request pathheaders:table A table with all the headers datamethod:function The output is the request method as a string ('GET', 'POST', etc)querystring:string It returns a dictionary with all the GET parametersip:string It returns the client's ipport:number It returns the port where Pegasus is runningaddHeader(string:key, string:value) Adds a new headeraddHeaders(table:headers) It adds news headersstatusCode(number:statusCode, string:statusMessage) It adds a Status CodecontentType(string:value) Adds a value to Content-Type fieldwrite(string:body) It creates the body with the value passed as
parameterwriteDefaultErrorMessage(statusCode: string, message:body) It sets an HTTP status code and writes an error message to the responsewriteFile(string:file) It creates the body with the content of the
file passed as parameterpost():table It returns a dictionary with all the POST parametersredirect(location:string, temporary:boolean): Makes an HTTP redirect to a new location. The status code is set to 302 if temporary is true and false otherwise.local pegasus = require 'pegasus'
local server = pegasus:new({ port='9090' })
server:start(function (req, rep)
rep:addHeader('Date', 'Mon, 15 Jun 2015 14:24:53 GMT'):write('hello pegasus world!')
return rep:close()
end)
local Pegasus = require 'pegasus'
local Compress = require 'pegasus.plugins.compress'
local server = Pegasus:new({
plugins = { Compress:new() }
})
server:start()
local Pegasus = require 'pegasus'
local Downloads = require 'pegasus.plugins.downloads'
local server = Pegasus:new({
plugins = {
Downloads:new {
prefix = "downloads",
stripPrefix = true,
},
}
})
server:start()
local Pegasus = require 'pegasus'
local Files = require 'pegasus.plugins.files'
local server = Pegasus:new({
plugins = {
Files:new {
location = "./",
default = "index.html",
},
}
})
server:start()
local Pegasus = require 'pegasus'
local Tls = require 'pegasus.plugins.tls'
local server = Pegasus:new({
plugins = {
TLS:new {
wrap = {
mode = "server",
protocol = "any",
key = "./serverAkey.pem",
certificate = "./serverA.pem",
cafile = "./rootA.pem",
verify = {"none"},
options = {"all", "no_sslv2", "no_sslv3", "no_tlsv1"},
},
sni = nil,
},,
}
})
server:start()
$ make install_dependencies
$ make unit_test
Lua
98.3%
HTML
1.1%