<p>Joshua C. Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/11026">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Matthew Fredrickson: Looks good to me, but someone else must approve
Joshua C. Colp: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">http.c: Support separated HTTP request<br><br>Currently, the Asterisk does not support seperated HTTP request.<br>This patch make the Asterisk enables to wait lest part of HTTP request.<br>Also increases acceptable HTTP body length to 40k to support more<br>larger request.<br><br>ASTERISK-28236<br><br>Change-Id: I48a401aa64a21c3b37bf3cb4e0486d64b7dd8aa1<br>---<br>M main/http.c<br>1 file changed, 29 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/http.c b/main/http.c</span><br><span>index 136c916..cf2ff5e 100644</span><br><span>--- a/main/http.c</span><br><span>+++ b/main/http.c</span><br><span>@@ -84,11 +84,18 @@</span><br><span> </span><br><span> /*! Maximum application/json or application/x-www-form-urlencoded body content length. */</span><br><span> #if !defined(LOW_MEMORY)</span><br><span style="color: hsl(0, 100%, 40%);">-#define MAX_CONTENT_LENGTH 4096</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_CONTENT_LENGTH 40960</span><br><span> #else</span><br><span> #define MAX_CONTENT_LENGTH 1024</span><br><span> #endif /* !defined(LOW_MEMORY) */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Initial response body length. */</span><br><span style="color: hsl(120, 100%, 40%);">+#if !defined(LOW_MEMORY)</span><br><span style="color: hsl(120, 100%, 40%);">+#define INITIAL_RESPONSE_BODY_BUFFER 1024</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+#define INITIAL_RESPONSE_BODY_BUFFER 512</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* !defined(LOW_MEMORY) */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Maximum line length for HTTP requests. */</span><br><span> #if !defined(LOW_MEMORY)</span><br><span> #define MAX_HTTP_LINE_LENGTH 4096</span><br><span>@@ -563,7 +570,7 @@</span><br><span> {</span><br><span> char server_name[MAX_SERVER_NAME_LENGTH];</span><br><span> struct ast_str *server_address = ast_str_create(MAX_SERVER_NAME_LENGTH);</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_str *out = ast_str_create(MAX_CONTENT_LENGTH);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *out = ast_str_create(INITIAL_RESPONSE_BODY_BUFFER);</span><br><span> </span><br><span> if (!http_header_data || !server_address || !out) {</span><br><span> ast_free(http_header_data);</span><br><span>@@ -922,19 +929,30 @@</span><br><span> static int http_body_read_contents(struct ast_tcptls_session_instance *ser, char *buf, int length, const char *what_getting)</span><br><span> {</span><br><span> int res;</span><br><span style="color: hsl(120, 100%, 40%);">+ int total = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /*</span><br><span style="color: hsl(0, 100%, 40%);">- * NOTE: Because ser->f is a non-standard FILE *, fread() does not behave as</span><br><span style="color: hsl(0, 100%, 40%);">- * documented.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Stream is in exclusive mode so we get it all if possible. */</span><br><span style="color: hsl(120, 100%, 40%);">+ while (total != length) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * NOTE: Because ser->f is a non-standard FILE *, fread() does not behave as</span><br><span style="color: hsl(120, 100%, 40%);">+ * documented.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Stay in fread until get all the expected data or timeout. */</span><br><span style="color: hsl(0, 100%, 40%);">- res = fread(buf, length, 1, ser->f);</span><br><span style="color: hsl(0, 100%, 40%);">- if (res < 1) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Short HTTP request %s (Wanted %d)\n",</span><br><span style="color: hsl(0, 100%, 40%);">- what_getting, length);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Stay in fread until get all the expected data or timeout. */</span><br><span style="color: hsl(120, 100%, 40%);">+ res = fread(buf + total, length - total, 1, ser->f);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res <= 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ total += res;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (total != length) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Wrong HTTP content read. Request %s (Wanted %d, Read %d)\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ what_getting, length, res);</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/11026">change 11026</a>. To unsubscribe, or for help writing mail filters, 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/11026"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I48a401aa64a21c3b37bf3cb4e0486d64b7dd8aa1 </div>
<div style="display:none"> Gerrit-Change-Number: 11026 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>