root/src/noit_http.h

Revision 49e329e9ec43712076e6d8fa719ed3cebd9f66e7, 3.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

fix off-by-one in hex output for chunked encoding, support for deflate, deflate and non-deflate works with curl, but only non-deflate (regular chunked) works with firefox. refs #64

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_HTTP_H
7 #define _NOIT_HTTP_H
8
9 #include "noit_defines.h"
10 #include "eventer/eventer.h"
11 #include "utils/noit_hash.h"
12
13 typedef enum {
14   NOIT_HTTP_OTHER, NOIT_HTTP_GET, NOIT_HTTP_HEAD
15 } noit_http_method;
16 typedef enum {
17   NOIT_HTTP09, NOIT_HTTP10, NOIT_HTTP11
18 } noit_http_protocol;
19
20 #define NOIT_HTTP_CHUNKED 0x0001
21 #define NOIT_HTTP_CLOSE   0x0002
22 #define NOIT_HTTP_GZIP    0x0010
23 #define NOIT_HTTP_DEFLATE 0x0020
24
25 #define DEFAULT_BCHAINSIZE ((1 << 15)-(3*sizeof(size_t))-(2*sizeof(void *)))
26 /* 64k - delta */
27 #define DEFAULT_BCHAINMINREAD (DEFAULT_BCHAINSIZE/4)
28
29 struct bchain {
30   struct bchain *next, *prev;
31   size_t start; /* where data starts (buff + start) */
32   size_t size;  /* data length (past start) */
33   size_t allocd;/* total allocation */
34   char buff[1]; /* over allocate as needed */
35 };
36
37 #define BCHAIN_SPACE(a) ((a)->allocd - (a)->size - (a)->start)
38
39 API_EXPORT(struct bchain *) bchain_alloc(size_t size);
40 API_EXPORT(void) bchain_free(struct bchain *);
41
42 typedef struct {
43   eventer_t e;
44   int needs_close;
45 } noit_http_connection;
46
47 typedef struct {
48   struct bchain *first_input; /* The start of the input chain */
49   struct bchain *last_input;  /* The end of the input chain */
50   struct bchain *current_input;  /* The point of the input where we */
51   size_t         current_offset; /* analyzing. */
52
53   struct bchain *current_request_chain;
54   char *method_str;
55   char *uri_str;
56   char *protocol_str;
57   u_int32_t opts;
58   noit_http_method method;
59   noit_http_protocol protocol;
60   noit_hash_table headers;
61   noit_boolean complete;
62 } noit_http_request;
63
64 typedef struct {
65   noit_http_protocol protocol;
66   int status_code;
67   char *status_reason;
68
69   noit_hash_table headers;
70   struct bchain *leader; /* serialization of status line and headers */
71
72   u_int32_t output_options;
73   struct bchain *output;       /* data is pushed in here */
74   struct bchain *output_raw;   /* internally transcoded here for output */
75   size_t output_raw_offset;    /* tracks our offset */
76   noit_boolean output_started; /* locks the options and leader */
77                                /*   and possibly output. */
78   noit_boolean closed;         /* set by _end() */
79   noit_boolean complete;       /* complete, drained and disposable */
80 } noit_http_response;
81
82 struct noit_http_session_ctx;
83 typedef int (*noit_http_dispatch_func) (struct noit_http_session_ctx *);
84
85 typedef struct noit_http_session_ctx {
86   noit_http_connection conn;
87   noit_http_request req;
88   noit_http_response res;
89   noit_http_dispatch_func dispatcher;
90   void *dispatcher_closure;
91   eventer_func_t drive;
92 } noit_http_session_ctx;
93
94 API_EXPORT(noit_http_session_ctx *)
95   noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t);
96
97 API_EXPORT(int)
98   noit_http_session_drive(eventer_t, int, void *, struct timeval *);
99
100 API_EXPORT(noit_boolean)
101   noit_http_response_status_set(noit_http_session_ctx *, int, const char *);
102 API_EXPORT(noit_boolean)
103   noit_http_response_header_set(noit_http_session_ctx *,
104                                 const char *, const char *);
105 API_EXPORT(noit_boolean)
106   noit_http_response_option_set(noit_http_session_ctx *, u_int32_t);
107 API_EXPORT(noit_boolean)
108   noit_http_response_append(noit_http_session_ctx *, const void *, size_t);
109 API_EXPORT(noit_boolean)
110   noit_http_response_append_bchain(noit_http_session_ctx *, struct bchain *);
111 API_EXPORT(noit_boolean)
112   noit_http_response_flush(noit_http_session_ctx *, noit_boolean);
113 API_EXPORT(noit_boolean) noit_http_response_end(noit_http_session_ctx *);
114
115 #endif
Note: See TracBrowser for help on using the browser.