static int
ts_lua_server_response_get_version(lua_State * L)
{
  int version;
  char buf[32];
  int n;

  ts_lua_http_ctx *http_ctx;

  http_ctx = ts_lua_get_http_ctx(L);

  TS_LUA_CHECK_SERVER_RESPONSE_HDR(http_ctx);

  version = TSHttpHdrVersionGet(http_ctx->server_response_bufp, http_ctx->server_response_hdrp);

  n = snprintf(buf, sizeof(buf), "%d.%d", TS_HTTP_MAJOR(version), TS_HTTP_MINOR(version));

  if(n >= (int)sizeof(buf)) {
    lua_pushlstring(L, buf, sizeof(buf) - 1);
  } else if(n > 0) {
    lua_pushlstring(L, buf, n);
  }
  
  return 1;
}
示例#2
0
static int
ts_lua_client_request_get_version(lua_State *L)
{
    int     version;
    char    buf[32];
    int     n;

    ts_lua_http_ctx  *http_ctx;

    http_ctx = ts_lua_get_http_ctx(L);

    version = TSHttpHdrVersionGet(http_ctx->client_request_bufp, http_ctx->client_request_hdrp);

    n = snprintf(buf, sizeof(buf)-1, "%d.%d", TS_HTTP_MAJOR(version), TS_HTTP_MINOR(version));
    lua_pushlstring(L, buf, n);

    return 1;
}