diff --git a/main/http.c b/main/http.c
index 1009afcc24412c0cead6edbc24935b9c1f54ca2d..d6bc006f3e27324bb9b69604b415d0939285b76a 100644
--- a/main/http.c
+++ b/main/http.c
@@ -416,7 +416,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) {
@@ -443,7 +443,7 @@ void ast_http_send(struct ast_tcptls_session_instance *ser,
 
 	/* send content */
 	if (method != AST_HTTP_HEAD || status_code >= 400) {
-		if (out) {
+		if (content_length) {
 			if (fwrite(ast_str_buffer(out), content_length, 1, ser->f) != 1) {
 				ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
 			}