Skip to content

Commit

Permalink
Merge pull request #1242 from alfred-bratterud/master
Browse files Browse the repository at this point in the history
v0.10.0 final
  • Loading branch information
alfreb authored Mar 16, 2017
2 parents c1e9172 + adb73b5 commit 15bb0ab
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions examples/demo_service/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "<!DOCTYPE html><html><head>"
<< "<link href='https://fonts.googleapis.com/css?family=Ubuntu:500,300' rel='stylesheet' type='text/css'>"
<< "</head><body>"
<< "<h1 style='color: #" << std::hex << (color >> 8) << "'>"
<< "<span style='"+ubuntu_medium+"'>Include</span><span style='"+ubuntu_light+"'>OS</span></h1>"
<< "<h2>Now speaks TCP!</h2>"
// .... generate more dynamic content
<< "<p>This is improvised http, but proper stuff is in the works.</p>"
<< "<footer><hr/>&copy; 2016, IncludeOS AS @ 60&deg; north</footer>"
<< "</body></html>";
<< "<link href='https://fonts.googleapis.com/css?family=Ubuntu:500,300'"
<< "rel='stylesheet' type='text/css'> </head><body>"
<< "<h1 style='color: #" << std::hex << ((color >> 8) | 0x020202)
<< "; font-family: \"Arial\", sans-serif'>"
<< "Include<span style='font-weight: lighter'>OS</span></h1>"
<< "<h2>The C++ Unikernel</h2>"
<< "<p>You have successfully booted an IncludeOS TCP service with simple http. "
<< "For a more sophisticated example, take a look at "
<< "<a href='https://github.com/hioa-cs/IncludeOS/tree/master/examples/acorn'>Acorn</a>.</p>"
<< "<footer><hr/>&copy; 2017 IncludeOS </footer></body></html>";

return stream.str();
}
Expand Down Expand Up @@ -115,8 +111,9 @@ void Service::start(const std::string&)
printf("<Service> @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);
Expand All @@ -128,12 +125,12 @@ void Service::start(const std::string&)
printf("<Service> @on_write: %u bytes written.\n", written);
});
}
catch(...)
catch(const std::exception& e)
{
printf("<Service> Unable to parse request.\n");
printf("<Service> Unable to parse request:\n%s\n", e.what());
}
});
});

printf("*** TEST SERVICE STARTED ***\n");
printf("*** Basic demo service started ***\n");
}

0 comments on commit 15bb0ab

Please sign in to comment.