ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Added HTTP_CLIENT_IP

thanks Kamil
ryah (author)
about 1 month ago
commit  8527cb0287b33b50e2c3544d4391e097187dcdd3
tree    f5a340030df930bed8052cc6621e38633ca1286a
parent  3c8fdda73cd2e571c3395c425737e439c1a8bf99
...
76
77
78
79
80
81
82
83
84
...
76
77
78
 
 
 
79
80
81
0
@@ -76,9 +76,6 @@ end
0
 
0
 
0
 if $0 == __FILE__
0
- require 'rubygems'
0
- require 'ruby-debug'
0
- Debugger.start
0
   require DIR + '/../ruby_lib/ebb'
0
   server = Ebb::start_server(SimpleApp.new, :port => 4001)
0
 end
...
318
319
320
321
 
322
323
324
...
327
328
329
 
 
 
330
331
332
...
563
564
565
 
566
567
568
...
318
319
320
 
321
322
323
324
...
327
328
329
330
331
332
333
334
335
...
566
567
568
569
570
571
572
0
@@ -318,7 +318,7 @@ static void client_init(ebb_client *client)
0
   if(!client->open) {
0
     /* DO SOCKET STUFF */
0
     socklen_t len;
0
- int fd = accept(client->server->fd, (struct sockaddr*)&(client->server->sockaddr), &len);
0
+ int fd = accept(client->server->fd, (struct sockaddr*)&(client->sockaddr), &len);
0
     if(fd < 0) {
0
       perror("accept()");
0
       return;
0
@@ -327,6 +327,9 @@ static void client_init(ebb_client *client)
0
     client->fd = fd;
0
   }
0
   
0
+ /* Address */
0
+ client->ip = inet_ntoa(client->sockaddr.sin_addr);
0
+
0
   set_nonblock(client->fd);
0
   
0
   /* INITIALIZE http_parser */
0
@@ -563,6 +566,7 @@ void ebb_client_close(ebb_client *client)
0
       client->upload_file = NULL;
0
       client->upload_filename = NULL;
0
     }
0
+ client->ip = NULL;
0
     
0
     close(client->fd);
0
     client->open = FALSE;
...
42
43
44
45
 
46
47
48
...
42
43
44
 
45
46
47
48
0
@@ -42,7 +42,7 @@ struct ebb_env_item {
0
 
0
 struct ebb_client {
0
   EBB_TCP_COMMON
0
-
0
+ char *ip;
0
   unsigned int in_use : 1;
0
   
0
   ebb_server *server;
...
21
22
23
 
24
25
26
...
173
174
175
 
 
 
176
177
178
...
253
254
255
 
256
257
258
...
21
22
23
24
25
26
27
...
174
175
176
177
178
179
180
181
182
...
257
258
259
260
261
262
263
0
@@ -21,6 +21,7 @@ static VALUE global_request_uri;
0
 static VALUE global_server_port;
0
 static VALUE global_content_length;
0
 static VALUE global_content_type;
0
+static VALUE global_http_client_ip;
0
 static VALUE global_http_prefix;
0
 static VALUE global_http_version;
0
 
0
@@ -173,6 +174,9 @@ VALUE client_env(VALUE _, VALUE rb_client)
0
   if(client->server->port)
0
     rb_hash_aset(env, global_server_port, rb_str_new2(client->server->port));
0
   
0
+ if(client->ip)
0
+ rb_hash_aset(env, global_http_client_ip, rb_str_new2(client->ip));
0
+
0
   rb_hash_aset(env, global_path_info, rb_hash_aref(env, global_request_path));
0
   return env;
0
 }
0
@@ -253,6 +257,7 @@ void Init_ebb_ext()
0
   DEF_GLOBAL(request_path, "REQUEST_PATH");
0
   DEF_GLOBAL(request_uri, "REQUEST_URI");
0
   DEF_GLOBAL(server_port, "SERVER_PORT");
0
+ DEF_GLOBAL(http_client_ip, "HTTP_CLIENT_IP");
0
   DEF_GLOBAL(http_prefix, "HTTP_");
0
   DEF_GLOBAL(http_version, "HTTP_VERSION");
0
   
...
45
46
47
 
48
49
50
...
45
46
47
48
49
50
51
0
@@ -45,6 +45,7 @@ class HttpParserTest < ServerTest
0
     assert_nil env['FRAGMENT']
0
     assert_nil env['QUERY_STRING']
0
     assert_equal "", env['rack.input']
0
+ assert_equal '127.0.0.1', env['HTTP_CLIENT_IP']
0
   end
0
   
0
   def test_parse_dumbfuck_headers

Comments

    No one has commented yet.