Browse Source

Add Content-Type headers according to the TFB specifications.

Matthieu Garrigues 10 years ago
parent
commit
1664671642
2 changed files with 14 additions and 9 deletions
  1. 1 3
      frameworks/C++/silicon/CMakeLists.txt
  2. 13 6
      frameworks/C++/silicon/main.cc

+ 1 - 3
frameworks/C++/silicon/CMakeLists.txt

@@ -4,10 +4,8 @@ project(silicon)
 
 
 include_directories($ENV{IROOT}/include)
 include_directories($ENV{IROOT}/include)
 
 
-set(CMAKE_VERBOSE_MAKEFILE ON)
-
 link_directories($ENV{IROOT}/lib)
 link_directories($ENV{IROOT}/lib)
-add_definitions(-std=c++14  -ftemplate-depth=1024 -DNDEBUG -O3)
+add_definitions(-std=c++14  -ftemplate-depth=512 -DNDEBUG -O3)
 
 
 add_executable(silicon_tpc_mysql main.cc)
 add_executable(silicon_tpc_mysql main.cc)
 target_link_libraries(silicon_tpc_mysql microhttpd mysqlclient)
 target_link_libraries(silicon_tpc_mysql microhttpd mysqlclient)

+ 13 - 6
frameworks/C++/silicon/main.cc

@@ -50,13 +50,17 @@ int main(int argc, char* argv[])
   
   
   auto hello_api = make_api(
   auto hello_api = make_api(
 
 
-    _plaintext = [] () { return "Hello, World!"; },
-    _json = [] () { return D(_message = "Hello, World!"); },
+    _plaintext = [] () { return response(_content_type = "text/plain",
+                                         _body = "Hello, World!"); },
 
 
+    _json = [] () { return response(_content_type = "application/json",
+                                    _body = D(_message = "Hello, World!")); },
+                        
     _db = [] (rn_orm& orm) {
     _db = [] (rn_orm& orm) {
       random_number r;
       random_number r;
       orm.find_by_id(1245, r);
       orm.find_by_id(1245, r);
-      return r;
+      return response(_content_type = "application/json",
+                      _body = r);
     },
     },
 
 
     _queries = [] (rn_orm& orm, get_parameters& get_params) {
     _queries = [] (rn_orm& orm, get_parameters& get_params) {
@@ -66,7 +70,8 @@ int main(int argc, char* argv[])
       std::vector<random_number> qs(N);
       std::vector<random_number> qs(N);
       for (int i = 0; i < N; i++)
       for (int i = 0; i < N; i++)
         orm.find_by_id(1 + rand() % 9999, qs[i]);
         orm.find_by_id(1 + rand() % 9999, qs[i]);
-      return std::move(qs);
+      return response(_content_type = "application/json",
+                      _body = std::move(qs));
     },
     },
 
 
     _updates = [] (rn_orm& orm, get_parameters& get_params) {
     _updates = [] (rn_orm& orm, get_parameters& get_params) {
@@ -80,7 +85,8 @@ int main(int argc, char* argv[])
         qs[i].randomNumber = 1 + rand() % 9999;
         qs[i].randomNumber = 1 + rand() % 9999;
         orm.update(qs[i]);
         orm.update(qs[i]);
       }
       }
-      return std::move(qs);
+      return response(_content_type = "application/json",
+                      _body = std::move(qs));
     },
     },
   
   
     _fortunes = [] (fortune_orm& orm) {
     _fortunes = [] (fortune_orm& orm) {
@@ -98,7 +104,8 @@ int main(int argc, char* argv[])
         ss << "<tr><td>" << f.id << "</td><td>" << escape_html_entities(f.message) << "</td></tr>";
         ss << "<tr><td>" << f.id << "</td><td>" << escape_html_entities(f.message) << "</td></tr>";
       ss << "</table></body></html>";
       ss << "</table></body></html>";
 
 
-      return ss.str();
+      return response(_content_type = "text/html",
+                      _body = ss.str());
     }
     }
   
   
     ).bind_factories(
     ).bind_factories(