Software /
code /
prosody
Annotate
net/httpserver_listener.lua @ 1522:569d58d21612
Add copyright header to those files missing one
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 10 Jul 2009 03:08:38 +0100 |
parent | 634:1af93ea23f96 |
child | 1540:19fb86c19a59 |
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 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 function httpserver.listener(conn, data) |
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; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if data then |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 request_reader(request, data); |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
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 function httpserver.disconnect(conn, err) |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local request = requests[conn]; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 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
|
35 request.conn = nil; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 request_reader(request, nil); |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 requests[conn] = nil; |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
1af93ea23f96
Adding initial net.httpserver (lots of work to do on it)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 connlisteners_register("httpserver", httpserver); |