Add http2 support to libcurl

Use nghttp2 to add http2 support to libcurl per
https://curl.se/docs/http2.html. The curl documentation indicates
we require nghttp2>=1.12.0. We build the latest release 1.58.0.

Change-Id: I9ca1a46d9af3f0d960722b722fd00b1b3157052f
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/WORKSPACE b/WORKSPACE
index 7809594..a5da525 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1433,6 +1433,14 @@
 )
 
 http_archive(
+    name = "com_github_nghttp2_nghttp2",
+    build_file = "//debian:BUILD.nghttp2.bazel",
+    sha256 = "7da19947b33a07ddcf97b9791331bfee8a8545e6b394275a9971f43cae9d636b",
+    strip_prefix = "nghttp2-1.58.0",
+    url = "https://github.com/nghttp2/nghttp2/archive/refs/tags/v1.58.0.tar.gz",
+)
+
+http_archive(
     # No official name exists.  Names used in our external dependencies include
     # zlib, madler_zlib, com_github_madler_zlib.
     name = "zlib",
diff --git a/debian/BUILD.nghttp2.bazel b/debian/BUILD.nghttp2.bazel
new file mode 100644
index 0000000..cd055cd
--- /dev/null
+++ b/debian/BUILD.nghttp2.bazel
@@ -0,0 +1,71 @@
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+
+licenses(["notice"])  # MIT/X derivative license
+
+exports_files(["COPYING"])
+
+write_file(
+    name = "nghttp2ver.h",
+    out = "lib/includes/nghttp2/nghttp2ver.h",
+    content = """
+/*
+ * nghttp2 - HTTP/2 C Library
+ *
+ * Copyright (c) 2012, 2013 Tatsuhiro Tsujikawa
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef NGHTTP2VER_H
+#define NGHTTP2VER_H
+
+/**
+ * @macro
+ * Version number of the nghttp2 library release
+ */
+#define NGHTTP2_VERSION "1.58.0"
+
+/**
+ * @macro
+ * Numerical representation of the version number of the nghttp2 library
+ * release. This is a 24 bit number with 8 bits for major number, 8 bits
+ * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
+ */
+#define NGHTTP2_VERSION_NUM 0x013a00
+
+#endif /* NGHTTP2VER_H */
+""".splitlines(),
+)
+
+cc_library(
+    name = "nghttp2",
+    srcs = glob(["lib/*.c"]),
+    hdrs = glob(["lib/*.h"]) + [
+        "lib/includes/nghttp2/nghttp2.h",
+        ":nghttp2ver.h",
+    ],
+    defines = [
+        "HAVE_TIME_H",
+        "HAVE_ARPA_INET_H",
+    ],
+    includes = [
+        "lib/includes/",
+    ],
+    visibility = ["//visibility:public"],
+)
diff --git a/debian/curl.BUILD b/debian/curl.BUILD
index a4f6526..1292c5e 100644
--- a/debian/curl.BUILD
+++ b/debian/curl.BUILD
@@ -422,6 +422,7 @@
             "-DCURL_DISABLE_NTLM",  # turning it off in configure is not enough
             "-DHAVE_LIBZ",
             "-DHAVE_ZLIB_H",
+            "-DUSE_NGHTTP2",
             "-Wno-string-plus-int",
             "-Wno-cast-qual",
             "-Wno-format-nonliteral",
@@ -466,6 +467,7 @@
         # Use the same version of zlib that gRPC does.
         "@zlib",
         ":define-ca-bundle-location",
+        "@com_github_nghttp2_nghttp2//:nghttp2",
     ] + select({
         ":windows": [],
         "//conditions:default": [