aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-03-14 12:11:19 +0100
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-03-14 12:11:19 +0100
commit15fdfef7f3556e681ab0ca69ad603cac30eb2008 (patch)
tree889d649a53e2a999a289a60c92a7ef179e1c11c4 /test
parentdb106357956d84283dc85ea3e47d512da5113db3 (diff)
parent695008f9d18220e9d9c2558129ffcd4db15d2a26 (diff)
downloadlitheweb-15fdfef7f3556e681ab0ca69ad603cac30eb2008.tar.gz
litheweb-15fdfef7f3556e681ab0ca69ad603cac30eb2008.tar.bz2
Merge branch 'master' of github.com:datenwolf/picoweb
Diffstat (limited to 'test')
-rw-r--r--test/bufbsdsocket.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/test/bufbsdsocket.c b/test/bufbsdsocket.c
index 27ce6ef..97c3526 100644
--- a/test/bufbsdsocket.c
+++ b/test/bufbsdsocket.c
@@ -119,6 +119,11 @@ int bufbsdsock_flush(void *data)
return 0;
}
+int bsdsock_flush(void* data)
+{
+ return 0;
+}
+
int sockfd = -1;
void bye(void)
@@ -136,29 +141,56 @@ void rhRoot(struct picohttpRequest *req)
{
fprintf(stderr, "handling request /%s\n", req->urltail);
- char http_header[] = "HTTP/x.x 200 OK\r\nServer: picoweb\r\nContent-Type: text/html\r\n\r\n";
- http_header[5] = '0'+req->httpversion.major;
- http_header[7] = '0'+req->httpversion.minor;
- picohttpIoWrite(req->ioops, sizeof(http_header)-1, http_header);
+ req->response.contenttype = "text/html";
+
char http_test[] = "<html><head><title>handling request /</title></head>\n<body><a href=\"/test\">/test</a></body></html>\n";
- picohttpIoWrite(req->ioops, sizeof(http_test)-1, http_test);
+ picohttpResponseWrite(req, sizeof(http_test)-1, http_test);
}
void rhTest(struct picohttpRequest *req)
{
fprintf(stderr, "handling request /test%s\n", req->urltail);
- char http_header[] = "HTTP/x.x 200 OK\r\nServer: picoweb\r\nContent-Type: text/text\r\n\r\n";
- http_header[5] = '0'+req->httpversion.major;
- http_header[7] = '0'+req->httpversion.minor;
- picohttpIoWrite(req->ioops, sizeof(http_header)-1, http_header);
+
char http_test[] = "handling request /test";
- picohttpIoWrite(req->ioops, sizeof(http_test)-1, http_test);
+ picohttpResponseWrite(req, sizeof(http_test)-1, http_test);
if(req->urltail) {
- picohttpIoWrite(req->ioops, strlen(req->urltail), req->urltail);
+ picohttpResponseWrite(req, strlen(req->urltail), req->urltail);
}
}
+static uint8_t const favicon_ico[] = {
+0x00,0x00,0x01,0x00,0x01,0x00,0x10,0x10,0x10,0x00,0x01,0x00,0x04,0x00,0x28,0x01,
+0x00,0x00,0x16,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x20,0x00,
+0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x09,
+0x06,0x00,0x21,0x23,0x22,0x00,0x48,0x4a,0x48,0x00,0x70,0x73,0x71,0x00,0x8d,0x90,
+0x8e,0x00,0xb4,0xb7,0xb5,0x00,0xd8,0xdc,0xda,0x00,0xfc,0xff,0xfd,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x77,
+0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x76,0x06,0x76,0x06,0x77,0x77,0x77,
+0x77,0x74,0x04,0x74,0x04,0x77,0x77,0x77,0x77,0x72,0x42,0x72,0x42,0x77,0x77,0x77,
+0x77,0x71,0x70,0x70,0x71,0x77,0x70,0x77,0x77,0x52,0x72,0x32,0x72,0x57,0x70,0x77,
+0x77,0x34,0x74,0x04,0x74,0x37,0x70,0x77,0x77,0x16,0x76,0x06,0x76,0x17,0x70,0x40,
+0x03,0x77,0x77,0x77,0x77,0x77,0x70,0x26,0x62,0x37,0x77,0x77,0x77,0x77,0x70,0x67,
+0x76,0x17,0x77,0x77,0x77,0x77,0x70,0x77,0x77,0x07,0x77,0x77,0x77,0x77,0x70,0x67,
+0x76,0x17,0x77,0x77,0x77,0x77,0x70,0x26,0x62,0x37,0x77,0x77,0x77,0x77,0x70,0x40,
+0x03,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};
+
+void rhFavicon(struct picohttpRequest *req)
+{
+ fprintf(stderr, "handling request /favicon.ico\n");
+
+ req->response.contenttype = "image/x-icon";
+ req->response.contentlength = sizeof(favicon_ico);
+ picohttpResponseWrite(req, sizeof(favicon_ico), favicon_ico);
+}
+
int main(int argc, char *argv[])
{
sockfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -209,10 +241,12 @@ int main(int argc, char *argv[])
.write = bsdsock_write,
.getch = bsdsock_getch,
.putch = bsdsock_putch,
+ .flush = bsdsock_flush,
.data = &confd
};
struct picohttpURLRoute routes[] = {
+ {"/favicon.ico|", 0, rhFavicon, 0, PICOHTTP_METHOD_GET},
{ "/test", 0, rhTest, 16, PICOHTTP_METHOD_GET },
{ "/|", 0, rhRoot, 0, PICOHTTP_METHOD_GET },
{ NULL, 0, 0, 0, 0 }