Я разработал клиентское приложение для подключения нестандартного сервера по HTTP / 2 с помощью libcurl. Он отлично работает на Ubuntu 18.04. Кстати, в Ubuntu 16.04 он выбирает HTTP / 1.1, а не HTTP / 2.
Я обнаружил, что для установки 16 апреля необходимо установить библиотеку nghttp2, поэтому я установил ее и обнаружил, что ALPN также предлагает h2. Но в конце концов он все еще использует HTTP / 1.1.
CURL *curl;
CURLcode res = curl_global_init(CURL_GLOBAL_DEFAULT);
if(res != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed: %s\n",
curl_easy_strerror(res));
return 1;
}
curl = curl_easy_init();
if(curl) {
struct curl_slist *headerList = agent->getHeaderList();
/* what call to write: */
curl_easy_setopt(curl, CURLOPT_URL, agent->getUrl().c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList);
curl_easy_setopt(curl, CURLOPT_VERBOSE, ASR_CLIENT_DEBUG ? 1L : 0L);
CURLcode rv;
do { /* dummy loop, just to break out from */
rv = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
rv = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
rv = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, ConnectAgent::headerCallback);
rv = curl_easy_setopt(curl, CURLOPT_HEADERDATA, agent);
rv = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ConnectAgent::bodyCallback);
rv = curl_easy_setopt(curl, CURLOPT_WRITEDATA, agent);
rv = curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
rv = curl_easy_setopt(curl, CURLOPT_POST, 1L);
rv = curl_easy_setopt(curl, CURLOPT_READFUNCTION, ConnectAgent::readToVoiceServerCallback);
rv = curl_easy_setopt(curl, CURLOPT_READDATA, agent);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* we are done... */
} while(0);
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
В Ubuntu 16.04 кажется, что HTTP2 готов, но реальное соединение на HTTP / 1.1
* Trying xx.xxx.xxx.xxx...
* Connected to xxx.xxx.xxx.xxx (xx.xxx.xxx.xxx) port xxxxx (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: -----------------------
CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=Unknown; ST=Unknown; L=Unknown; O=Mort Bay Consulting Pty. Ltd.; OU=Jetty; CN=jetty.eclipse.org
* start date: May 20 11:38:03 2015 GMT
* expire date: Aug 18 11:38:03 2015 GMT
* issuer: C=Unknown; ST=Unknown; L=Unknown; O=Mort Bay Consulting Pty. Ltd.; OU=Jetty; CN=jetty.eclipse.org
* SSL certificate verify result: self signed certificate (18), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f40f00008c0)
> POST /voice HTTP/1.1
Построен на Ubuntu 18.04 с тем же исходным кодом, работает нормально с подключением по HTTP / 2