[Asterisk-code-review] http.c: Support separated HTTP request (asterisk[master])

Friendly Automation asteriskteam at digium.com
Tue Feb 26 07:17:54 CST 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/10869 )

Change subject: http.c: Support separated HTTP request
......................................................................

http.c: Support separated HTTP request

Currently, the Asterisk does not support seperated HTTP request.
This patch make the Asterisk enables to wait lest part of HTTP request.
Also increases acceptable HTTP body length to 40k to support more
larger request.

ASTERISK-28236

Change-Id: I48a401aa64a21c3b37bf3cb4e0486d64b7dd8aa1
---
M main/http.c
1 file changed, 23 insertions(+), 6 deletions(-)

Approvals:
  Matthew Fredrickson: Looks good to me, but someone else must approve
  Joshua C. Colp: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/main/http.c b/main/http.c
index dcf90ae..e27f2ce 100644
--- a/main/http.c
+++ b/main/http.c
@@ -82,11 +82,18 @@
 
 /*! Maximum application/json or application/x-www-form-urlencoded body content length. */
 #if !defined(LOW_MEMORY)
-#define MAX_CONTENT_LENGTH 4096
+#define MAX_CONTENT_LENGTH 40960
 #else
 #define MAX_CONTENT_LENGTH 1024
 #endif	/* !defined(LOW_MEMORY) */
 
+/*! Initial response body length. */
+#if !defined(LOW_MEMORY)
+#define INITIAL_RESPONSE_BODY_BUFFER 1024
+#else
+#define INITIAL_RESPONSE_BODY_BUFFER 512
+#endif	/* !defined(LOW_MEMORY) */
+
 /*! Maximum line length for HTTP requests. */
 #if !defined(LOW_MEMORY)
 #define MAX_HTTP_LINE_LENGTH 4096
@@ -557,7 +564,7 @@
 {
 	char server_name[MAX_SERVER_NAME_LENGTH];
 	struct ast_str *server_address = ast_str_create(MAX_SERVER_NAME_LENGTH);
-	struct ast_str *out = ast_str_create(MAX_CONTENT_LENGTH);
+	struct ast_str *out = ast_str_create(INITIAL_RESPONSE_BODY_BUFFER);
 
 	if (!http_header_data || !server_address || !out) {
 		ast_free(http_header_data);
@@ -916,14 +923,24 @@
 static int http_body_read_contents(struct ast_tcptls_session_instance *ser, char *buf, int length, const char *what_getting)
 {
 	int res;
+	int total = 0;
 
 	/* Stream is in exclusive mode so we get it all if possible. */
-	res = ast_iostream_read(ser->stream, buf, length);
-	if (res < length) {
-		ast_log(LOG_WARNING, "Short HTTP request %s (Wanted %d)\n",
-			what_getting, length);
+	while (total != length) {
+		res = ast_iostream_read(ser->stream, buf + total, length - total);
+		if (res <= 0) {
+			break;
+		}
+
+		total += res;
+	}
+
+	if (total != length) {
+		ast_log(LOG_WARNING, "Wrong HTTP content read. Request %s (Wanted %d, Read %d)\n",
+			what_getting, length, res);
 		return -1;
 	}
+
 	return 0;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/10869
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I48a401aa64a21c3b37bf3cb4e0486d64b7dd8aa1
Gerrit-Change-Number: 10869
Gerrit-PatchSet: 9
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
Gerrit-Reviewer: Michael L. Young <elgueromexicano at gmail.com>
Gerrit-Reviewer: sungtae kim <pchero21 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190226/90019015/attachment.html>


More information about the asterisk-code-review mailing list