AnsweredAssumed Answered

MQX 4.1 RTCS web_hvac response.content_length question

Question asked by pbanta on Oct 10, 2014
Latest reply on Oct 14, 2014 by Karel Mozny

It's not clear to me how to set response.content_length in my CGI functions.

 

The MQX_RTCS User Guide says in section 8.2.14:

 

content_length

Length of the response entity from CGI script.

 

 

If you look at the web_hvac example there are conflicting examples of how to set the content_length field.

 

Example 1 - content_length is set to data_length

In cgi_index.c there is this code:

/* Calculate content length while saving it to buffer */
length = snprintf(str, BUFF_SIZE, "%ld\n%ld\n%ld\n", hour, min, sec);
response.data = str;
response.data_length = length;
response.content_length = response.data_length;
/* Send response */
HTTPSRV_cgi_write(&response);
return (response.content_length);

 

This seems to match what it says in the MQX RTCS User Guide.

 

Example 2 - content_length is set to zero

In cgi_hvac.c there is this code:

response.ses_handle = param->ses_handle;
response.content_type = HTTPSRV_CONTENT_TYPE_HTML;
response.status_code = 200;
response.data = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
    "<html><head><title>HVAC Settings response</title>"
    "<meta http-equiv=\"REFRESH\" content=\"0;url=hvac.shtml\"></head>\n<body>\n";
response.data_length = strlen(response.data);
response.content_length = 0;
HTTPSRV_cgi_write(&response);

if (!bParams)
{
    response.data = "No parameters received.<br>\n";
    response.data_length = strlen(response.data);
    HTTPSRV_cgi_write(&response);
}
response.data = "<br><br>\n</body></html>";
response.data_length = strlen(response.data);
HTTPSRV_cgi_write(&response);
return (response.content_length);

 

In this case there are multiple calls to HTTPSRV_cgi_write() and content_length is set to zero on line 8.  It is never set to non-zero.

 

My question:

1. When should content_length be set to data_length and when should it be set to zero?

 

Thanks,

 

Paul

Outcomes