| 1 |
/* |
|---|
| 2 |
* Copyright (c) 2007, OmniTI Computer Consulting, Inc. |
|---|
| 3 |
* All rights reserved. |
|---|
| 4 |
*/ |
|---|
| 5 |
|
|---|
| 6 |
#include "noit_defines.h" |
|---|
| 7 |
#include "eventer/eventer.h" |
|---|
| 8 |
#include "noit_conf.h" |
|---|
| 9 |
#include "utils/noit_hash.h" |
|---|
| 10 |
#include "utils/noit_log.h" |
|---|
| 11 |
#include "jlog/jlog.h" |
|---|
| 12 |
#include "noit_jlog_listener.h" |
|---|
| 13 |
#include "noit_listener.h"c |
|---|
| 14 |
#include "noit_http.h" |
|---|
| 15 |
|
|---|
| 16 |
int |
|---|
| 17 |
stratcon_request_dispatcher(noit_http_session_ctx *ctx) { |
|---|
| 18 |
const char *key, *value; |
|---|
| 19 |
int klen; |
|---|
| 20 |
noit_hash_iter iter = NOIT_HASH_ITER_ZERO; |
|---|
| 21 |
noit_http_request *req = &ctx->req; |
|---|
| 22 |
|
|---|
| 23 |
noitL(noit_error, "http: %s %s %s\n", |
|---|
| 24 |
req->method_str, req->uri_str, req->protocol_str); |
|---|
| 25 |
while(noit_hash_next(&req->headers, &iter, &key, &klen, (void **)&value)) { |
|---|
| 26 |
noitL(noit_error, "http: [%s: %s]\n", key, value); |
|---|
| 27 |
} |
|---|
| 28 |
noit_http_response_status_set(ctx, 200, "OK"); |
|---|
| 29 |
noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED); |
|---|
| 30 |
noit_http_response_append(ctx, "Hello there!", 12); |
|---|
| 31 |
noit_http_response_flush(ctx, false); |
|---|
| 32 |
noit_http_response_append(ctx, "Hello there again!", 18); |
|---|
| 33 |
noit_http_response_end(ctx); |
|---|
| 34 |
ctx->conn.needs_close = noit_true; |
|---|
| 35 |
return 0; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
int |
|---|
| 39 |
stratcon_realtime_http_handler(eventer_t e, int mask, void *closure, |
|---|
| 40 |
struct timeval *now) { |
|---|
| 41 |
acceptor_closure_t *ac = closure; |
|---|
| 42 |
noit_http_session_ctx *http_ctx = ac->service_ctx; |
|---|
| 43 |
if(!http_ctx) { |
|---|
| 44 |
http_ctx = ac->service_ctx = |
|---|
| 45 |
noit_http_session_ctx_new(stratcon_request_dispatcher, e); |
|---|
| 46 |
} |
|---|
| 47 |
return http_ctx->drive(e, mask, http_ctx, now); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
void |
|---|
| 51 |
stratcon_realtime_http_init(const char *toplevel) { |
|---|
| 52 |
eventer_name_callback("stratcon_realtime_http", |
|---|
| 53 |
stratcon_realtime_http_handler); |
|---|
| 54 |
} |
|---|