What is the importance of setting CURLOPT_HTTP_VERSION in an application?

  1. I don't see any benefit. Let curl deal with that.

  2. Curl will do that for you. And I'm pretty sure the future HTTP 2.0 will not break backward compatibility.

  3. As stated in HTTP 1.0 vs 1.1, the only valid reason to prefer HTTP 1.0 is when you cannot send a Host header to the server. But honestly I can't imagine a real world situation.


I've got an old PHP application that ran on a server with a version of PHP/libcurl that did not support HTTP 2. It makes requests to an external API and inspects response headers to determine what to do next. But this old code was only designed to handle HTTP 1.0 and HTTP 1.1 headers.

If the application is installed on a server that has HTTP 2 support, curl will choose to use that, and the application will break. So I cannot install it on a newer server, or upgrade the current server, without making code changes.

In this case, changing the application to use HTTP 1.1 (which is known to work) is a much simpler change than changing many parts of the code to inspect a new variety of possible response headers.

Tags:

Php

Http

Curl