{"id":8848,"date":"2016-04-29T08:43:06","date_gmt":"2016-04-29T06:43:06","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=8848"},"modified":"2016-04-29T08:43:06","modified_gmt":"2016-04-29T06:43:06","slug":"curl-7-49-0-goodies-coming","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2016\/04\/29\/curl-7-49-0-goodies-coming\/","title":{"rendered":"curl 7.49.0 goodies coming"},"content":{"rendered":"<p>Here&#8217;s a closer look at three new features that we&#8217;re shipping in <a href=\"https:\/\/curl.haxx.se\/\">curl and libcurl<\/a> 7.49.0, to be released on May 18th 2016.<\/p>\n<h2>connect to this instead<\/h2>\n<p>If you&#8217;re one of the users who thought <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--resolve\"><code>--resolve<\/code><\/a> and doing Host: header tricks with <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-H\"><code>--header<\/code><\/a> weren&#8217;t good enough, you&#8217;ll appreciate that we&#8217;re adding yet another option for you to fiddle with the connection procedure. Another &#8220;Swiss army knife style&#8221; option for you who know what you&#8217;re doing.<\/p>\n<p>With <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--connect-to\"><code>--connect-to<\/code><\/a> you basically provide an internal alias for a certain name + port to instead internally use another name + port to connect to.<\/p>\n<p><em>Instead of connecting to HOST1:PORT1, connect to HOST2:PORT2<\/em><\/p>\n<p>It is very similar to <code>--resolve<\/code> which is a way to say: when connecting to HOST1:PORT1 use this ADDR2:PORT2. <code>--resolve<\/code> effectively prepopulates the internal DNS cache and makes curl completely avoid the DNS lookup and instead feeds it with the IP address you&#8217;d like it to use.<\/p>\n<p><code>--connect-to<\/code> doesn&#8217;t avoid the DNS lookup, but it will make sure that a <em>different<\/em> host name and destination port pair is used than what was found in the URL. A typical use case for this would be to make sure that your curl request asks a specific server out of several in a pool of many, where each has a unique name but you normally reach them with a single URL who&#8217;s host name is otherwise load balanced.<\/p>\n<p><code>--connect-to<\/code> can be specified multiple times to add mappings for multiple names, so that even following HTTP redirects to other host names etc can be handled. You don&#8217;t even necessarily have to redirect the first used host name.<\/p>\n<p>The libcurl option name for for this feature is <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_CONNECT_TO.html\">CURLOPT_CONNECT_TO<\/a>.<\/p>\n<p>Michael Kaufmann brought this feature.<\/p>\n<h2>http2 prior knowledge<\/h2>\n<p>In our ongoing quest to provide more and better HTTP\/2 support in a world that is slowly but steadily doing more and more transfers over the new version of the protocol, curl now offers <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--http2-prior-knowledge\"><code>--http2-prior-knowledge<\/code><\/a>.<\/p>\n<p>As the name might hint, this is a way to tell curl that you have &#8220;prior knowledge&#8221; that the URL you specifies goes to a host that you know supports HTTP\/2. The term <em>prior knowledge<\/em> is in fact used in the HTTP\/2 spec (<a href=\"http:\/\/httpwg.org\/specs\/rfc7540.html\">RFC 7540<\/a>) for this scenario.<\/p>\n<p>Normally when given a HTTP:\/\/ or a HTTPS:\/\/ URL, there will be no assumption that it supports HTTP\/2 but curl when then try to upgrade that from version HTTP\/1. The command line tool tries to upgrade all HTTPS:\/\/ URLs <a href=\"https:\/\/daniel.haxx.se\/blog\/2015\/12\/14\/curl-and-http2-by-default\/\">by default<\/a> even, and <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_HTTP_VERSION.html\">libcurl can be told<\/a> to do so.<\/p>\n<p>libcurl wise, you ask for a prior knowledge use by setting <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_HTTP_VERSION.html\">CURLOPT_HTTP_VERSION <\/a>to CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE.<\/p>\n<p>Asking for http2 prior knowledge when the server does in fact not support HTTP\/2 will give you an error back.<\/p>\n<p>Diego Bes brought this feature.<\/p>\n<h2>TCP Fast Open<\/h2>\n<p>TCP Fast Open is documented in <a href=\"https:\/\/tools.ietf.org\/html\/rfc7413\">RFC 7413<\/a> and is basically a way to pass on data to the remote machine earlier in the TCP handshake &#8211; already in the SYN and SYN-ACK packets. This of course as a means to get data over faster and reduce latency.<\/p>\n<p>The <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--tcp-fastopen\"><code>--tcp-fastopen<\/code><\/a> option is supported on Linux and OS X only for now.<\/p>\n<p>This is an idea and technique that has been around for a while and it is slowly getting implemented and supported by servers. There have been some reports of problems in the wild when &#8220;middle boxes&#8221; that fiddle with TCP traffic see these packets, that sometimes result in breakage. So this option is opt-in to avoid the risk that it causes problems to users.<\/p>\n<p>A typical real-world case where you would use this option is when\u00a0 sending an HTTP POST to a site you don&#8217;t have a connection already established to. Just note that TFO relies on the client having had contact established with the server before and having a special TFO &#8220;<a href=\"https:\/\/tools.ietf.org\/html\/rfc7413#section-4.1.3\">cookie<\/a>&#8221; stored and non-expired.<\/p>\n<p>TCP Fast Open is so far only used for clear-text TCP protocols in curl. These days more and more protocols switch over to their TLS counterparts (and there&#8217;s room for future improvements to add the initial TLS handshake parts with TFO). A related option to speed up TLS handshakes is <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--false-start\"><code>--false-start<\/code><\/a> (supported with the NSS or the secure transport backends).<\/p>\n<p>With libcurl, you enable TCP Fast Open with <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_TCP_FASTOPEN.html\">CURLOPT_TCP_FASTOPEN<\/a>.<\/p>\n<p>Alessandro Ghedini brought this feature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a closer look at three new features that we&#8217;re shipping in curl and libcurl 7.49.0, to be released on May 18th 2016. connect to this instead If you&#8217;re one of the users who thought &#8211;resolve and doing Host: header tricks with &#8211;header weren&#8217;t good enough, you&#8217;ll appreciate that we&#8217;re adding yet another option for &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2016\/04\/29\/curl-7-49-0-goodies-coming\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl 7.49.0 goodies coming<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,13,6],"tags":[33,369,94,288],"class_list":["post-8848","post","type-post","status-publish","format-standard","hentry","category-curl","category-net","category-floss","tag-curl-and-libcurl","tag-http2","tag-release-time","tag-tcp"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/8848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=8848"}],"version-history":[{"count":16,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/8848\/revisions"}],"predecessor-version":[{"id":8864,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/8848\/revisions\/8864"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=8848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=8848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=8848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}