提交 7c434d61 编写于 作者: F freemine

add env FALLBACK, for the sake of easy debug in different mode

上级 93cb6386
......@@ -242,6 +242,8 @@ typedef struct HttpServer {
pthread_mutex_t serverMutex;
HttpDecodeMethod *methodScanner[HTTP_METHOD_SCANNER_SIZE];
bool (*processData)(HttpContext *pContext);
int fallback:2;
} HttpServer;
extern const char *httpKeepAliveStr[];
......
......@@ -72,6 +72,13 @@ static void httpDestroyContext(void *data) {
httpFreeJsonBuf(pContext);
httpFreeMultiCmds(pContext);
if (!tsHttpServer.fallback) {
if (pContext->parser.parser) {
ehttp_parser_destroy(pContext->parser.parser);
pContext->parser.parser = NULL;
}
}
tfree(pContext);
}
......@@ -169,11 +176,6 @@ void httpReleaseContext(HttpContext *pContext) {
httpDebug("context:%p, won't be destroyed for cache is already released", pContext);
// httpDestroyContext((void **)(&ppContext));
}
if (pContext->parser.parser) {
ehttp_parser_destroy(pContext->parser.parser);
pContext->parser.parser = NULL;
}
}
bool httpInitContext(HttpContext *pContext) {
......@@ -193,19 +195,21 @@ bool httpInitContext(HttpContext *pContext) {
memset(pParser, 0, sizeof(HttpParser));
pParser->pCur = pParser->pLast = pParser->buffer;
ehttp_parser_callbacks_t callbacks = {
on_request_line,
on_status_line,
on_header_field,
on_body,
on_end,
on_error
};
ehttp_parser_conf_t conf = {
.flush_block_size = 0
};
pParser->parser = ehttp_parser_create(callbacks, conf, pContext);
pParser->inited = 1;
if (!tsHttpServer.fallback) {
ehttp_parser_callbacks_t callbacks = {
on_request_line,
on_status_line,
on_header_field,
on_body,
on_end,
on_error
};
ehttp_parser_conf_t conf = {
.flush_block_size = 0
};
pParser->parser = ehttp_parser_create(callbacks, conf, pContext);
pParser->inited = 1;
}
httpDebug("context:%p, fd:%d, ip:%s, thread:%s, accessTimes:%d, parsed:%d",
pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->accessTimes, pContext->parsed);
......
......@@ -138,7 +138,7 @@ static bool httpDecompressData(HttpContext *pContext) {
}
static bool httpReadData(HttpContext *pContext) {
if (1) return ehttpReadData(pContext);
if (!tsHttpServer.fallback) return ehttpReadData(pContext);
if (!pContext->parsed) {
httpInitContext(pContext);
......@@ -437,11 +437,13 @@ static bool ehttpReadData(HttpContext *pContext) {
if (strstr(buf, "GET ")==buf && !strchr(buf, '\r') && !strchr(buf, '\n')) {
D("==half of request line received:\n%s\n==", buf);
}
if (ehttp_parser_parse(pParser->parser, buf, nread)) {
D("==parsing failed==");
httpCloseContextByServer(pContext);
return false;
}
if (pContext->parser.failed) {
D("==parsing failed: [0x%x]==", pContext->parser.failed);
httpNotifyContextClose(pContext);
......@@ -450,7 +452,7 @@ static bool ehttpReadData(HttpContext *pContext) {
if (pContext->parsed) {
// int ret = httpCheckReadCompleted(pContext);
// already done in ehttp_parser
int ret = HTTP_CHECK_BODY_SUCCESS;
int ret = HTTP_CHECK_BODY_SUCCESS;
if (ret == HTTP_CHECK_BODY_CONTINUE) {
//httpDebug("context:%p, fd:%d, ip:%s, not finished yet, wait another event", pContext, pContext->fd, pContext->ipstr);
httpReleaseContext(pContext);
......
......@@ -39,6 +39,12 @@ HttpServer tsHttpServer;
void taosInitNote(int numOfNoteLines, int maxNotes, char* lable);
int httpInitSystem() {
tsHttpServer.fallback = 0;
const char *v = getenv("FALLBACK");
if (v) {
tsHttpServer.fallback = 1;
}
strcpy(tsHttpServer.label, "rest");
tsHttpServer.serverIp = 0;
tsHttpServer.serverPort = tsHttpPort;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册