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

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

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