int Http2Handler::submit_push_promise(Stream *stream,
                                      const StringRef &push_path) {
  auto authority = stream->header.authority;

  if (authority.empty()) {
    authority = stream->header.host;
  }

  auto scheme = get_config()->no_tls ? StringRef::from_lit("http")
                                     : StringRef::from_lit("https");

  auto nva = make_array(http2::make_nv_ll(":method", "GET"),
                        http2::make_nv_ls_nocopy(":path", push_path),
                        http2::make_nv_ls_nocopy(":scheme", scheme),
                        http2::make_nv_ls_nocopy(":authority", authority));

  auto promised_stream_id = nghttp2_submit_push_promise(
      session_, NGHTTP2_FLAG_END_HEADERS, stream->stream_id, nva.data(),
      nva.size(), nullptr);

  if (promised_stream_id < 0) {
    return promised_stream_id;
  }

  auto promised_stream = std::make_unique<Stream>(this, promised_stream_id);

  auto &promised_header = promised_stream->header;
  promised_header.method = StringRef::from_lit("GET");
  promised_header.path = push_path;
  promised_header.scheme = scheme;
  promised_header.authority =
      make_string_ref(promised_stream->balloc, authority);

  add_stream(promised_stream_id, std::move(promised_stream));

  return 0;
}
int Http2Handler::submit_push_promise(Stream *stream,
                                      const StringRef &push_path) {
  auto authority = stream->header.authority;

  if (authority.empty()) {
    authority = stream->header.host;
  }

  auto scheme = get_config()->no_tls ? StringRef::from_lit("http")
                                     : StringRef::from_lit("https");

  auto nva = make_array(http2::make_nv_ll(":method", "GET"),
                        http2::make_nv_ls_nocopy(":path", push_path),
                        http2::make_nv_ls_nocopy(":scheme", scheme),
                        http2::make_nv_ls_nocopy(":authority", authority));

  auto promised_stream_id = nghttp2_submit_push_promise(
      session_, NGHTTP2_FLAG_END_HEADERS, stream->stream_id, nva.data(),
      nva.size(), nullptr);

  if (promised_stream_id < 0) {
    return promised_stream_id;
  }

  auto promised_stream = std::make_unique<Stream>(this, promised_stream_id);

  auto &promised_header = promised_stream->header;
  promised_header.method = StringRef::from_lit("GET");
  promised_header.path = push_path;
  promised_header.scheme = scheme;
  promised_header.authority =
      make_string_ref(promised_stream->balloc, authority);

  add_stream(promised_stream_id, std::move(promised_stream));

  return 0;
}