Software /
code /
prosody
Annotate
plugins/mod_httpserver.lua @ 748:172c43d735e9
modulemanager: Really fix call_module_method to work properly
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 02:01:09 +0000 |
parent | 696:b35faad717f2 |
child | 1384:2f7403d47cf1 |
rev | line source |
---|---|
696
b35faad717f2
mod_httpserver: Add require 'net.httpserver'
Matthew Wild <mwild1@gmail.com>
parents:
635
diff
changeset
|
1 |
b35faad717f2
mod_httpserver: Add require 'net.httpserver'
Matthew Wild <mwild1@gmail.com>
parents:
635
diff
changeset
|
2 local httpserver = require "net.httpserver"; |
635
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local open = io.open; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local t_concat = table.concat; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local http_base = "www_files"; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" }; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local http_path = { http_base }; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local function handle_request(method, body, request) |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local path = request.url.path:gsub("%.%.%/", ""):gsub("^/[^/]+", ""); |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 http_path[2] = path; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local f, err = open(t_concat(http_path), "r"); |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if not f then return response_404; end |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local data = f:read("*a"); |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 f:close(); |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 return data; |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
25f1117d7886
Add initial mod_httpserver for serving static content
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 httpserver.new{ port = 5280, base = "files", handler = handle_request, ssl = false} |