static void
parse_response(StateInfo *state)
{
  TSIOBufferBlock block;
  TSParseResult pr = TS_PARSE_CONT;
  int64_t avail;
  char *start;

  block = TSIOBufferReaderStart(state->resp_io_buf_reader);

  while ((pr == TS_PARSE_CONT) && (block != NULL)) {
    start = (char *)TSIOBufferBlockReadStart(block, state->resp_io_buf_reader, &avail);
    if (avail > 0) {
      pr = TSHttpHdrParseResp(state->resp_info->parser, state->resp_info->buf, state->resp_info->http_hdr_loc,
                              (const char **)&start, (const char *)(start + avail));
    }
    block = TSIOBufferBlockNext(block);
  }

  if (pr != TS_PARSE_CONT) {
    state->resp_info->status = TSHttpHdrStatusGet(state->resp_info->buf, state->resp_info->http_hdr_loc);
    state->resp_info->parsed = true;
    TSDebug(PLUGIN_NAME, "HTTP Status: %d", state->resp_info->status);
  }
}
Exemplo n.º 2
0
int
ts_http_fetcher_parse_header(http_fetcher *fch)
{
    int64_t         avail, used;
    const char      *start, *guard, *end;
    int             ret;
    TSIOBufferBlock blk;

    blk = TSIOBufferReaderStart(fch->resp_reader);

    while (blk) {
        guard = start = TSIOBufferBlockReadStart(blk, fch->resp_reader, &avail);
        end = start + avail;

        ret = TSHttpHdrParseResp(fch->http_parser, fch->hdr_bufp, fch->hdr_loc, &start, end);

        switch (ret) {

            case TS_PARSE_ERROR:
                return -1;

            case TS_PARSE_DONE:
                used = start - guard;
                TSIOBufferCopy(fch->hdr_buffer, fch->resp_reader, used, 0);
                TSIOBufferReaderConsume(fch->resp_reader, used);

                ts_http_fetcher_extract(fch);
                // ts_http_fetcher_setup_filter(fch);

                fch->header_done = 1;

                return 0;

            default:
                TSIOBufferCopy(fch->hdr_buffer, fch->resp_reader, avail, 0);
                TSIOBufferReaderConsume(fch->resp_reader, avail);
                break;
        }

        blk = TSIOBufferBlockNext(blk);
    }

    return 0;
}