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.
........

Merged revisions 412922 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 412923 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@412924 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2014-04-23 18:00:40 +00:00
parent 11858be68c
commit 7ac2e15e77

View File

@@ -443,8 +443,8 @@ void ast_http_send(struct ast_tcptls_session_instance *ser,
/* send content */ /* send content */
if (method != AST_HTTP_HEAD || status_code >= 400) { if (method != AST_HTTP_HEAD || status_code >= 400) {
if (content_length) { if (out && ast_str_strlen(out)) {
if (fwrite(ast_str_buffer(out), content_length, 1, ser->f) != 1) { if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) {
ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno)); ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
} }
} }