http.c: Reduce log spam
authorGeorge Joseph <gjoseph@digium.com>
Wed, 5 Jul 2017 20:31:43 +0000 (14:31 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Tue, 11 Jul 2017 14:29:51 +0000 (09:29 -0500)
Messages like "fwrite() failed: Connection reset by peer" are no
help whatsoever, especially since they can be caused simply by a
client disconnecting.

* Make those WARNINGs DEBUGs.
* Check the return from ast_iostream_printf of headers.

Change-Id: I17bd5f3621514152a7b2b263c801324c5e96568b

main/http.c

index ea85a28..7191eb5 100644 (file)
@@ -508,7 +508,7 @@ void ast_http_send(struct ast_tcptls_session_instance *ser,
        send_content = method != AST_HTTP_HEAD || status_code >= 400;
 
        /* send http header */
-       ast_iostream_printf(ser->stream,
+       if (ast_iostream_printf(ser->stream,
                "HTTP/1.1 %d %s\r\n"
                "%s"
                "Date: %s\r\n"
@@ -526,13 +526,16 @@ void ast_http_send(struct ast_tcptls_session_instance *ser,
                http_header ? ast_str_buffer(http_header) : "",
                content_length,
                send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : ""
-               );
+               ) <= 0) {
+               ast_debug(1, "ast_iostream_printf() failed: %s\n", strerror(errno));
+               close_connection = 1;
+       }
 
        /* send content */
-       if (send_content && fd) {
+       if (!close_connection && send_content && fd) {
                while ((len = read(fd, buf, sizeof(buf))) > 0) {
                        if (ast_iostream_write(ser->stream, buf, len) != len) {
-                               ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
+                               ast_debug(1, "ast_iostream_write() failed: %s\n", strerror(errno));
                                close_connection = 1;
                                break;
                        }