@@ -30,23 +30,19 @@ std::string HTML_RESPONSE()
30
30
{
31
31
const int color = rand ();
32
32
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
39
34
std::stringstream stream;
40
35
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/>© 2016, IncludeOS AS @ 60° 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/>© 2017 IncludeOS </footer></body></html>" ;
50
46
51
47
return stream.str ();
52
48
}
@@ -115,8 +111,9 @@ void Service::start(const std::string&)
115
111
printf (" <Service> @on_read: %u bytes received.\n " , n);
116
112
try
117
113
{
114
+ std::string data{(const char *)buf.get (), n};
118
115
// try to parse the request
119
- http::Request req{( const char *)buf. get (), n };
116
+ http::Request req{data };
120
117
121
118
// handle the request, getting a matching response
122
119
auto res = handle_request (req);
@@ -128,12 +125,12 @@ void Service::start(const std::string&)
128
125
printf (" <Service> @on_write: %u bytes written.\n " , written);
129
126
});
130
127
}
131
- catch (... )
128
+ catch (const std:: exception & e )
132
129
{
133
- printf (" <Service> Unable to parse request. \n " );
130
+ printf (" <Service> Unable to parse request: \n %s \n " , e. what () );
134
131
}
135
132
});
136
133
});
137
134
138
- printf (" *** TEST SERVICE STARTED ***\n " );
135
+ printf (" *** Basic demo service started ***\n " );
139
136
}
0 commit comments