fixed handle of dynamic variables in the compressed resources
This commit is contained in:
parent
0dde9cbc8b
commit
15de5c9b30
|
|
@ -175,10 +175,10 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
ESP_LOGI(TAG, "POST request handle");
|
ESP_LOGI(TAG, "POST request handle");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (memmem(req->uri, strlen(req->uri), "/storage/upload/", sizeof("/storage/upload/")-1))
|
if (memmem(req->uri, strlen(req->uri), "/storage/upload/", sizeof("/storage/upload/") - 1))
|
||||||
return upload_post_handler(req);
|
return upload_post_handler(req);
|
||||||
|
|
||||||
if (memmem(req->uri, strlen(req->uri), "/storage/delete/", sizeof("/storage/delete/")-1))
|
if (memmem(req->uri, strlen(req->uri), "/storage/delete/", sizeof("/storage/delete/") - 1))
|
||||||
return delete_post_handler(req);
|
return delete_post_handler(req);
|
||||||
|
|
||||||
char *buf = ((struct file_server_data*) req->user_ctx)->scratch;
|
char *buf = ((struct file_server_data*) req->user_ctx)->scratch;
|
||||||
|
|
@ -347,12 +347,7 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
}
|
}
|
||||||
//read first portion of data from file
|
//read first portion of data from file
|
||||||
readBytes = espfs_fread(file, buf, bufSize);
|
readBytes = espfs_fread(file, buf, bufSize);
|
||||||
//check if file is compressed by GZIP and add correspondent header
|
|
||||||
if (memmem(buf, 3, GZIP_SIGN, 3))
|
|
||||||
{
|
|
||||||
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
|
|
||||||
httpd_resp_set_hdr(req, "Cache-Control", "max-age=600");
|
|
||||||
}
|
|
||||||
|
|
||||||
//check if the file can contains dynamic variables
|
//check if the file can contains dynamic variables
|
||||||
if (IS_FILE_EXT(filename, ".html") ||
|
if (IS_FILE_EXT(filename, ".html") ||
|
||||||
|
|
@ -360,6 +355,15 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
IS_FILE_EXT(filename, ".css") ||
|
IS_FILE_EXT(filename, ".css") ||
|
||||||
IS_FILE_EXT(filename, ".js"))
|
IS_FILE_EXT(filename, ".js"))
|
||||||
isDynamicVars = true;
|
isDynamicVars = true;
|
||||||
|
|
||||||
|
//check if file is compressed by GZIP and add correspondent header
|
||||||
|
if (memmem(buf, 3, GZIP_SIGN, 3))
|
||||||
|
{
|
||||||
|
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
|
||||||
|
httpd_resp_set_hdr(req, "Cache-Control", "max-age=600");
|
||||||
|
isDynamicVars = false;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int pt = 0;
|
int pt = 0;
|
||||||
|
|
@ -393,9 +397,12 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
//unexpected end of file
|
//unexpected end of file
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Unexpected end of file");
|
||||||
goto file_send_error;
|
goto file_send_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (buf[pt] == '~' || ch == '~') //close tag, got valid dynamic variable name
|
if (buf[pt] == '~' || ch == '~') //close tag, got valid dynamic variable name
|
||||||
{
|
{
|
||||||
DynVarName[k] = 0x00;
|
DynVarName[k] = 0x00;
|
||||||
|
|
@ -406,8 +413,11 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
//not found close tag, exit by overflow max variable size or file end
|
//not found close tag, exit by overflow max variable size or file end
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Dyn variable close tag not found");
|
||||||
goto file_send_error;
|
goto file_send_error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
chunk[preparedBytes++] = buf[pt++]; //write to chunk ordinary character
|
chunk[preparedBytes++] = buf[pt++]; //write to chunk ordinary character
|
||||||
|
|
||||||
|
|
@ -417,8 +427,13 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
ESP_LOGI(TAG, "Call resp_send_chank because of chunk full. Send %d bytes", preparedBytes);
|
ESP_LOGI(TAG, "Call resp_send_chank because of chunk full. Send %d bytes", preparedBytes);
|
||||||
#endif
|
#endif
|
||||||
if (httpd_resp_send_chunk(req, chunk, preparedBytes) != ESP_OK)
|
esp_err_t send_err = httpd_resp_send_chunk(req, chunk, preparedBytes);
|
||||||
|
|
||||||
|
if (send_err != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "%s", esp_err_to_name(send_err));
|
||||||
goto file_send_error;
|
goto file_send_error;
|
||||||
|
}
|
||||||
preparedBytes = 0;
|
preparedBytes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -440,7 +455,7 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
while (bufSize > 0);
|
while (bufSize > 0);
|
||||||
|
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
ESP_LOGI(TAG, "File sending complete, read from file %d", (int)readBytes);
|
ESP_LOGI(TAG, "File sending complete, read from file %d", (int )readBytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Respond with an empty chunk to signal HTTP response completion */
|
/* Respond with an empty chunk to signal HTTP response completion */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user