Software /
code /
prosody
Annotate
net/httpserver_listener.lua @ 2558:0a65fc0c7bee
net.adns: Use different flavour of voodoo to make UDP sockets work smoothly with libevent (no packet merging)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 31 Jan 2010 19:54:56 +0000 |
parent | 2372:bb88b76c21d0 |
child | 2925:692b3c6c5bd2 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
634
diff
changeset
|
8 |
634
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local connlisteners_register = require "net.connlisteners".register; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local new_request = require "net.httpserver".new_request; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local request_reader = require "net.httpserver".request_reader; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local requests = {}; -- Open requests |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local httpserver = { default_port = 80, default_mode = "*a" }; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
2129
fcdcdf00787c
*_listener: Update for new net.server API, specifically .listener -> .onincoming, .disconnect -> .ondisconnect
Matthew Wild <mwild1@gmail.com>
parents:
1540
diff
changeset
|
19 function httpserver.onincoming(conn, data) |
634
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local request = requests[conn]; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if not request then |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 request = new_request(conn); |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 requests[conn] = request; |
1540
19fb86c19a59
net.httpserver: Mark a request as secure if it is made using HTTPS
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
25 |
19fb86c19a59
net.httpserver: Mark a request as secure if it is made using HTTPS
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
26 -- If using HTTPS, request is secure |
2372
bb88b76c21d0
httpserver_listener: Update for new connection API
Matthew Wild <mwild1@gmail.com>
parents:
2129
diff
changeset
|
27 if conn:ssl() then |
1540
19fb86c19a59
net.httpserver: Mark a request as secure if it is made using HTTPS
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
28 request.secure = true; |
19fb86c19a59
net.httpserver: Mark a request as secure if it is made using HTTPS
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
29 end |
634
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 if data then |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 request_reader(request, data); |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
2129
fcdcdf00787c
*_listener: Update for new net.server API, specifically .listener -> .onincoming, .disconnect -> .ondisconnect
Matthew Wild <mwild1@gmail.com>
parents:
1540
diff
changeset
|
37 function httpserver.ondisconnect(conn, err) |
634
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local request = requests[conn]; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if request and not request.destroyed then |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 request.conn = nil; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 request_reader(request, nil); |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 requests[conn] = nil; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 connlisteners_register("httpserver", httpserver); |