diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index 8ac787a0..32d508f0 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -122,6 +122,15 @@ void capitalize(std::string& s, size_t offset) } } +void sanitize_header_value(std::string& s, size_t offset) +{ + for(size_t i = offset, eoi = s.size(); i < eoi; ++i) { + if(s[i] == '\r' || s[i] == '\n') { + s[i] = ' '; + } + } +} + std::string colorizeHeaders(const char *hdrs) { std::string nhdrs; diff --git a/src/shrpx_http.h b/src/shrpx_http.h index 61b05235..e5732c70 100644 --- a/src/shrpx_http.h +++ b/src/shrpx_http.h @@ -41,6 +41,8 @@ std::string create_via_header_value(int major, int minor); void capitalize(std::string& s, size_t offset); +void sanitize_header_value(std::string& s, size_t offset); + // Adds ANSI color codes to HTTP headers |hdrs|. std::string colorizeHeaders(const char *hdrs); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 4e7413c2..68fcc9c3 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -160,6 +160,7 @@ int HttpDownstreamConnection::push_request_headers() http::capitalize(hdrs, hdrs.size()-(*i).first.size()); hdrs += ": "; hdrs += (*i).second; + http::sanitize_header_value(hdrs, hdrs.size()-(*i).second.size()); hdrs += "\r\n"; } if(downstream_->get_request_connection_close()) {