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
removing old files
Ryan Dahl (author)
2 months ago
commit  9bccca53b6ae1533edf3211ad0ba83a48ed9b5a9
tree    a658a2fc4b9d92df6e72291c32dfc17cb24c23f7
parent  6b67ca61e0da5ad0b69ee5aff0a116ca5c6db8d2
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
0
@@ -1,30 +0,0 @@
0
-# Stand alone Makefile
0
-# Not used when compiling from ruby binding
0
-
0
-GLIB_CFLAGS = `pkg-config --cflags glib-2.0`
0
-GLIB_LIBS = `pkg-config --libs glib-2.0`
0
-
0
-LIBEV_PREFIX = /opt/libev-2.01
0
-LIBEV_CFLAGS = -I$(LIBEV_PREFIX)/include
0
-LIBEV_LIBS = -L$(LIBEV_PREFIX)/lib -lev
0
-
0
-CC = gcc
0
-CFLAGS = -g -Wall $(GLIB_CFLAGS) $(LIBEV_CFLAGS) # -DDEBUG
0
-LIBS = $(LIBEV_LIBS) $(GLIB_LIBS) -lpthread
0
-OBJS = ebb.o parser.o
0
-EXE = ebb_test
0
-
0
-%.o : %.c Makefile
0
-  $(CC) $(CFLAGS) -c $< -o $@
0
-
0
-all: $(OBJS) $(EXE)
0
-
0
-$(EXE): $(OBJS) Makefile
0
-  $(CC) $(CFLAGS) $(OBJS) $(LIBS) $@.c -o $(EXE)
0
-
0
-parser.c: parser.rl
0
-  ragel parser.rl | rlgen-cd -G2 -o parser.c
0
-
0
-.PHONY : clean
0
-clean:
0
-  rm -f $(OBJS) $(EXE) parser.c .ruby_generated_makefile
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,55 +0,0 @@
0
-#include <stdio.h>
0
-#include <signal.h>
0
-#include <stdlib.h>
0
-#include <string.h>
0
-#include "ebb.h"
0
-
0
-
0
-void request_cb(ebb_client *client, void *data)
0
-{
0
- const char *header = "HTTP/1.1 200 OK\r\n"
0
- "Connection: close\r\n"
0
- "Content-Type: text/plain\r\n\r\n";
0
- int i;
0
- //g_message("Request");
0
- char buffer[1000];
0
-
0
- ebb_client_write(client, header, strlen(header));
0
-
0
- for(i=0; i<client->env_size; i++) {
0
- if(client->env_fields[i]) {
0
- ebb_client_write(client, client->env_fields[i], client->env_field_lengths[i]);
0
- ebb_client_write(client, "\r\n", 2);
0
- ebb_client_write(client, client->env_values[i], client->env_value_lengths[i]);
0
- ebb_client_write(client, "\r\n\r\n", 4);
0
-
0
- strncpy(buffer, client->env_fields[i], client->env_field_lengths[i]);
0
- strncpy(buffer+client->env_field_lengths[i], client->env_values[i], client->env_value_lengths[i]);
0
- buffer[client->env_field_lengths[i] + client->env_value_lengths[i] ] = '\0';
0
-
0
- printf("%s\n", buffer);
0
- }
0
- }
0
-
0
- ebb_client_write(client, "Hello.\r\n\r\n", 6);
0
-
0
- ebb_client_start_writing(client, NULL);
0
-}
0
-
0
-int main(void)
0
-{
0
- struct ev_loop *loop = ev_default_loop(0);
0
- ebb_server *server = ebb_server_alloc();
0
-
0
- ebb_server_init(server, loop, "localhost", 4001, request_cb, NULL);
0
-
0
- /* Ignore SIGPIPE */
0
- signal(SIGPIPE, SIG_IGN);
0
-
0
- fprintf(stdout, "Starting server at 0.0.0.0 4001\n");
0
-
0
- ebb_server_start(server);
0
- ev_loop(loop, 0);
0
- ebb_server_free(server);
0
- return 0; // success
0
-}
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,156 +0,0 @@
0
-require File.dirname(__FILE__) + '/../ruby_lib/ebb'
0
-require 'test/unit'
0
-require 'net/http'
0
-require 'base64'
0
-
0
-
0
-class EbbTest < Test::Unit::TestCase
0
- def setup
0
- @pid = fork do
0
- server = Ebb::Server.new(self, :port => 4044)
0
- STDOUT.reopen "/dev/null", "a"
0
- server.start
0
- end
0
- sleep 0.5
0
- end
0
-
0
- def teardown
0
- Process.kill('KILL', @pid)
0
- sleep 0.5
0
- end
0
-
0
- def get(path)
0
- Net::HTTP.get_response(URI.parse("http://0.0.0.0:4044#{path}"))
0
- end
0
-
0
- def post(path, data)
0
- Net::HTTP.post_form(URI.parse("http://0.0.0.0:4044#{path}"), data)
0
- end
0
-
0
- @@responses = {}
0
- def call(env)
0
- commands = env['PATH_INFO'].split('/')
0
-
0
- if commands.include?('bytes')
0
- n = commands.last.to_i
0
- raise "bytes called with n <= 0" if n <= 0
0
- body = @@responses[n] || "C"*n
0
- status = 200
0
-
0
- elsif commands.include?('env')
0
- env.delete('rack.input') # delete this because it's hard to marshal
0
- env.delete('rack.errors')
0
- body = Base64.encode64(Marshal.dump(env))
0
- status = 200
0
-
0
- elsif commands.include?('test_post_length')
0
- input_body = ""
0
- while chunk = env['rack.input'].read(512)
0
- input_body << chunk
0
- end
0
-
0
- content_length_header = env['HTTP_CONTENT_LENGTH'].to_i
0
-
0
- if content_length_header == input_body.length
0
- body = "Content-Length matches input length"
0
- status = 200
0
- else
0
- body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}"
0
- # content_length = #{env['HTTP_CONTENT_LENGTH'].to_i}
0
- # input_body.length = #{input_body.length}"
0
- status = 500
0
- end
0
-
0
- else
0
- status = 404
0
- body = "Undefined url"
0
- end
0
-
0
- [status, {'Content-Type' => 'text/plain'}, body]
0
- end
0
-
0
- def test_get_bytes
0
- [1,10,1000].each do |i|
0
- response = get("/bytes/#{i}")
0
- assert_equal "#{'C'*i.to_i}", response.body
0
- end
0
- end
0
-
0
- def test_get_unknown
0
- response = get('/blah')
0
- assert_equal "Undefined url", response.body
0
- end
0
-
0
- def test_small_posts
0
- [1,10,321,123,1000].each do |i|
0
- response = post("/test_post_length", 'C'*i)
0
- assert_equal 200, response.code.to_i, response.body
0
- end
0
- end
0
-
0
- # this is rough but does detect major problems
0
- def test_ab
0
- r = %x{ab -n 1000 -c 50 -q http://0.0.0.0:4044/bytes/123}
0
- assert r =~ /Requests per second:\s*(\d+)/, r
0
- assert $1.to_i > 100, r
0
- end
0
-
0
- def test_large_post
0
- [50,60,100].each do |i|
0
- response = post("/test_post_length", 'C'*1024*i)
0
- assert_equal 200, response.code.to_i, response.body
0
- end
0
- end
0
-
0
- def test_env
0
- response = get('/env')
0
- env = Marshal.load(Base64.decode64(response.body))
0
- assert_equal '/env', env['PATH_INFO']
0
- assert_equal '/env', env['REQUEST_PATH']
0
- assert_equal 'HTTP/1.1', env['SERVER_PROTOCOL']
0
- assert_equal 'CGI/1.2', env['GATEWAY_INTERFACE']
0
- assert_equal '0.0.0.0', env['SERVER_NAME']
0
- assert_equal '4044', env['SERVER_PORT']
0
- assert_equal 'GET', env['REQUEST_METHOD']
0
- end
0
-end
0
-
0
-class EbbRailsTest < Test::Unit::TestCase
0
- # just to make sure there isn't some load error
0
- def test_ebb_rails_version
0
- out = %x{ruby #{Ebb::LIBDIR}/../bin/ebb_rails -v}
0
- assert_match %r{Ebb #{Ebb::VERSION}}, out
0
- end
0
-
0
- # def get(path)
0
- # Net::HTTP.get_response(URI.parse("http://0.0.0.0:4043#{path}"))
0
- # end
0
- #
0
- # def test_starting_with_many_options
0
- # %x{cd /tmp && rails ebb_test && ruby #{Ebb::LIBDIR}/../bin/ebb_rails start -d -e development -c /tmp/ebb_test -u www -g www -P /tmp/ebb.1.pid -p 4043 &}
0
- # response = get('/')
0
- # assert_equal 200, response.code
0
- # ensure
0
- # Process.kill('KILL', %x{cat /tmp/ebb.1.pid})
0
- # end
0
-end
0
-
0
-
0
-
0
-
0
-#
0
-# class SocketTest < Test::Unit::TestCase
0
-# def test_socket_creation
0
-# filename = '/tmp/ebb.socket'
0
-# @pid = fork do
0
-# server = Ebb::Server.new(TestApp.new, {:socket => filename})
0
-# server.start
0
-# end
0
-# sleep(1)
0
-# assert File.exists?(filename)
0
-#
0
-# Process.kill('KILL', @pid)
0
-#
0
-# assert !File.exists?(filename)
0
-# end
0
-# end

Comments

    No one has commented yet.