예제 #1
0
static int
noit_lua_http_option_set(lua_State *L) {
  CCALL_DECL(L, noit_http_session_ctx, http_ctx, 2);
  u_int32_t opt = lua_tointeger(L,2);
  lua_pushboolean(L, noit_http_response_option_set(http_ctx, opt));
  return 1;
}
예제 #2
0
int
noit_rest_request_dispatcher(noit_http_session_ctx *ctx) {
  noit_http_rest_closure_t *restc = noit_http_session_dispatcher_closure(ctx);
  rest_request_handler handler = restc->fastpath;
  if(!handler) handler = noit_http_get_handler(restc);
  if(handler) {
    void *old_closure = restc, *new_closure;
    noit_http_response *res = noit_http_session_response(ctx);
    int rv;
    rv = handler(restc, restc->nparams, restc->params);
    /* If the request is closed, we need to cleanup.  However
     * if the dispatch closure has changed, the callee has done
     * something (presumably freeing the restc in the process)
     * and it would be unsafe for us to free it as well.
     */
    new_closure = noit_http_session_dispatcher_closure(ctx);
    if(old_closure == new_closure &&
       noit_http_response_closed(res)) noit_http_rest_clean_request(restc);
    return rv;
  }
  noit_http_response_status_set(ctx, 404, "NOT FOUND");
  noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED);
  noit_http_rest_clean_request(restc);
  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;
}