Discussion:
HTTP2: how to know the HTTP version used by libcurl
Ganesh Nikam
2016-04-26 06:37:38 UTC
Permalink
Hi All,

We want to use libcurl with HTTP/2 support. As per the details
regarding CURL_HTTP_VERSION_2_0
(https://curl.haxx.se/libcurl/c/CURLOPT_HTTP_VERSION.html), libcurl will
attempt to send HTTP/2 request using upgrade header. But if server is not
supporting HTTP/2, then it will fall back to HTTP 1.1 version. For HTTPS
requests the protocol negotiation will happen using ALPN. As per my
understanding the "fall back" mechanism for HTTP and ALPN for HTTPS are
internal to the libcurl. Application using libcurl will not have any idea
about this. I have some queries on these:

1. Is there any way to know the current HTTP version getting used in
libcurl requests ? I checked getinfo parameters but there is not parameter
for HTTP version ? In our application we want to know HTTP version getting
used for current requests.

2. If we have can send HTTPS requests by setting http version to
CURL_HTTP_VERSION_2_0,
then what is the purpose of CURL_HTTP_VERSION_2TLS ?

Regards
Ganesh Nikam
Daniel Stenberg
2016-04-26 09:27:30 UTC
Permalink
1. Is there any way to know the current HTTP version getting used in libcurl
requests ? I checked getinfo parameters but there is not parameter for HTTP
version ? In our application we want to know HTTP version getting used for
current requests.
We really should provide a getinfo parameter for that! Are you interested in
helping us make that happen?

Right now the best way is probably to provide a header callback and parse out
the version yourself in the first response header. (By HTTP terminology it is
the status line and not a header, but it is passed to the header callback
nonetheless.)
2. If we have can send HTTPS requests by setting http version to
CURL_HTTP_VERSION_2_0, then what is the purpose of CURL_HTTP_VERSION_2TLS ?
If you know you work with HTTPS then there's no difference between them. The
CURL_HTTP_VERSION_2TLS option is there for those who want to use both HTTP and
HTTPS URLs and have libcurl use HTTP/2 automatically only for the HTTPS ones.

It should also make it possible for libcurl to (at some point in the future)
perhaps switch to CURL_HTTP_VERSION_2TLS as default selected HTTP version.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://cu
Ganesh Nikam
2016-04-26 09:41:12 UTC
Permalink
Hi Daniel,

Thanks for the quick reply. I will check the code and if possible I will
add the getinfo parameter.

The 2nd point about answers my query. Similar to browsers (like firefox and
chrome which support http/2 with HTTPS only), we can configure libcurl,
using this HTTP version.


Regards
Ganesh Nikam
Post by Ganesh Nikam
1. Is there any way to know the current HTTP version getting used in
Post by Ganesh Nikam
libcurl requests ? I checked getinfo parameters but there is not parameter
for HTTP version ? In our application we want to know HTTP version getting
used for current requests.
We really should provide a getinfo parameter for that! Are you interested
in helping us make that happen?
Right now the best way is probably to provide a header callback and parse
out the version yourself in the first response header. (By HTTP terminology
it is the status line and not a header, but it is passed to the header
callback nonetheless.)
2. If we have can send HTTPS requests by setting http version to
Post by Ganesh Nikam
CURL_HTTP_VERSION_2_0, then what is the purpose of CURL_HTTP_VERSION_2TLS ?
If you know you work with HTTPS then there's no difference between them.
The CURL_HTTP_VERSION_2TLS option is there for those who want to use both
HTTP and HTTPS URLs and have libcurl use HTTP/2 automatically only for the
HTTPS ones.
It should also make it possible for libcurl to (at some point in the
future) perhaps switch to CURL_HTTP_VERSION_2TLS as default selected HTTP
version.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Ganesh Nikam
2016-05-19 07:10:54 UTC
Permalink
Hi Daniel,

I have created the patch for adding CURLINFO_HTTP_VERSION flag in
curl_easy_getinfo() function. Please find the attachment. Can you please
review it and let me know if there are any comments ?


Regards
Ganesh Nikam
Post by Ganesh Nikam
Hi Daniel,
Thanks for the quick reply. I will check the code and if possible I will
add the getinfo parameter.
The 2nd point about answers my query. Similar to browsers (like firefox
and chrome which support http/2 with HTTPS only), we can configure libcurl,
using this HTTP version.
Regards
Ganesh Nikam
Post by Ganesh Nikam
1. Is there any way to know the current HTTP version getting used in
Post by Ganesh Nikam
libcurl requests ? I checked getinfo parameters but there is not parameter
for HTTP version ? In our application we want to know HTTP version getting
used for current requests.
We really should provide a getinfo parameter for that! Are you interested
in helping us make that happen?
Right now the best way is probably to provide a header callback and parse
out the version yourself in the first response header. (By HTTP terminology
it is the status line and not a header, but it is passed to the header
callback nonetheless.)
2. If we have can send HTTPS requests by setting http version to
Post by Ganesh Nikam
CURL_HTTP_VERSION_2_0, then what is the purpose of CURL_HTTP_VERSION_2TLS ?
If you know you work with HTTPS then there's no difference between them.
The CURL_HTTP_VERSION_2TLS option is there for those who want to use both
HTTP and HTTPS URLs and have libcurl use HTTP/2 automatically only for the
HTTPS ones.
It should also make it possible for libcurl to (at some point in the
future) perhaps switch to CURL_HTTP_VERSION_2TLS as default selected HTTP
version.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Daniel Stenberg
2016-05-19 07:38:01 UTC
Permalink
Post by Ganesh Nikam
I have created the patch for adding CURLINFO_HTTP_VERSION flag in
curl_easy_getinfo() function. Please find the attachment. Can you please
review it and let me know if there are any comments ?
Ah, Frank Gevaerts actually beat you to it and submitted his version of that
patch here: https://github.com/curl/curl/pull/799

I think I prefer his use of the version defines, plus he also makes it
available to the command line tool.

Do you agree or is there anything in your version we should merge into
Frank's?
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.
Ganesh Nikam
2016-05-19 08:26:36 UTC
Permalink
Frank's patch looks fine. We can go with that :) !!!


Regards
Ganesh Nikam
Post by Ganesh Nikam
I have created the patch for adding CURLINFO_HTTP_VERSION flag in
Post by Ganesh Nikam
curl_easy_getinfo() function. Please find the attachment. Can you please
review it and let me know if there are any comments ?
Ah, Frank Gevaerts actually beat you to it and submitted his version of
that patch here: https://github.com/curl/curl/pull/799
I think I prefer his use of the version defines, plus he also makes it
available to the command line tool.
Do you agree or is there anything in your version we should merge into
Frank's?
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Continue reading on narkive:
Loading...