[Asterisk-code-review] http.c: Send content. (asterisk[14])
Benjamin Keith Ford
asteriskteam at digium.com
Mon Oct 23 13:46:45 CDT 2017
Benjamin Keith Ford has uploaded this change for review. ( https://gerrit.asterisk.org/6884
Change subject: http.c: Send content.
......................................................................
http.c: Send content.
Currently ast_http_send barricades a portion of the content that
needs to be sent in order to establish a connection for things
like the ARI client. The conditional and contents have been changed
to ensure that everything that needs to be sent, will be sent.
Change-Id: I8816d2d8f80f4fefc6dcae4b5fdfc97f1e46496d
---
M main/http.c
1 file changed, 13 insertions(+), 22 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/84/6884/1
diff --git a/main/http.c b/main/http.c
index 32eb418..e6dc5cf 100644
--- a/main/http.c
+++ b/main/http.c
@@ -451,9 +451,12 @@
struct timeval now = ast_tvnow();
struct ast_tm tm;
char timebuf[80];
+ char buf[256];
+ int len;
int content_length = 0;
int close_connection;
struct ast_str *server_header_field = ast_str_create(MAX_SERVER_NAME_LENGTH);
+ int send_content;
if (!ser || !ser->f || !server_header_field) {
/* The connection is not open. */
@@ -504,6 +507,8 @@
lseek(fd, 0, SEEK_SET);
}
+ send_content = method != AST_HTTP_HEAD || status_code >= 400;
+
/* send http header */
if (fprintf(ser->f,
"HTTP/1.1 %d %s\r\n"
@@ -513,46 +518,32 @@
"%s"
"%s"
"Content-Length: %d\r\n"
- "\r\n",
+ "\r\n"
+ "%s",
status_code, status_title ? status_title : "OK",
ast_str_buffer(server_header_field),
timebuf,
close_connection ? "Connection: close\r\n" : "",
static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
http_header ? ast_str_buffer(http_header) : "",
- content_length
+ content_length,
+ send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : ""
) <= 0) {
ast_debug(1, "fprintf() failed: %s\n", strerror(errno));
close_connection = 1;
}
/* send content */
- if (!close_connection && (method != AST_HTTP_HEAD || status_code >= 400)) {
- if (out && ast_str_strlen(out)) {
+ if (!close_connection && send_content && fd) {
+ while ((len = read(fd, buf, sizeof(buf))) > 0) {
/*
* NOTE: Because ser->f is a non-standard FILE *, fwrite() will probably not
* behave exactly as documented.
*/
- if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) {
+ if (fwrite(buf, len, 1, ser->f) != 1) {
ast_debug(1, "fwrite() failed: %s\n", strerror(errno));
close_connection = 1;
- }
- }
-
- if (fd) {
- char buf[256];
- int len;
-
- while ((len = read(fd, buf, sizeof(buf))) > 0) {
- /*
- * NOTE: Because ser->f is a non-standard FILE *, fwrite() will probably not
- * behave exactly as documented.
- */
- if (fwrite(buf, len, 1, ser->f) != 1) {
- ast_debug(1, "fwrite() failed: %s\n", strerror(errno));
- close_connection = 1;
- break;
- }
+ break;
}
}
}
--
To view, visit https://gerrit.asterisk.org/6884
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8816d2d8f80f4fefc6dcae4b5fdfc97f1e46496d
Gerrit-Change-Number: 6884
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171023/8c5f7019/attachment-0001.html>
More information about the asterisk-code-review
mailing list