about summary refs log tree commit homepage
path: root/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'http.c')
-rw-r--r--http.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/http.c b/http.c
index 1485eb2..4519498 100644
--- a/http.c
+++ b/http.c
@@ -33,15 +33,15 @@ static void
 http_defer_rbuf(struct mog_http *http, struct mog_rbuf *rbuf, size_t buf_len)
 {
         struct mog_rbuf *old = http->rbuf;
-        size_t defer_bytes = buf_len - http->offset;
-        char *src = rbuf->rptr + http->offset;
+        size_t defer_bytes = buf_len - http->_p.offset;
+        char *src = rbuf->rptr + http->_p.offset;
 
-        if (http->skip_rbuf_defer) {
-                http->skip_rbuf_defer = 0;
+        if (http->_p.skip_rbuf_defer) {
+                http->_p.skip_rbuf_defer = 0;
                 return;
         }
 
-        assert(http->offset >= 0 && "http->offset negative");
+        assert(http->_p.offset >= 0 && "http->_p.offset negative");
         assert(defer_bytes <= MOG_RBUF_MAX_SIZE && "defer bytes overflow");
 
         if (defer_bytes == 0) {
@@ -55,13 +55,13 @@ http_defer_rbuf(struct mog_http *http, struct mog_rbuf *rbuf, size_t buf_len)
                 memcpy(http->rbuf->rptr, src, defer_bytes);
                 http->rbuf->rsize = defer_bytes;
         }
-        http->offset = 0;
+        http->_p.offset = 0;
 }
 
 static void
 http_process_client(struct mog_http *http, char *buf, size_t buf_len)
 {
-        switch (http->http_method) {
+        switch (http->_p.http_method) {
         case MOG_HTTP_METHOD_NONE: assert(0 && "BUG: unset HTTP method");
         case MOG_HTTP_METHOD_GET: mog_http_get_open(http, buf); break;
         case MOG_HTTP_METHOD_HEAD: mog_http_get_open(http, buf); break;
@@ -99,10 +99,10 @@ static enum mog_next http_wbuf_in_progress(struct mog_http *http)
         case MOG_WRSTATE_ERR:
                 return MOG_NEXT_CLOSE;
         case MOG_WRSTATE_DONE:
-                if (!http->persistent) return MOG_NEXT_CLOSE;
+                if (!http->_p.persistent) return MOG_NEXT_CLOSE;
                 if (http->forward == NULL)
                         mog_http_reset(http);
-                assert(http->offset == 0 && "bad offset");
+                assert(http->_p.offset == 0 && "bad offset");
                 return MOG_NEXT_ACTIVE;
         case MOG_WRSTATE_BUSY:
                 /* unlikely, we never put anything big in wbuf */
@@ -114,7 +114,7 @@ static enum mog_next http_wbuf_in_progress(struct mog_http *http)
 
 static enum mog_next http_forward_in_progress(struct mog_fd *mfd)
 {
-        enum mog_http_method method = mfd->as.http.http_method;
+        enum mog_http_method method = mfd->as.http._p.http_method;
 
         if (method == MOG_HTTP_METHOD_GET)
                 return mog_http_get_in_progress(mfd);
@@ -142,15 +142,16 @@ static enum mog_next http_queue_step(struct mog_fd *mfd)
         /* we may have pipelined data in http->rbuf */
         rbuf = http->rbuf ? http->rbuf : mog_rbuf_get(MOG_RBUF_BASE_SIZE);
         buf = rbuf->rptr;
-        off = http->offset;
+        off = http->_p.offset;
         assert(off >= 0 && "offset is negative");
         assert(off < rbuf->rcapa && "offset is too big");
         if (http->rbuf) {
                 /* request got pipelined, resuming now */
                 buf_len = http->rbuf->rsize;
-                assert(http->offset <= buf_len && "bad offset from pipelining");
+                assert(http->_p.offset <= buf_len
+                        && "bad offset from pipelining");
                 assert(buf_len <= http->rbuf->rcapa && "bad rsize stashed");
-                if (http->offset < buf_len)
+                if (http->_p.offset < buf_len)
                         goto parse;
         }
 reread:
@@ -166,14 +167,14 @@ parse:
                 case MOG_PARSER_CONTINUE:
                         assert(http->wbuf == NULL &&
                                "tried to write (and failed) with partial req");
-                        if (http->offset >= rbuf->rcapa) {
+                        if (http->_p.offset >= rbuf->rcapa) {
                                 rbuf->rsize = buf_len;
                                 http->rbuf = rbuf = mog_rbuf_grow(rbuf);
                                 if (!rbuf)
                                         goto err400;
                                 buf = rbuf->rptr;
                         }
-                        off = http->offset;
+                        off = http->_p.offset;
                         goto reread;
                 case MOG_PARSER_DONE:
                         http_process_client(http, buf, buf_len);
@@ -185,7 +186,7 @@ parse:
                         } else if (http->forward) {
                                 http_defer_rbuf(http, rbuf, buf_len);
                                 return http_forward_in_progress(mfd);
-                        } else if (!http->persistent) {
+                        } else if (!http->_p.persistent) {
                                 return MOG_NEXT_CLOSE;
                         } else {
                                 http_defer_rbuf(http, rbuf, buf_len);
@@ -288,15 +289,16 @@ void mog_httpget_post_accept(int fd, struct mog_svc *svc)
  */
 char *mog_http_path(struct mog_http *http, char *buf)
 {
-        char *path = buf + http->path_tip;
-        size_t len = http->path_end - http->path_tip;
+        char *path = buf + http->_p.path_tip;
+        size_t len = http->_p.path_end - http->_p.path_tip;
 
-        assert(http->path_end > http->path_tip && "bad HTTP path from parser");
+        assert(http->_p.path_end > http->_p.path_tip
+                && "bad HTTP path from parser");
 
         if (! mog_valid_path(path, len))
                 return NULL;
 
-        if (http->http_method == MOG_HTTP_METHOD_PUT) {
+        if (http->_p.http_method == MOG_HTTP_METHOD_PUT) {
                 if (!mog_valid_put_path(path, len)) {
                         errno = EINVAL;
                         return NULL;
@@ -330,12 +332,12 @@ mog_http_resp0(
         dst = CPY("\r\nDate: ");
         now = mog_now();
         dst = mempcpy(dst, now->httpdate, sizeof(now->httpdate)-1);
-        if (alive && http->persistent) {
+        if (alive && http->_p.persistent) {
                 dst = CPY("\r\nContent-Length: 0"
                         "\r\nContent-Type: text/plain"
                         "\r\nConnection: keep-alive\r\n\r\n");
         } else {
-                http->persistent = 0;
+                http->_p.persistent = 0;
                 dst = CPY("\r\nContent-Length: 0"
                         "\r\nContent-Type: text/plain"
                         "\r\nConnection: close\r\n\r\n");