[Home]

Summary:ASTERISK-18064: Asterisk's AMI over HTTP adds an extra \r\n in the headers causing strict parsers to fail
Reporter:m0bius (m0bius)Labels:
Date Opened:2011-06-25 04:32:39Date Closed:2011-07-26 09:46:45
Priority:MinorRegression?
Status:Closed/CompleteComponents:Core/ManagerInterface
Versions:1.8.4 Frequency of
Occurrence
Constant
Related
Issues:
Environment:Attachments:( 0) manager.patch
Description:In the http.c module the headers are constructed as:

{quote}
/* send http header */
       fprintf(ser->f, "HTTP/1.1 %d %s\r\n"
               "Server: Asterisk/%s\r\n"
               "Date: %s\r\n"
               "Connection: close\r\n"
               "%s"
               "Content-Length: %d\r\n"
               "%s\r\n\r\n",
               status_code, status_title ? status_title : "OK",
               ast_get_version(),
               timebuf,
               static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
               content_length,
               http_header ? ast_str_buffer(http_header) : ""
               );
{quote}

In the case of MXML the headers being generated from the manager on generic_http_callback():

{quote}
ast_str_append(&http_header, 0,
               "Content-type: text/%s\r\n"
               "Cache-Control: no-cache;\r\n"
               "Set-Cookie: mansession_id=\"%08x\"; Version=1; Max-Age=%d\r\n"
               "Pragma: SuppressEvents\r\n",
               contenttype[format],
               session->managerid, httptimeout);
{quote}

The http_header is passed back to the http.c resulting in a response of the type:

{quote}
Pragma: SuppressEvents\r\n\r\n\r\n
{quote}

This is invalid HTTP 1.1 since it is expected that the headers from the body should be separated by one \r\n. Strict parsers consider the last \r\n to be a part of the body but then the Content-Length specified does not count up to contain the extra bytes.

Patch is simple, and attached.
Comments:By: Jonathan Rose (jrose) 2011-07-18 14:19:56.039-0500

@m0bius:  Has this been resolved already?  Looking at http.c in the current 1.8 from svn, ast_http_send has the following for this block:

/* send http header */
fprintf(ser->f, "HTTP/1.1 %d %s\r\n"
"Server: Asterisk/%s\r\n"
"Date: %s\r\n"
"Connection: close\r\n"
"%s"
"Content-Length: %d\r\n"
"%s"
"\r\n",
status_code, status_title ? status_title : "OK",
ast_get_version(),
timebuf,
static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
content_length,
http_header ? ast_str_buffer(http_header) : ""
);

Which as you'll notice is different from what you are showing and would only have "\r\n\r\n" on the element in question.
So I'm guessing at the moment this issue has already been resolved, just going at it from the opposite direction.

Please confirm whether this is still an issue at your earliest convenience.

By: Jonathan Rose (jrose) 2011-07-26 09:35:43.190-0500

Alright, based on blame files and svn logs, it's obvious to me that this was actually fixed back in March in the svn build of 1.8.  I'm pretty sure these changes should be in the latest 1.8 releases.

If the issue persists, please create another issue.

By: Jonathan Rose (jrose) 2011-07-26 09:46:45.057-0500

Addressed before the issue was even reported by qwell in 1.8 r309204