Skip to content

Commit 15bb0ab

Browse files
authored
Merge pull request #1242 from alfred-bratterud/master
v0.10.0 final
2 parents c1e9172 + adb73b5 commit 15bb0ab

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

examples/demo_service/service.cpp

+16-19
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ std::string HTML_RESPONSE()
3030
{
3131
const int color = rand();
3232

33-
/* HTML Fonts */
34-
std::string ubuntu_medium = "font-family: \'Ubuntu\', sans-serif; font-weight: 500; ";
35-
std::string ubuntu_normal = "font-family: \'Ubuntu\', sans-serif; font-weight: 400; ";
36-
std::string ubuntu_light = "font-family: \'Ubuntu\', sans-serif; font-weight: 300; ";
37-
38-
/* HTML */
33+
// Generate some HTML
3934
std::stringstream stream;
4035
stream << "<!DOCTYPE html><html><head>"
41-
<< "<link href='https://fonts.googleapis.com/css?family=Ubuntu:500,300' rel='stylesheet' type='text/css'>"
42-
<< "</head><body>"
43-
<< "<h1 style='color: #" << std::hex << (color >> 8) << "'>"
44-
<< "<span style='"+ubuntu_medium+"'>Include</span><span style='"+ubuntu_light+"'>OS</span></h1>"
45-
<< "<h2>Now speaks TCP!</h2>"
46-
// .... generate more dynamic content
47-
<< "<p>This is improvised http, but proper stuff is in the works.</p>"
48-
<< "<footer><hr/>&copy; 2016, IncludeOS AS @ 60&deg; north</footer>"
49-
<< "</body></html>";
36+
<< "<link href='https://fonts.googleapis.com/css?family=Ubuntu:500,300'"
37+
<< "rel='stylesheet' type='text/css'> </head><body>"
38+
<< "<h1 style='color: #" << std::hex << ((color >> 8) | 0x020202)
39+
<< "; font-family: \"Arial\", sans-serif'>"
40+
<< "Include<span style='font-weight: lighter'>OS</span></h1>"
41+
<< "<h2>The C++ Unikernel</h2>"
42+
<< "<p>You have successfully booted an IncludeOS TCP service with simple http. "
43+
<< "For a more sophisticated example, take a look at "
44+
<< "<a href='https://github.com/hioa-cs/IncludeOS/tree/master/examples/acorn'>Acorn</a>.</p>"
45+
<< "<footer><hr/>&copy; 2017 IncludeOS </footer></body></html>";
5046

5147
return stream.str();
5248
}
@@ -115,8 +111,9 @@ void Service::start(const std::string&)
115111
printf("<Service> @on_read: %u bytes received.\n", n);
116112
try
117113
{
114+
std::string data{(const char*)buf.get(), n};
118115
// try to parse the request
119-
http::Request req{(const char*)buf.get(), n};
116+
http::Request req{data};
120117

121118
// handle the request, getting a matching response
122119
auto res = handle_request(req);
@@ -128,12 +125,12 @@ void Service::start(const std::string&)
128125
printf("<Service> @on_write: %u bytes written.\n", written);
129126
});
130127
}
131-
catch(...)
128+
catch(const std::exception& e)
132129
{
133-
printf("<Service> Unable to parse request.\n");
130+
printf("<Service> Unable to parse request:\n%s\n", e.what());
134131
}
135132
});
136133
});
137134

138-
printf("*** TEST SERVICE STARTED ***\n");
135+
printf("*** Basic demo service started ***\n");
139136
}

0 commit comments

Comments
 (0)