From 2d7dbb1f3f5e670b13767e4623ab6459dd35eba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kesson?= Date: Tue, 14 Mar 2017 12:00:22 +0100 Subject: [PATCH 1/2] examples: Fixed bug in demo_service --- examples/demo_service/service.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/demo_service/service.cpp b/examples/demo_service/service.cpp index 49e8e44298..2c5eafe1b4 100644 --- a/examples/demo_service/service.cpp +++ b/examples/demo_service/service.cpp @@ -115,8 +115,9 @@ void Service::start(const std::string&) printf(" @on_read: %u bytes received.\n", n); try { + std::string data{(const char*)buf.get(), n}; // try to parse the request - http::Request req{(const char*)buf.get(), n}; + http::Request req{data}; // handle the request, getting a matching response auto res = handle_request(req); @@ -128,9 +129,9 @@ void Service::start(const std::string&) printf(" @on_write: %u bytes written.\n", written); }); } - catch(...) + catch(const std::exception& e) { - printf(" Unable to parse request.\n"); + printf(" Unable to parse request:\n%s\n", e.what()); } }); }); From adb73b5effa3abb927b11bda4cb5b0013dc17860 Mon Sep 17 00:00:00 2001 From: Alfred Bratterud Date: Thu, 16 Mar 2017 12:11:45 +0100 Subject: [PATCH 2/2] Demo-service updates --- examples/demo_service/service.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/demo_service/service.cpp b/examples/demo_service/service.cpp index 2c5eafe1b4..d19e6bb99e 100644 --- a/examples/demo_service/service.cpp +++ b/examples/demo_service/service.cpp @@ -30,23 +30,19 @@ std::string HTML_RESPONSE() { const int color = rand(); - /* HTML Fonts */ - std::string ubuntu_medium = "font-family: \'Ubuntu\', sans-serif; font-weight: 500; "; - std::string ubuntu_normal = "font-family: \'Ubuntu\', sans-serif; font-weight: 400; "; - std::string ubuntu_light = "font-family: \'Ubuntu\', sans-serif; font-weight: 300; "; - - /* HTML */ + // Generate some HTML std::stringstream stream; stream << "" - << "" - << "" - << "

" - << "IncludeOS

" - << "

Now speaks TCP!

" - // .... generate more dynamic content - << "

This is improvised http, but proper stuff is in the works.

" - << "

© 2016, IncludeOS AS @ 60° north
" - << ""; + << " " + << "

" + << "IncludeOS

" + << "

The C++ Unikernel

" + << "

You have successfully booted an IncludeOS TCP service with simple http. " + << "For a more sophisticated example, take a look at " + << "Acorn.

" + << ""; return stream.str(); } @@ -136,5 +132,5 @@ void Service::start(const std::string&) }); }); - printf("*** TEST SERVICE STARTED ***\n"); + printf("*** Basic demo service started ***\n"); }