-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11fa760
commit 6b65d38
Showing
5 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local ox = require'ox' | ||
local PORT = 9094 | ||
print(PORT) | ||
print(ox.tcpserv(PORT, function(c) | ||
return ox.readln(c, 2048, function(c, line) | ||
return ox.write(c, 'HTTP/1.1 200 OK\r\n\r\nHello World\r\n', ox.close) | ||
end) | ||
end)) | ||
|
||
ox.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
print 'this test requires apache bench!' | ||
|
||
local ox = require 'ox' | ||
local http = require 'ox.http' | ||
local PORT = ... or 8092 | ||
local http = require'ox.http' | ||
local PORT = ... or 8093 | ||
local N = 10000 | ||
local test = 'ab -c 1000 -n '..N..' http://localhost:'..PORT..'/' | ||
local testline = 'GET / HTTP/1.0' | ||
|
||
local tc = table.concat | ||
http.route '*' '*' '*' (function(c, host, method, path) | ||
--print(host, method, path) | ||
local body = ('Host: %s\nMethod: %s\nPath: %s\n'):format(host, method, path) | ||
return http.reply(c, 200, body) | ||
end) | ||
|
||
print(ox.tcpserv(PORT, http.accept)) | ||
print(PORT) | ||
ox.start() | ||
assert(ox.tcpserv(PORT, http.accept)) | ||
|
||
local p | ||
ox.at(ox.time + 3, function() | ||
local results = p:read(480) | ||
local n = results:match 'Complete requests:%s+(%d+)' | ||
assert(n, 'Could not parse complete requests from apache bench') | ||
assert(tonumber(n) == N, 'Complete requests not equal to N') | ||
p:close() | ||
ox.stop() | ||
end) | ||
|
||
ox.start(function() | ||
p = assert(io.popen(test), 'Could not open apache bench') | ||
end) | ||
|
||
print 'pass' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local ox = require 'ox' | ||
local http = require 'ox.http' | ||
local PORT = 9090 | ||
|
||
|
||
print('1 readln, no parsing', PORT) | ||
print(ox.tcpserv(PORT, function(c) | ||
return ox.readln(c, 2048, function(c, line) | ||
return ox.write(c, 'HTTP/1.1 200 OK\r\n\r\nHello World\r\n', ox.close) | ||
end) | ||
end)) | ||
|
||
print('full parsing', PORT+1) | ||
print(ox.tcpserv(PORT+2, function(c) | ||
return http.readreq(c, function(c) | ||
c.res = {jar={},head={}} | ||
return http.reply(c, 200, 'Hello World') | ||
end) | ||
end)) | ||
|
||
|
||
print('fill parsing + routing', PORT+2) | ||
http.route '*' '*' '*' (function(c) | ||
return c:reply(200, 'Hello World') | ||
end) | ||
|
||
print(ox.tcpserv(PORT+2, http.accept)) | ||
|
||
ox.start() |