Line data Source code
1 : #include "source/server/admin/utils.h" 2 : 3 : #include "source/common/common/enum_to_int.h" 4 : #include "source/common/http/headers.h" 5 : 6 : namespace Envoy { 7 : namespace Server { 8 : namespace Utility { 9 : 10 98 : void populateFallbackResponseHeaders(Http::Code code, Http::ResponseHeaderMap& header_map) { 11 98 : header_map.setStatus(std::to_string(enumToInt(code))); 12 98 : if (header_map.ContentType() == nullptr) { 13 : // Default to text-plain if unset. 14 0 : header_map.setReferenceContentType(Http::Headers::get().ContentTypeValues.TextUtf8); 15 0 : } 16 : // Default to 'no-cache' if unset, but not 'no-store' which may break the back button. 17 98 : if (header_map.get(Http::CustomHeaders::get().CacheControl).empty()) { 18 98 : header_map.setReference(Http::CustomHeaders::get().CacheControl, 19 98 : Http::CustomHeaders::get().CacheControlValues.NoCacheMaxAge0); 20 98 : } 21 : 22 : // Under no circumstance should browsers sniff content-type. 23 98 : header_map.addReference(Http::Headers::get().XContentTypeOptions, 24 98 : Http::Headers::get().XContentTypeOptionValues.Nosniff); 25 98 : } 26 : 27 : // Helper method to get the histogram_buckets parameter. Returns false if histogram_buckets query 28 : // param is found and value is not "cumulative" or "disjoint", true otherwise. 29 : absl::Status histogramBucketsParam(const Http::Utility::QueryParamsMulti& params, 30 0 : HistogramBucketsMode& histogram_buckets_mode) { 31 0 : absl::optional<std::string> histogram_buckets_query_param = 32 0 : params.getFirstValue("histogram_buckets"); 33 0 : histogram_buckets_mode = HistogramBucketsMode::NoBuckets; 34 0 : if (histogram_buckets_query_param.has_value()) { 35 0 : if (histogram_buckets_query_param.value() == "cumulative") { 36 0 : histogram_buckets_mode = HistogramBucketsMode::Cumulative; 37 0 : } else if (histogram_buckets_query_param.value() == "disjoint") { 38 0 : histogram_buckets_mode = HistogramBucketsMode::Disjoint; 39 0 : } else if (histogram_buckets_query_param.value() == "detailed") { 40 0 : histogram_buckets_mode = HistogramBucketsMode::Detailed; 41 0 : } else if (histogram_buckets_query_param.value() != "none") { 42 0 : return absl::InvalidArgumentError( 43 0 : "usage: /stats?histogram_buckets=(cumulative|disjoint|none)\n"); 44 0 : } 45 0 : } 46 0 : return absl::OkStatus(); 47 0 : } 48 : 49 : // Helper method to get the format parameter. 50 0 : absl::optional<std::string> formatParam(const Http::Utility::QueryParamsMulti& params) { 51 0 : return params.getFirstValue("format"); 52 0 : } 53 : 54 : } // namespace Utility 55 : } // namespace Server 56 : } // namespace Envoy