mirror of https://github.com/nealey/eris.git
get unit tests working again
This commit is contained in:
parent
451db45dad
commit
688d7c9b7e
2
CHANGES
2
CHANGES
|
@ -1,4 +1,4 @@
|
|||
2:
|
||||
2.0:
|
||||
Remove Accept header parsing: it was broken and the result was
|
||||
that the Accept header had no effect
|
||||
Remove the .gz trick: I never used it, but I would not be averse
|
||||
|
|
8
eris.c
8
eris.c
|
@ -668,8 +668,6 @@ header(char *buf, int buflen, const char *hname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *mimetype;
|
||||
|
||||
static struct mimeentry {
|
||||
const char *name,
|
||||
*type;
|
||||
|
@ -931,7 +929,6 @@ doit(char *headerbuf, size_t headerlen, char *url)
|
|||
|
||||
while (url[0] == '/')
|
||||
++url;
|
||||
mimetype = getmimetype(url);
|
||||
if ((fd = open(url, O_RDONLY)) >= 0) {
|
||||
if (fstat(fd, &st))
|
||||
goto bad;
|
||||
|
@ -1747,9 +1744,8 @@ main(int argc, char *argv[], const char *const *envp)
|
|||
fputs("HTTP/1.0 206 Partial Content\r\n", stdout);
|
||||
else
|
||||
fputs("HTTP/1.0 200 OK\r\n", stdout);
|
||||
fputs("Server: " FNORD "\r\nContent-Type: ", stdout);
|
||||
fputs(mimetype, stdout);
|
||||
fputs("\r\n", stdout);
|
||||
printf("Server: %s\r\n", FNORD);
|
||||
printf("Content-Type: %s\r\n", getmimetype(url));
|
||||
switch (keepalive) {
|
||||
case -1:
|
||||
fputs("Connection: close\r\n", stdout);
|
||||
|
|
|
@ -20,7 +20,7 @@ class NewlineTests(LinesTests):
|
|||
|
||||
p = eris()
|
||||
so, se = p.communicate(b'GET / HTTP/1.0\n\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 6 127.0.0.1 (null) (null) /index.html\n')
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ class ArgTests(LinesTests):
|
|||
def check_index(self, *args):
|
||||
p = eris(*args)
|
||||
so, se = p.communicate(b'GET / HTTP/1.0\r\n\r\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 6 127.0.0.1 (null) (null) /index.html\n')
|
||||
|
||||
def testArgs(self):
|
||||
|
@ -42,7 +42,7 @@ class ArgTests(LinesTests):
|
|||
def testPortAppend(self):
|
||||
p = eris('-p')
|
||||
so, se = p.communicate(b'GET / HTTP/1.0\r\n\r\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertRegexpMatches(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: (Mon|Tue|Wed|Thu|Fri|Sat|Sun), .. (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) 2... ..:..:.. GMT\r\n\r\njames\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 6 127.0.0.1:80 (null) (null) /index.html\n')
|
||||
|
||||
def testBadArgs(self):
|
||||
|
@ -75,18 +75,18 @@ class DirTests(BasicTests):
|
|||
|
||||
def testRootDir(self):
|
||||
so, se = self.get('/', 'empty')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Directory Listing: /</h3>\n<pre>\n</pre>\n')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Directory Listing: /</h3>\n<pre>\n</pre>\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 32 empty (null) (null) /\n')
|
||||
|
||||
def testNoTrailingSlash(self):
|
||||
so, se = self.get('/files', 'default')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 404 Not Found\r\nConnection: close\r\nContent-Length: 50\r\nContent-Type: text/html\r\n\r\n<title>Not Found</title>No such file or directory.')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 404 Not Found\r\nConnection: close\r\nContent-Length: 67\r\nContent-Type: text/html\r\n\r\n<title>No such file or directory.</title>No such file or directory.')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 404 0 default (null) (null) /files\n')
|
||||
|
||||
def testFiles(self):
|
||||
so, se = self.get('/files/', 'default')
|
||||
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Directory Listing: /files/</h3>\n<pre>\n<a href="/">Parent directory</a>\n[TXT] <a href="1.txt">1.txt</a>\n</pre>\n')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Directory Listing: /files/</h3>\n<pre>\n<a href="/">Parent directory</a>\n[TXT] <a href="1.txt">1.txt</a>\n</pre>\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 110 default (null) (null) /files/\n')
|
||||
|
||||
|
||||
|
@ -96,18 +96,18 @@ class CGITests(BasicTests):
|
|||
|
||||
def testSet(self):
|
||||
so, se = self.get('/cgi/set.cgi', 'default')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\n')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 242 default (null) (null) /cgi/set.cgi\n')
|
||||
|
||||
def testSetArgs(self):
|
||||
so, se = self.get('/cgi/set.cgi?a=1&b=2&c=3', 'default')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nQUERY_STRING:a=1&b=2&c=3\n')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nQUERY_STRING:a=1&b=2&c=3\n')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 267 default (null) (null) /cgi/set.cgi\n')
|
||||
|
||||
def testPost(self):
|
||||
so, se = self.post('/cgi/set.cgi', 'default', 'a=1&b=2&c=3')
|
||||
self.assertLinesEqual(se, b'10.1.2.3 200 330 default (null) (null) /cgi/set.cgi\n')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:POST\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nCONTENT_TYPE:application/x-www-form-urlencoded\nCONTENT_LENGTH:11\nForm data: a=1&b=2&c=3')
|
||||
self.assertLinesEqual(so, b'HTTP/1.0 200 OK\r\nServer: eris/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:eris/2\nSERVER_NAME:default\nSERVER_PORT:80\nREQUEST_METHOD:POST\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nCONTENT_TYPE:application/x-www-form-urlencoded\nCONTENT_LENGTH:11\nForm data: a=1&b=2&c=3')
|
||||
|
||||
# XXX: Test posting to static html with keepalive
|
||||
# (it probably won't discard content-length octets)
|
||||
|
|
Loading…
Reference in New Issue