From a884ffe43027e837e9fef41626c34e7f00bb2df1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 9 Jun 2012 05:42:39 +0200 Subject: Fixes allowing 26 more test cases in 1334 to 1393 range to succeed --- src/tool_cb_hdr.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'src/tool_cb_hdr.c') diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index ddc4c6638..ef340f798 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -41,10 +41,9 @@ static char *parse_filename(const char *ptr, size_t len); size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) { - HeaderData *hdrdata = userdata; - struct getout *urlnode = hdrdata->urlnode; - struct OutStruct *outs = hdrdata->outs; - struct OutStruct *heads = hdrdata->heads; + struct HdrCbData *hdrcbdata = userdata; + struct OutStruct *outs = hdrcbdata->outs; + struct OutStruct *heads = hdrcbdata->heads; const char *str = ptr; const size_t cb = size * nmemb; const char *end = (char*)ptr + cb; @@ -57,39 +56,35 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) */ size_t failure = (size * nmemb) ? 0 : 1; - if(!outs->config) + if(!heads->config) return failure; #ifdef DEBUGBUILD if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) { - warnf(outs->config, "Header data exceeds single call write limit!\n"); + warnf(heads->config, "Header data exceeds single call write limit!\n"); return failure; } #endif - /* --dump-header option */ - if(outs->config->headerfile) { - fwrite(ptr, size, nmemb, heads->stream); - } /* - ** This callback callback MIGHT set the filename upon appropriate - ** conditions and server specifying filename in Content-Disposition. - */ - - if(!outs->config->content_disposition) - return cb; - - if(!urlnode) - return failure; + * Write header data when curl option --dump-header (-D) is given. + */ - if(!checkprefix("http://", urlnode->url) && - !checkprefix("https://", urlnode->url)) - return cb; + if(heads->config->headerfile && heads->stream) { + size_t rc = fwrite(ptr, size, nmemb, heads->stream); + if(rc != cb) + return rc; + } - if(!(urlnode->flags & GETOUT_USEREMOTE)) - return cb; + /* + * This callback sets the filename where output shall be written when + * curl options --remote-name (-O) and --remote-header-name (-J) have + * been simultaneously given and additionally server returns an HTTP + * Content-Disposition header specifying a filename property. + */ - if((cb > 20) && checkprefix("Content-disposition:", str)) { + if(hdrcbdata->honor_cd_filename && + (cb > 20) && checkprefix("Content-disposition:", str)) { const char *p = str + 20; /* look for the 'filename=' parameter @@ -123,6 +118,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) outs->s_isreg = TRUE; outs->fopened = FALSE; outs->stream = NULL; + hdrcbdata->honor_cd_filename = FALSE; break; } else -- cgit v1.2.3