{"id":13032,"date":"2020-01-13T15:03:39","date_gmt":"2020-01-13T14:03:39","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=13032"},"modified":"2020-01-13T16:10:49","modified_gmt":"2020-01-13T15:10:49","slug":"curl-ootw-raw","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2020\/01\/13\/curl-ootw-raw\/","title":{"rendered":"curl ootw: &#8211;raw"},"content":{"rendered":"\n<p>(ootw is short for &#8220;<a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/01\/07\/curl-option-of-the-week\/\">option of the week<\/a>&#8220;!)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>--raw<\/code><\/h2>\n\n\n\n<p>Introduced back in April of 2007 in <a href=\"https:\/\/curl.haxx.se\/changes.html#7_16_2\">curl 7.16.2<\/a>, the <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--raw\">man page details<\/a> for this option is very brief:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>(HTTP) When used, it disables all internal HTTP decoding of content or transfer encodings and instead makes them passed on unaltered, raw. <\/p><\/blockquote>\n\n\n\n<p>This option is for HTTP(S) and it was brought to curl when someone wanted to use curl in a proxy solution. In that setup the user parsed the incoming headers and acted on them and in the case where for example <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chunked_transfer_encoding\">chunked encoded<\/a> data is received, which curl then automatically &#8220;decodes&#8221; so that it can deliver the pure clean data, the user would find that there were headers in the received response that says &#8220;chunked&#8221; but since libcurl had already decoded the body, it wasn&#8217;t actually still chunked when it landed!<\/p>\n\n\n\n<p>In the libcurl side, an application can explicitly switch off this, by disabling transfer and content encoding with <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_HTTP_TRANSFER_DECODING.html\">CURLOPT_HTTP_TRANSFER_DECODING<\/a> and <a href=\"https:\/\/curl.haxx.se\/libcurl\/c\/CURLOPT_HTTP_CONTENT_DECODING.html\">CURLOPT_HTTP_CONTENT_DECODING<\/a>.<\/p>\n\n\n\n<p>The <code>--raw<\/code> option is the command line version that disable both of those at once.<\/p>\n\n\n\n<p>With <code>--raw<\/code>, no transfer or content decoding is done and the &#8220;raw&#8221; stream is instead delivered or saved. You really only do this if you for some reason want to handle those things yourself instead.<\/p>\n\n\n\n<p>Content decoding includes automatice gzip compression, so <code>--raw<\/code> will also disable that, even if you use <code>--compressed<\/code>.<\/p>\n\n\n\n<p>It should be noted that chunked encoding is a HTTP\/1.1 thing. We don&#8217;t do that anymore in HTTP\/2 and later &#8211; and curl will default to HTTP\/2 over HTTPS if possible since a while back. Users can also often avoid chunked encoded responses by insisting on HTTP\/1.0, like with the <code><a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-0\">--http1.0<\/a><\/code> option (since chunked wasn&#8217;t included in 1.0).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example command line<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">curl --raw https:\/\/example.com\/dyn-content.cgi<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Related options<\/h2>\n\n\n\n<p><code><a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#--compressed\">--compressed<\/a><\/code> asks the server to provide the response compressed and curl will then decompress it automatically. Thus reduce the amount of data that gets sent over the wire.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(ootw is short for &#8220;option of the week&#8220;!) &#8211;raw Introduced back in April of 2007 in curl 7.16.2, the man page details for this option is very brief: (HTTP) When used, it disables all internal HTTP decoding of content or transfer encodings and instead makes them passed on unaltered, raw. This option is for HTTP(S) &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/01\/13\/curl-ootw-raw\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl ootw: &#8211;raw<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":13041,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[33,486],"class_list":["post-13032","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-curl","tag-curl-and-libcurl","tag-option-of-the-week"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13032","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=13032"}],"version-history":[{"count":12,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13032\/revisions"}],"predecessor-version":[{"id":13202,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/13032\/revisions\/13202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media\/13041"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=13032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=13032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=13032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}