From 7897f5b94bc59fa59d3e1a71b015060a37ef2b0d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 21 Feb 2015 00:06:05 +0900 Subject: [PATCH] asio-lib: Remove validation offered by nghttp2 lib --- src/asio_http2_handler.cc | 61 +++++++++------------------------------ 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/src/asio_http2_handler.cc b/src/asio_http2_handler.cc index f491e320..fb8c6a2b 100644 --- a/src/asio_http2_handler.cc +++ b/src/asio_http2_handler.cc @@ -336,54 +336,25 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame, return 0; } - if (!nghttp2_check_header_name(name, namelen) || - !nghttp2_check_header_value(value, valuelen)) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } - auto &req = stream->get_request()->impl(); - if (name[0] == ':' && !req.headers().empty()) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } - - if (util::streq_l(":method", name, namelen)) { - if (!req.method().empty()) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } + switch (nghttp2::http2::lookup_token(name, namelen)) { + case nghttp2::http2::HD__METHOD: req.method(std::string(value, value + valuelen)); - } else if (util::streq_l(":scheme", name, namelen)) { - if (!req.scheme().empty()) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } + break; + case nghttp2::http2::HD__SCHEME: req.scheme(std::string(value, value + valuelen)); - } else if (util::streq_l(":authority", name, namelen)) { - if (!req.authority().empty()) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } + break; + case nghttp2::http2::HD__AUTHORITY: req.authority(std::string(value, value + valuelen)); - } else if (util::streq_l(":path", name, namelen)) { - if (!req.path().empty()) { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } + break; + case nghttp2::http2::HD__PATH: req.path(std::string(value, value + valuelen)); - } else { - if (name[0] == ':') { - stream_error(session, stream_id, NGHTTP2_PROTOCOL_ERROR); - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; - } - - if (util::streq_l("host", name, namelen)) { - req.host(std::string(value, value + valuelen)); - } - + break; + case nghttp2::http2::HD_HOST: + req.host(std::string(value, value + valuelen)); + // fall through + default: req.add_header(std::string(name, name + namelen), std::string(value, value + valuelen)); } @@ -416,12 +387,6 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, auto &req = stream->get_request()->impl(); - if (req.method().empty() || req.scheme().empty() || req.path().empty() || - (req.authority().empty() && req.host().empty())) { - stream_error(session, frame->hd.stream_id, NGHTTP2_PROTOCOL_ERROR); - return 0; - } - if (req.host().empty()) { req.host(req.authority()); }