diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2017-06-06 15:28:13 -0700 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2017-06-06 15:28:13 -0700 |
| commit | 4758d5be3debd098e3ce9ba703c75269ecf6f9b1 (patch) | |
| tree | 4f899ea041a389a3e26a774ff019d4657bdcb284 /scripts | |
| parent | cfbe25de0832059d2752d6cec5f1924a40f20f17 (diff) | |
| download | bmcweb-4758d5be3debd098e3ce9ba703c75269ecf6f9b1.tar.gz bmcweb-4758d5be3debd098e3ce9ba703c75269ecf6f9b1.zip | |
incremental
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/build_web_assets.py | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/scripts/build_web_assets.py b/scripts/build_web_assets.py index 46bf199..ee04e22 100755 --- a/scripts/build_web_assets.py +++ b/scripts/build_web_assets.py @@ -24,27 +24,45 @@ CONTENT_TYPES = { CPP_MIDDLE_BUFFER = """ CROW_ROUTE(app, "{relative_path_sha1}") ([](const crow::request& req, crow::response& res) {{ {CACHE_FOREVER_HEADER} - res.add_header("ETag", "{sha1}"); - if (req.headers.count("If-None-Match") == 1) {{ - if (req.get_header_value("If-None-Match") == "{sha1}") {{ - res.code = 304; - res.end(); - return; - }} + std::string sha1("{sha1}"); + res.add_header(etag_string, sha1); + + if (req.get_header_value(if_none_match_string) == sha1) {{ + res.code = 304; + }} else {{ + res.code = 200; + // TODO, if you have a browser from the dark ages that doesn't support gzip, + // unzip it before sending based on Accept-Encoding header + res.add_header(content_encoding_string, {content_encoding}); + res.add_header(content_type_string, "{content_type}"); + + res.write(staticassets::{relative_path_escaped}); }} - - res.code = 200; - // TODO, if you have a browser from the dark ages that doesn't support gzip, - // unzip it before sending based on Accept-Encoding header - res.add_header("Content-Encoding", {content_encoding}); - res.add_header("Content-Type", "{content_type}"); - - res.write(staticassets::{relative_path_escaped}); - res.end(); }}); + """ +HPP_START_BUFFER = ("#pragma once\n" + "\n" + "#include <string>\n" + "\n" + "#include <crow/app.h>\n" + "#include <crow/http_request.h>\n" + "#include <crow/http_response.h>\n" + "\n" + "#include <crow/routing.h>\n" + "\n" + "namespace crow {\n" + "namespace webassets {\n" + "static const std::string gzip_string = \"gzip\";\n" + "static const std::string none_string = \"none\";\n" + "static const std::string if_none_match_string = \"If-None-Match\";\n" + "static const std::string content_encoding_string = \"Content-Encoding\";\n" + "static const std::string content_type_string = \"Content-Type\";\n" + "static const std::string etag_string = \"ETag\";\n" + ) + def twos_comp(val, bits): """compute the 2's compliment of int value val""" @@ -230,21 +248,7 @@ def main(): total_payload_size += len(file_content) with open(args.output.replace("cpp", "hpp"), 'w') as hpp_output: - hpp_output.write("#pragma once\n" - "\n" - "#include <string>\n" - "\n" - "#include <crow/app.h>\n" - "#include <crow/http_request.h>\n" - "#include <crow/http_response.h>\n" - "\n" - "#include <crow/routing.h>\n" - "\n" - "namespace crow {\n" - "namespace webassets {\n" - "static const std::string gzip_string = \"gzip\";\n" - "static const std::string none_string = \"none\";\n" - ) + hpp_output.write(HPP_START_BUFFER) hpp_output.write("struct staticassets {\n") for full_filepath in dependency_ordered_file_list: |

