From 8ccad4ce21dd2d988548a3a05cd454c77bfdc60d Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Wed, 23 Apr 2014 17:47:07 +0000 Subject: [PATCH] http: Fix spurious ERROR message in responses with no content. Backport -r411687 and fix the fix because content_length is the length of out plus the length of the file controlled by fd. When a response has an out content length of 0, fwrite would be called to write a buffer with no data in it. This resulted in the following classic error message: [Apr 3 11:49:17] ERROR[26421] http.c: fwrite() failed: Success This patch makes it so that we only attempt to write the content of out if the out string is non-zero. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@412922 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/http.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/http.c b/main/http.c index cc3fc9fc51..d77f278ad4 100644 --- a/main/http.c +++ b/main/http.c @@ -406,7 +406,7 @@ void ast_http_send(struct ast_tcptls_session_instance *ser, /* calc content length */ if (out) { - content_length += strlen(ast_str_buffer(out)); + content_length += ast_str_strlen(out); } if (fd) { @@ -433,8 +433,8 @@ void ast_http_send(struct ast_tcptls_session_instance *ser, /* send content */ if (method != AST_HTTP_HEAD || status_code >= 400) { - if (out) { - if (fwrite(ast_str_buffer(out), content_length, 1, ser->f) != 1) { + if (out && ast_str_strlen(out)) { + if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) { ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno)); } }