{"id":10161,"date":"2017-06-16T09:20:52","date_gmt":"2017-06-16T07:20:52","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=10161"},"modified":"2017-06-16T09:20:52","modified_gmt":"2017-06-16T07:20:52","slug":"curl-read-headers-from-file","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2017\/06\/16\/curl-read-headers-from-file\/","title":{"rendered":"curl: read headers from file"},"content":{"rendered":"<p><a href=\"https:\/\/curl.haxx.se\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-thumbnail wp-image-8936\" src=\"https:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2016\/04\/good_curl_logo-200x76.png\" alt=\"\" width=\"200\" height=\"76\" srcset=\"https:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2016\/04\/good_curl_logo-200x76.png 200w, https:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2016\/04\/good_curl_logo-450x172.png 450w, https:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2016\/04\/good_curl_logo-768x294.png 768w, https:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2016\/04\/good_curl_logo-1200x459.png 1200w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a>Starting in curl 7.55.0 (since <a href=\"https:\/\/github.com\/curl\/curl\/commit\/84b9458837551a2749b45d924089f2015415a324\">this commit<\/a>), you can tell curl to read custom headers from a file. A feature that <a href=\"https:\/\/stackoverflow.com\/questions\/12661159\/curl-read-headers-from-file\">has been asked for<\/a> numerous times in the past, and the answer has always been to write a shell script to do it. Like this:<\/p>\n<pre>#!\/bin\/sh\r\nwhile read line; do\r\n  args=\"$args -H '$line'\";\r\ndone\r\ncurl $args $URL\r\n<\/pre>\n<p>That&#8217;s now a response of the past (or for users stuck on old curl versions). We can now instead tell curl to read headers itself from a file using the curl standard @filename way:<\/p>\n<pre>$ curl -H @headers https:\/\/example.com<\/pre>\n<p>&#8230; and this also works if you want to just send custom headers to the proxy you do CONNECT to:<\/p>\n<pre>$ curl --proxy-headers @headers --proxy proxy:8080 https:\/\/example.com\/<\/pre>\n<p>(this is a pure curl tool change that doesn&#8217;t affect libcurl, the library)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting in curl 7.55.0 (since this commit), you can tell curl to read custom headers from a file. A feature that has been asked for numerous times in the past, and the answer has always been to write a shell script to do it. Like this: #!\/bin\/sh while read line; do args=&#8221;$args -H &#8216;$line'&#8221;; done &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2017\/06\/16\/curl-read-headers-from-file\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl: read headers from file<\/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],"tags":[33,455,230],"class_list":["post-10161","post","type-post","status-publish","format-standard","hentry","category-curl","tag-curl-and-libcurl","tag-documentation","tag-http"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/10161","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=10161"}],"version-history":[{"count":5,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/10161\/revisions"}],"predecessor-version":[{"id":10166,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/10161\/revisions\/10166"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=10161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=10161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=10161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}