diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index 1e36fdef7562d3ee14d4f7ebbc9713cc749d6ee7..5012fd15f50478dfdc59d261ab7bcf1157d17d23 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -337,6 +337,7 @@ static void on_header_field(void *arg, const char *key, const char *val) { if (pParser->failed) return; + D("==key:[%s], val:[%s]==", key, val); int avail = sizeof(pParser->buffer) - (pParser->pLast - pParser->buffer); int n = snprintf(pParser->pLast, avail, "%s: %s\r\n", key, val); @@ -350,7 +351,7 @@ static void on_header_field(void *arg, const char *key, const char *val) { break; } pParser->bufsize += n; - pParser->pCur = pParser->pLast; + pParser->pCur = pParser->pLast + n; if (!httpParseHead(pContext)) { httpDebug("context:%p, fd:%d, ip:%s, thread:%s, accessTimes:%d, on_header_field(%s,%s), parse head failed", @@ -372,9 +373,19 @@ static void on_body(void *arg, const char *chunk, size_t len) { if (pParser->failed) return; - if (pParser->data.pos == 0) pParser->data.pos = pParser->pLast; + if (pParser->data.pos == 0) { + pParser->data.pos = pParser->pLast; + pParser->data.len = 0; + } - A("not implemented yet"); + int avail = sizeof(pParser->buffer) - (pParser->pLast - pParser->buffer); + if (len+1>=avail) { + pParser->failed |= EHTTP_CONTEXT_PROCESS_FAILED; + return; + } + memcpy(pParser->pLast, chunk, len); + pParser->pLast += len; + pParser->data.len += len; } static void on_end(void *arg) { diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index d21fa89d5cadc760dd425d3ec0c8972c97bcde2e..4f2ea63dc2462ac0681f7b7540f4886c1717fecf 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -138,7 +138,7 @@ static bool httpDecompressData(HttpContext *pContext) { } static bool httpReadData(HttpContext *pContext) { - if (0) return ehttpReadData(pContext); + if (1) return ehttpReadData(pContext); if (!pContext->parsed) { httpInitContext(pContext); @@ -448,7 +448,9 @@ static bool ehttpReadData(HttpContext *pContext) { return false; } if (pContext->parsed) { - int ret = httpCheckReadCompleted(pContext); + // int ret = httpCheckReadCompleted(pContext); + // already done in ehttp_parser + 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);