aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de>2013-03-12 20:13:53 +0100
committerWolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de>2013-03-12 20:13:53 +0100
commit5ff179fad970eb0a878a27511d6c90419bac2cdf (patch)
tree1d639f92585d55831353115ef607dd899dc9930e /test
parent62d44c3e46f63c891b18d05be5fbfa3c4a57feb5 (diff)
downloadlitheweb-5ff179fad970eb0a878a27511d6c90419bac2cdf.tar.gz
litheweb-5ff179fad970eb0a878a27511d6c90419bac2cdf.tar.bz2
Tue Mar 12 20:13:53 CET 2013
Diffstat (limited to 'test')
-rw-r--r--test/bsd_socket.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/test/bsd_socket.c b/test/bsd_socket.c
index d4bd5a2..39f601d 100644
--- a/test/bsd_socket.c
+++ b/test/bsd_socket.c
@@ -80,6 +80,11 @@ int bsdsock_putch(char ch, void *data)
return bsdsock_write(1, &ch, data);
}
+int bsdsock_flush(void* data)
+{
+ return 0;
+}
+
int sockfd = -1;
void bye(void)
@@ -97,29 +102,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/vnd.microsoft.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);
@@ -170,10 +202,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 }