From 939c9c723edcea3536f5682815f60c81a3d2c3f4 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Wed, 5 Sep 2018 14:12:00 +0900 Subject: [PATCH] Create empty file when content-length is 0 Change-Id: Idd68889083e2e545c0eb48a29af7f9c3bb7c65c3 --- agent/download-agent-http-mgr.c | 14 +++++++++++--- agent/download-agent-http-msg-handler.c | 20 ++++++++++++++++++++ agent/include/download-agent-http-msg-handler.h | 4 ++++ packaging/download-provider.spec | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/agent/download-agent-http-mgr.c b/agent/download-agent-http-mgr.c index 6bf449f..a015c73 100755 --- a/agent/download-agent-http-mgr.c +++ b/agent/download-agent-http-mgr.c @@ -1107,6 +1107,7 @@ da_ret_t __handle_event_http_header(http_raw_data_t *raw_data, da_info_t *da_inf char *mime_type = DA_NULL; char *etag = DA_NULL; char *file_name = DA_NULL; + char *transfer_encoding = DA_NULL; NULL_CHECK_RET(da_info); http_info = da_info->http_info; @@ -1123,14 +1124,20 @@ da_ret_t __handle_event_http_header(http_raw_data_t *raw_data, da_info_t *da_inf DA_MUTEX_LOCK(&(http_info->mutex_state)); http_state = http_info->state; DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGV("http_state[%s]", __get_state_str(http_state)); + DA_LOGD("http_state[%s]", __get_state_str(http_state)); http_msg_response = http_info->http_msg_response; switch (http_state) { case HTTP_STATE_DOWNLOAD_REQUESTED: case HTTP_STATE_REQUEST_PAUSE: case HTTP_STATE_REQUEST_RESUME: case HTTP_STATE_REDIRECTED: - http_msg_response_get_content_length(http_msg_response, &size); + if (http_msg_response_get_content_length(http_msg_response, + &size) == DA_TRUE + && size == 0 + && http_msg_response_get_transfer_encoding(http_msg_response, + &transfer_encoding) == DA_FALSE) + start_file_writing(da_info); + http_info->content_len_from_header = size; http_msg_response_get_content_type(http_msg_response, &mime_type); http_info->content_type_from_header = mime_type; @@ -1400,8 +1407,9 @@ da_ret_t __handle_event_http_final(http_raw_data_t *raw_data, da_info_t *da_info http_info->state = HTTP_STATE_DOWNLOAD_FINISH; DA_MUTEX_UNLOCK(&(http_info->mutex_state)); break; + case HTTP_STATE_DOWNLOAD_STARTED: case HTTP_STATE_DOWNLOADING: - DA_LOGD("case HTTP_STATE_DOWNLOADING"); + DA_LOGD("case HTTP_STATE_DOWNLOAD_STARTED or HTTP_STATE_DOWNLOADING"); #ifdef _RAF_SUPPORT if (http_info->is_raf_mode_confirmed == DA_TRUE) ret = file_write_complete_for_raf(file_info); diff --git a/agent/download-agent-http-msg-handler.c b/agent/download-agent-http-msg-handler.c index e038b55..92d54c3 100755 --- a/agent/download-agent-http-msg-handler.c +++ b/agent/download-agent-http-msg-handler.c @@ -927,6 +927,26 @@ da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response, return DA_TRUE; } +da_bool_t http_msg_response_get_transfer_encoding(http_msg_response_t *http_msg_response, + char **out_value) +{ + da_bool_t b_ret = DA_FALSE; + http_header_t *header = NULL; + + DA_LOGV(""); + + b_ret = __get_http_header_for_field(http_msg_response, + HTTP_FIELD_TRANSFER_ENCODING, &header); + if (!b_ret) { + DA_LOGE("no Transfer-Encoding"); + return DA_FALSE; + } + if (out_value) + *out_value = strdup(header->value); + + return DA_TRUE; +} + char *__stristr(const char *long_str, const char *find_str) { int i = 0; diff --git a/agent/include/download-agent-http-msg-handler.h b/agent/include/download-agent-http-msg-handler.h index 6db624a..e37e183 100755 --- a/agent/include/download-agent-http-msg-handler.h +++ b/agent/include/download-agent-http-msg-handler.h @@ -20,6 +20,9 @@ #include "download-agent-type.h" #include "download-agent-dl-info.h" +// General Header +#define HTTP_FIELD_TRANSFER_ENCODING "Transfer-Encoding" + // Reqeust Header #define HTTP_FIELD_UAGENT "User-Agent" #define HTTP_FIELD_HOST "Host" @@ -61,6 +64,7 @@ da_bool_t http_msg_response_get_content_disposition(http_msg_response_t *http_ms da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, char **out_value); da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response, char **out_value); da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response, char **out_value); +da_bool_t http_msg_response_get_transfer_encoding(http_msg_response_t *http_msg_response, char **out_value); #ifdef _RAF_SUPPORT da_bool_t http_msg_response_get_RAF_mode(http_msg_response_t *http_msg_response, char **out_value); diff --git a/packaging/download-provider.spec b/packaging/download-provider.spec index 29c3d17..627d95f 100755 --- a/packaging/download-provider.spec +++ b/packaging/download-provider.spec @@ -1,6 +1,6 @@ Name: download-provider Summary: Download the contents in background -Version: 2.1.101 +Version: 2.1.102 Release: 0 Group: Development/Libraries License: Apache-2.0 -- 2.7.4