diff options
author | Wolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de> | 2013-06-28 18:14:16 +0200 |
---|---|---|
committer | Wolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de> | 2013-06-28 18:14:16 +0200 |
commit | f9cc5128f5e9eb726b8562d33067ddce6d65385c (patch) | |
tree | 18c2039d9e4c893a9cf244e379b6a8aba5db8d3c /test | |
parent | ffa2fc800d92b40f4a128814ae55b121a7852e58 (diff) | |
download | litheweb-f9cc5128f5e9eb726b8562d33067ddce6d65385c.tar.gz litheweb-f9cc5128f5e9eb726b8562d33067ddce6d65385c.tar.bz2 |
multipart code works
Diffstat (limited to 'test')
-rw-r--r-- | test/bsdsocket.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/test/bsdsocket.c b/test/bsdsocket.c index 9665e1a..e090054 100644 --- a/test/bsdsocket.c +++ b/test/bsdsocket.c @@ -107,12 +107,13 @@ void rhRoot(struct picohttpRequest *req) char http_test[] = "<html><head><title>handling request /</title></head><body>\n" -"<a href=\"/test\">/test</a>" -"<form action=\"/upload\" enctype=\"multipart/form-data\" method=\"post\">" -"<label for=\"file1\">File: </label><input type=\"file\" name=\"file1\"></input>" -"<label for=\"file2\">File: </label><input type=\"file\" name=\"file2\"></input>" -"<input type=\"submit\" value=\"Upload\"></input>" -"</form>" +"<a href=\"/test\">/test</a>\n" +"<form action=\"/upload\" enctype=\"multipart/form-data\" method=\"post\">\n" +"<label for=\"name\">Name: </label><input type=\"text\" name=\"name\"></input><br/>\n" +"<label for=\"file1\">File: </label><input type=\"file\" name=\"file1\"></input><br/>\n" +"<label for=\"file2\">File: </label><input type=\"file\" name=\"file2\"></input><br/>\n" +"<input type=\"submit\" value=\"Upload\"></input>\n" +"</form>\n" "</body></html>\n"; picohttpResponseWrite(req, sizeof(http_test)-1, http_test); @@ -141,8 +142,21 @@ void rhUpload(struct picohttpRequest *req) char http_test[] = "handling request /upload"; - struct picohttpMultipart mp; - picohttpMultipartNext(req, &mp); + struct picohttpMultipart mp = picohttpMultipartStart(req); + + while( !picohttpMultipartNext(&mp) ) { + fprintf(stderr, "processing form field \"%s\"\n", mp.disposition.name); + for(int16_t ch = picohttpMultipartGetch(&mp); + 0 <= ch; + ch = picohttpMultipartGetch(&mp) ) { + fputc(ch, stderr); + } + if( !mp.finished ) { + break; + } + } + if( !mp.finished ) { + } picohttpResponseWrite(req, sizeof(http_test)-1, http_test); if(req->urltail) { @@ -206,7 +220,7 @@ int main(int argc, char *argv[]) struct picohttpURLRoute routes[] = { { "/test", 0, rhTest, 16, PICOHTTP_METHOD_GET }, - { "/upload|", 0, rhUpload, 0, PICOHTTP_METHOD_GET }, + { "/upload", 0, rhUpload, 16, PICOHTTP_METHOD_POST }, { "/|", 0, rhRoot, 0, PICOHTTP_METHOD_GET }, { NULL, 0, 0, 0, 0 } }; |