Unverified Commit e50a2002 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

FILE: fix CURLOPT_NOBODY and CURLOPT_HEADER output

Now FILE transfers send headers to the header callback like HTTP and
other protocols. Also made curl_easy_getinfo(...CURLINFO_PROTOCOL...)
work for FILE in the callbacks.

Makes "curl -i file://.." and "curl -I file://.." work like before
again. Applied the bold header logic to them too.

Regression from c1c27625 (7.61.0)

Reported-by: Shaun Jackman
Fixes #3083
Closes #3101
parent b55e85d4
Loading
Loading
Loading
Loading
+13 −14
Original line number Original line Diff line number Diff line
@@ -386,7 +386,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done)


  *done = TRUE; /* unconditionally */
  *done = TRUE; /* unconditionally */


  Curl_initinfo(data);
  Curl_pgrsStartNow(data);
  Curl_pgrsStartNow(data);


  if(data->set.upload)
  if(data->set.upload)
@@ -413,21 +412,18 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
    }
    }
  }
  }


  /* If we have selected NOBODY and HEADER, it means that we only want file
  if(fstated) {
     information. Which for FILE can't be much more than the file size and
     date. */
  if(data->set.opt_no_body && data->set.include_header && fstated) {
    time_t filetime;
    time_t filetime;
    struct tm buffer;
    struct tm buffer;
    const struct tm *tm = &buffer;
    const struct tm *tm = &buffer;
    char header[80];
    char header[80];
    snprintf(header, sizeof(header),
    snprintf(header, sizeof(header),
             "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size);
             "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size);
    result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0);
    result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
    if(result)
    if(result)
      return result;
      return result;


    result = Curl_client_write(conn, CLIENTWRITE_BOTH,
    result = Curl_client_write(conn, CLIENTWRITE_HEADER,
                               (char *)"Accept-ranges: bytes\r\n", 0);
                               (char *)"Accept-ranges: bytes\r\n", 0);
    if(result)
    if(result)
      return result;
      return result;
@@ -439,18 +435,21 @@ static CURLcode file_do(struct connectdata *conn, bool *done)


    /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
    /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
    snprintf(header, sizeof(header),
    snprintf(header, sizeof(header),
             "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
             "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n%s",
             Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
             Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
             tm->tm_mday,
             tm->tm_mday,
             Curl_month[tm->tm_mon],
             Curl_month[tm->tm_mon],
             tm->tm_year + 1900,
             tm->tm_year + 1900,
             tm->tm_hour,
             tm->tm_hour,
             tm->tm_min,
             tm->tm_min,
             tm->tm_sec);
             tm->tm_sec,
    result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0);
             data->set.opt_no_body ? "": "\r\n");
    if(!result)
    result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
    if(result)
      return result;
    /* set the file size to make it available post transfer */
    /* set the file size to make it available post transfer */
    Curl_pgrsSetDownloadSize(data, expected_size);
    Curl_pgrsSetDownloadSize(data, expected_size);
    if(data->set.opt_no_body)
      return result;
      return result;
  }
  }


+0 −1
Original line number Original line Diff line number Diff line
@@ -85,7 +85,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
#ifdef USE_SSL
#ifdef USE_SSL
  Curl_ssl_free_certinfo(data);
  Curl_ssl_free_certinfo(data);
#endif
#endif

  return CURLE_OK;
  return CURLE_OK;
}
}


+1 −0
Original line number Original line Diff line number Diff line
@@ -3745,6 +3745,7 @@ static CURLcode create_conn(struct Curl_easy *data,
    /* this is supposed to be the connect function so we better at least check
    /* this is supposed to be the connect function so we better at least check
       that the file is present here! */
       that the file is present here! */
    DEBUGASSERT(conn->handler->connect_it);
    DEBUGASSERT(conn->handler->connect_it);
    Curl_persistconninfo(conn);
    result = conn->handler->connect_it(conn, &done);
    result = conn->handler->connect_it(conn, &done);


    /* Setup a "faked" transfer that'll do nothing */
    /* Setup a "faked" transfer that'll do nothing */
+3 −2
Original line number Original line Diff line number Diff line
@@ -158,8 +158,9 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
  }
  }


  if(hdrcbdata->config->show_headers &&
  if(hdrcbdata->config->show_headers &&
     (protocol & (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP))) {
    (protocol &
    /* bold headers only happen for HTTP(S) and RTSP */
     (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP|CURLPROTO_FILE))) {
    /* bold headers only for selected protocols */
    char *value = NULL;
    char *value = NULL;


    if(!outs->stream && !tool_create_output_file(outs, FALSE))
    if(!outs->stream && !tool_create_output_file(outs, FALSE))
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ file
 <name>
 <name>
X-Y range on a file:// URL to stdout
X-Y range on a file:// URL to stdout
 </name>
 </name>
 <command>
<command option="no-include">
-r 1-4 file://localhost/%PWD/log/test1016.txt 
-r 1-4 file://localhost/%PWD/log/test1016.txt 
</command>
</command>
<file name="log/test1016.txt">
<file name="log/test1016.txt">
Loading