Nim don't have a library that support http/2 protocol. I found this library and it already has a python binding.
https://github.com/nghttp2/nghttp2
Any ideas on how to achieve this for Nim?
Thank @shashlick I will give it a try. But, my first approach was to use the c2nim and it works well.
But, when I import the library it gives the following error:
## Define WIN32 when build target is Win32 API (borrowed from
## libcurl)
when (defined(_WIN32) or defined(__WIN32__)) and not defined(WIN32): <<< line 29
const
WIN32* = true
## Compatibility for non-Clang compilers
when not defined(__has_declspec_attribute):
template __has_declspec_attribute*(x: untyped): untyped =
0
when defined(_MSC_VER) and (_MSC_VER < 1800):
## MSVC < 2013 does not have inttypes.h because it is not C99
## compliant. See compiler macros and version number in
## https://sourceforge.net/p/predef/wiki/Compilers/
else:
when defined(NGHTTP2_STATICLIB):
const
NGHTTP2_EXTERN* = true
elif defined(WIN32) or
(__has_declspec_attribute(dllexport) and
__has_declspec_attribute(dllimport)):
when defined(BUILDING_NGHTTP2):
const
NGHTTP2_EXTERN* = __declspec(dllexport)
else:
const
NGHTTP2_EXTERN* = __declspec(dllimport)
else:
when defined(BUILDING_NGHTTP2):
const
NGHTTP2_EXTERN* = __attribute__((visibility("default")))
else:
const
NGHTTP2_EXTERN* = true
## *
Any idea how to fix this?Here's a working wrapper for nghttp2. It will download the code from github, build it with cmake/make or configure/make and link the lib. You can pick static or dynamic linking.
To compile and link dynamically: nim c -d:nghttp2Git nghttp2.nim
To statically link add: -d:nghttp2Static
To pick a specific git tag: -d:nghttp2SetVer=v1.40.0
import os
import nimterop/[build, cimport]
const
baseDir = currentSourcePath.parentDir() / "nghttp2Lib"
getHeader(
header = "nghttp2.h",
giturl = "https://github.com/nghttp2/nghttp2",
outdir = baseDir,
cmakeFlags = "-DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON",
conFlags = "--enable-lib-only"
)
static:
cDebug()
cSkipSymbol(@["NGHTTP2_PROTO_ALPN"])
cIncludeDir(baseDir / "buildcache" / "lib" / "includes")
when isDefined(nghttp2Static):
cImport(nghttp2Path)
else:
cImport(nghttp2Path, dynlib="nghttp2LPath")
I have only tested on Linux but it should work cross-platform if nghttp2 compiles smoothly on those platforms.