<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6884">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">http.c: Fix http header send content.<br><br>Currently ast_http_send barricades a portion of the content that<br>needs to be sent in order to establish a connection for things<br>like the ARI client. The conditional and contents have been changed<br>to ensure that everything that needs to be sent, will be sent.<br><br>ASTERISK-27372<br><br>Change-Id: I8816d2d8f80f4fefc6dcae4b5fdfc97f1e46496d<br>---<br>M main/http.c<br>1 file changed, 14 insertions(+), 25 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/http.c b/main/http.c<br>index 32eb418..76f410c 100644<br>--- a/main/http.c<br>+++ b/main/http.c<br>@@ -451,9 +451,12 @@<br> struct timeval now = ast_tvnow();<br> struct ast_tm tm;<br> char timebuf[80];<br>+ char buf[256];<br>+ int len;<br> int content_length = 0;<br> int close_connection;<br> struct ast_str *server_header_field = ast_str_create(MAX_SERVER_NAME_LENGTH);<br>+ int send_content;<br> <br> if (!ser || !ser->f || !server_header_field) {<br> /* The connection is not open. */<br>@@ -504,6 +507,8 @@<br> lseek(fd, 0, SEEK_SET);<br> }<br> <br>+ send_content = method != AST_HTTP_HEAD || status_code >= 400;<br>+<br> /* send http header */<br> if (fprintf(ser->f,<br> "HTTP/1.1 %d %s\r\n"<br>@@ -513,46 +518,30 @@<br> "%s"<br> "%s"<br> "Content-Length: %d\r\n"<br>- "\r\n",<br>+ "\r\n"<br>+ "%s",<br> status_code, status_title ? status_title : "OK",<br> ast_str_buffer(server_header_field),<br> timebuf,<br> close_connection ? "Connection: close\r\n" : "",<br> static_content ? "" : "Cache-Control: no-cache, no-store\r\n",<br> http_header ? ast_str_buffer(http_header) : "",<br>- content_length<br>+ content_length,<br>+ send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : ""<br> ) <= 0) {<br> ast_debug(1, "fprintf() failed: %s\n", strerror(errno));<br> close_connection = 1;<br>- }<br>-<br>- /* send content */<br>- if (!close_connection && (method != AST_HTTP_HEAD || status_code >= 400)) {<br>- if (out && ast_str_strlen(out)) {<br>+ } else if (send_content && fd) {<br>+ /* send file content */<br>+ while ((len = read(fd, buf, sizeof(buf))) > 0) {<br> /*<br> * NOTE: Because ser->f is a non-standard FILE *, fwrite() will probably not<br> * behave exactly as documented.<br> */<br>- if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) {<br>+ if (fwrite(buf, len, 1, ser->f) != 1) {<br> ast_debug(1, "fwrite() failed: %s\n", strerror(errno));<br> close_connection = 1;<br>- }<br>- }<br>-<br>- if (fd) {<br>- char buf[256];<br>- int len;<br>-<br>- while ((len = read(fd, buf, sizeof(buf))) > 0) {<br>- /*<br>- * NOTE: Because ser->f is a non-standard FILE *, fwrite() will probably not<br>- * behave exactly as documented.<br>- */<br>- if (fwrite(buf, len, 1, ser->f) != 1) {<br>- ast_debug(1, "fwrite() failed: %s\n", strerror(errno));<br>- close_connection = 1;<br>- break;<br>- }<br>+ break;<br> }<br> }<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6884">change 6884</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6884"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I8816d2d8f80f4fefc6dcae4b5fdfc97f1e46496d </div>
<div style="display:none"> Gerrit-Change-Number: 6884 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>