public
Description: A cross-platform web server that's scripted with Nu.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nunja.git
New -l option makes nunja bind only to loopback to serve local-only 
connections.
timburks (author)
Thu Aug 07 22:05:52 -0700 2008
commit  e5b79720af70f40bee1c43095e9dfd16ef6514cf
tree    024e261664b5501910778052c73ea92eeebeff91
parent  2081d118f7792b1c867be4916281f474bc44f127
...
154
155
156
157
 
 
158
159
160
...
154
155
156
 
157
158
159
160
161
0
@@ -154,7 +154,8 @@
0
      ;; Handle a request. Used internally.
0
      (- (id)handleRequest:(id)request is
0
         (if (Nunja verbose)
0
- (NSLog "handling request #{(request uri)}"))
0
+ (NSLog "handling request #{(request uri)}")
0
+ (NSLog "request from host #{(request remoteHost)} port #{(request remotePort)}"))
0
         (set response (dict))
0
         (set HEAD nil)
0
         (set TITLE nil)
0
...
46
47
48
 
 
49
50
51
...
53
54
55
56
 
 
 
 
57
58
59
...
46
47
48
49
50
51
52
53
...
55
56
57
 
58
59
60
61
62
63
64
0
@@ -46,6 +46,8 @@
0
              ("--site" (set argi (+ argi 1)) (set site (argv argi)))
0
              ("-p" (set argi (+ argi 1)) (set port ((argv argi) intValue)))
0
              ("--port" (set argi (+ argi 1)) (set port ((argv argi) intValue)))
0
+ ("-l" (Nunja setLocalOnly:YES))
0
+ ("--local" (Nunja setLocalOnly:YES))
0
              ("-v" (Nunja setVerbose:YES))
0
              ("--verbose" (Nunja setVerbose:YES))
0
              (else (puts (+ "unknown option: " (argv argi)))
0
@@ -53,7 +55,10 @@
0
        (set argi (+ argi 1)))
0
 
0
 (set n ((Nunja alloc) init))
0
-(n bindToAddress:"0.0.0.0" port:port)
0
+(if (Nunja localOnly)
0
+ (then (n bindToAddress:"127.0.0.1" port:port))
0
+ (else (n bindToAddress:"0.0.0.0" port:port)))
0
+
0
 (if site
0
     (n setDelegate:((NunjaDelegate alloc) initWithSite:site)))
0
 (puts (+ "Nunja is running on port " port))
...
22
23
24
 
25
26
27
...
41
42
43
 
44
45
46
...
90
91
92
 
 
 
 
 
 
 
 
 
93
94
95
...
200
201
202
 
 
 
 
 
 
 
203
204
205
...
208
209
210
211
212
213
214
...
22
23
24
25
26
27
28
...
42
43
44
45
46
47
48
...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
211
212
213
214
215
216
217
218
219
220
221
222
223
...
226
227
228
 
229
230
231
0
@@ -22,6 +22,7 @@ limitations under the License.
0
 #include <event.h>
0
 #include <evhttp.h>
0
 #define HTTP_SEEOTHER 303
0
+#define HTTP_DENIED 403
0
 
0
 #include <netdb.h>
0
 #include <evdns.h>
0
@@ -41,6 +42,7 @@ void NunjaInit()
0
 @class Nunja;
0
 
0
 static BOOL verbose_nunja = NO;
0
+static BOOL local_nunja = NO;
0
 
0
 @interface NunjaRequest : NSObject
0
 {
0
@@ -90,6 +92,15 @@ static BOOL verbose_nunja = NO;
0
     }
0
 }
0
 
0
+- (NSString *) remoteHost
0
+{
0
+ return [NSString stringWithCString:req->remote_host encoding:NSUTF8StringEncoding];
0
+}
0
+
0
+- (int) remotePort {
0
+ return req->remote_port;
0
+}
0
+
0
 static NSDictionary *nunja_request_headers_helper(struct evhttp_request *req)
0
 {
0
     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
0
@@ -200,6 +211,13 @@ static void nunja_response_helper(struct evhttp_request *req, int code, NSString
0
 
0
 + (BOOL) verbose {return verbose_nunja;}
0
 
0
++ (void) setLocalOnly:(BOOL) l
0
+{
0
+ local_nunja = l;
0
+}
0
+
0
++ (BOOL) localOnly {return local_nunja;}
0
+
0
 + (void) load
0
 {
0
     NunjaInit();
0
@@ -208,7 +226,6 @@ static void nunja_response_helper(struct evhttp_request *req, int code, NSString
0
 static void nunja_request_handler(struct evhttp_request *req, void *nunja_pointer)
0
 {
0
     Nunja *nunja = (Nunja *) nunja_pointer;
0
-
0
     id delegate = [nunja delegate];
0
     if (delegate) {
0
         [delegate handleRequest:[[[NunjaRequest alloc] initWithNunja:nunja request:req] autorelease]];

Comments

    No one has commented yet.