示例#1
0
static int
noit_lua_http_header_set(lua_State *L) {
  const char *hdr, *val;
  CCALL_DECL(L, noit_http_session_ctx, http_ctx, 3);
  hdr = lua_tostring(L,2);
  val = lua_tostring(L,3);
  if(!hdr || !val) luaL_error(L, "invalid header or headervalue");
  noit_http_response_header_set(http_ctx, hdr, val);
  return 0;
}
static int
rest_cull_filter(noit_http_rest_closure_t *restc,
                 int npats, char **pats) {
  int rv;
  char cnt_str[32];
  noit_http_session_ctx *ctx = restc->http_ctx;

  rv = noit_filtersets_cull_unused();
  if(rv > 0) noit_conf_mark_changed();
  snprintf(cnt_str, sizeof(cnt_str), "%d", rv);
  noit_http_response_ok(ctx, "text/html");
  noit_http_response_header_set(ctx, "X-Filters-Removed", cnt_str);
  noit_http_response_end(ctx);
  return 0;
}
示例#3
0
static int
handoff_request_dispatcher(noit_http_session_ctx *ctx) {
  char *hello = "message:hello\r\n";
  if(the_one_and_only) {
    hello = "message:already connected\r\n";
    noit_http_response_server_error(ctx, "text/plain");
    noit_http_response_append(ctx, hello, strlen(hello));
    noit_http_response_end(ctx);
    return 0;
  }
  the_one_and_only = ctx;
  noit_http_response_status_set(ctx, 200, "OK");
  noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED);
  noit_http_response_header_set(ctx, "Content-Type", "text/plain");
  noit_http_response_append(ctx, hello, strlen(hello));
  noit_http_response_flush(ctx, noit_false);
  return EVENTER_EXCEPTION;
}
int
stratcon_request_dispatcher(noit_http_session_ctx *ctx) {
  const char *key, *value;
  realtime_context *rc = noit_http_session_dispatcher_closure(ctx);
  int klen;
  noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
  noit_http_request *req = noit_http_session_request(ctx);

  if(rc->setup == RC_INITIAL) {
    eventer_t completion;
    struct realtime_tracker *node;
    char c[1024];
    int num_interests;
    const char *uri_str = noit_http_request_uri_str(req);
    noit_hash_table *headers = noit_http_request_headers_table(req);

    num_interests = stratcon_realtime_uri_parse(rc, uri_str);
    if(num_interests == 0) {
      noit_http_response_status_set(ctx, 404, "OK");
      noit_http_response_option_set(ctx, NOIT_HTTP_CLOSE);
      noit_http_response_end(ctx);
      return 0;
    }

    noitL(noit_error, "http: %s %s %s\n",
          noit_http_request_method_str(req), uri_str,
          noit_http_request_protocol_str(req));
    while(noit_hash_next_str(headers, &iter, &key, &klen, &value)) {
      noitL(noit_error, "http: [%s: %s]\n", key, value);
    }
    noit_http_response_status_set(ctx, 200, "OK");
    noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED);
    /*noit_http_response_option_set(ctx, NOIT_HTTP_GZIP);*/
    /*noit_http_response_option_set(ctx, NOIT_HTTP_DEFLATE);*/
    noit_http_response_header_set(ctx, "Content-Type", "text/html");

    snprintf(c, sizeof(c),
             "<html><head><script>document.domain='%s';</script></head><body>\n",
             rc->document_domain);
    noit_http_response_append(ctx, c, strlen(c));

    /* this dumb crap is to make some browsers happy (Safari) */
    memset(c, ' ', sizeof(c));
    noit_http_response_append(ctx, c, sizeof(c));
    noit_http_response_flush(ctx, noit_false);

    rc->setup = RC_REQ_RECV;
    /* Each interest references the ctx */
    for(node = rc->checklist; node; node = node->next) {
      char uuid_str[UUID_STR_LEN+1];
      noit_http_session_ref_inc(ctx);
      uuid_unparse_lower(node->checkid, uuid_str);
      noitL(noit_error, "Resolving uuid: %s\n", uuid_str);
    }
    completion = eventer_alloc();
    completion->mask = EVENTER_TIMER;
    completion->callback = stratcon_realtime_http_postresolve;
    completion->closure = ctx;
    gettimeofday(&completion->whence, NULL);
    stratcon_datastore_push(DS_OP_FIND_COMPLETE, NULL, NULL,
                            rc->checklist, completion);
  }
  return EVENTER_EXCEPTION;
}