コード例 #1
0
static int
ts_lua_client_request_get_body_size(lua_State *L)
{
    int64_t body_size;
    ts_lua_http_ctx  *http_ctx;

    http_ctx = ts_lua_get_http_ctx(L);

    body_size = TSHttpTxnClientReqBodyBytesGet(http_ctx->txnp);
    lua_pushnumber(L, body_size);

    return 1;
}
コード例 #2
0
ファイル: remap_stats.c プロジェクト: 333777/trafficserver
static int
handle_txn_close(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
{
  TSHttpTxn txn = (TSHttpTxn) edata;
  config_t *config;
  void *txnd;
  int status_code = 0;
  TSMBuffer buf;
  TSMLoc hdr_loc;
  uint64_t out_bytes, in_bytes;
  char *remap, *hostname;
  char *unknown = "unknown";
  char stat_name[MAX_STAT_LENGTH];

  config = (config_t *) TSContDataGet(cont);
  txnd = TSHttpTxnArgGet(txn, config->txn_slot);

  hostname = (char *) ((uintptr_t) txnd & (~((uintptr_t) 0x01)));       // Get hostname

  if (txnd) {
    if ((uintptr_t) txnd & 0x01)        // remap succeeded?
    {
      if (!config->post_remap_host)
        remap = hostname;
      else
        remap = get_effective_host(txn);

      if (!remap)
        remap = unknown;

      in_bytes = TSHttpTxnClientReqHdrBytesGet(txn);
      in_bytes += TSHttpTxnClientReqBodyBytesGet(txn);

      CREATE_STAT_NAME(stat_name, remap, "in_bytes");
      stat_add(stat_name, (TSMgmtInt) in_bytes, config->persist_type, config->stat_creation_mutex);

      out_bytes = TSHttpTxnClientRespHdrBytesGet(txn);
      out_bytes += TSHttpTxnClientRespBodyBytesGet(txn);

      CREATE_STAT_NAME(stat_name, remap, "out_bytes");
      stat_add(stat_name, (TSMgmtInt) out_bytes, config->persist_type, config->stat_creation_mutex);

      if (TSHttpTxnClientRespGet(txn, &buf, &hdr_loc) == TS_SUCCESS) {
        status_code = (int) TSHttpHdrStatusGet(buf, hdr_loc);
        TSHandleMLocRelease(buf, TS_NULL_MLOC, hdr_loc);

        if (status_code < 200)
          CREATE_STAT_NAME(stat_name, remap, "status_other");
        else if (status_code <= 299)
          CREATE_STAT_NAME(stat_name, remap, "status_2xx");
        else if (status_code <= 399)
          CREATE_STAT_NAME(stat_name, remap, "status_3xx");
        else if (status_code <= 499)
          CREATE_STAT_NAME(stat_name, remap, "status_4xx");
        else if (status_code <= 599)
          CREATE_STAT_NAME(stat_name, remap, "status_5xx");
        else
          CREATE_STAT_NAME(stat_name, remap, "status_other");

        stat_add(stat_name, 1, config->persist_type, config->stat_creation_mutex);
      } else {
        CREATE_STAT_NAME(stat_name, remap, "status_unknown");
        stat_add(stat_name, 1, config->persist_type, config->stat_creation_mutex);
      }

      if (remap != unknown)
        TSfree(remap);
    } else if (hostname)
      TSfree(hostname);
  }

  TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
  TSDebug(DEBUG_TAG, "Handler Finished");
  return 0;
}