diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-01-12 21:51:12 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2020-07-08 19:54:29 -0400 |
commit | 7c7f8c467c8b6af678faf10078d7a59c3856045a (patch) | |
tree | 491b6c04ef37043a51e230825aab4deb0a347c47 /src/http_chunk.c | |
parent | cc2134c88badd541cfe1954c80e371db5f28ede3 (diff) | |
download | lighttpd-git-7c7f8c467c8b6af678faf10078d7a59c3856045a.tar.gz |
[multiple] split con, request (very large change)
NB: r->tmp_buf == srv->tmp_buf (pointer is copied for quicker access)
NB: request read and write chunkqueues currently point to connection
chunkqueues; per-request and per-connection chunkqueues are
not distinct from one another
con->read_queue == r->read_queue
con->write_queue == r->write_queue
NB: in the future, a separate connection config may be needed for
connection-level module hooks. Similarly, might need to have
per-request chunkqueues separate from per-connection chunkqueues.
Should probably also have a request_reset() which is distinct from
connection_reset().
Diffstat (limited to 'src/http_chunk.c')
-rw-r--r-- | src/http_chunk.c | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/src/http_chunk.c b/src/http_chunk.c index ca2d2b83..89b18e6a 100644 --- a/src/http_chunk.c +++ b/src/http_chunk.c @@ -54,15 +54,15 @@ static int http_chunk_len_append_tempfile(chunkqueue * const cq, uintmax_t len, #endif } -static int http_chunk_append_file_open_fstat(connection * const con, const buffer * const fn, struct stat * const st) { +static int http_chunk_append_file_open_fstat(const request_st * const r, const buffer * const fn, struct stat * const st) { return - (con->conf.follow_symlink - || !stat_cache_path_contains_symlink(fn, con->conf.errh)) - ? stat_cache_open_rdonly_fstat(fn, st, con->conf.follow_symlink) + (r->conf.follow_symlink + || !stat_cache_path_contains_symlink(fn, r->conf.errh)) + ? stat_cache_open_rdonly_fstat(fn, st, r->conf.follow_symlink) : -1; } -static int http_chunk_append_read_fd_range(connection * const con, const buffer * const fn, const int fd, off_t offset, off_t len) { +static int http_chunk_append_read_fd_range(request_st * const r, const buffer * const fn, const int fd, off_t offset, off_t len) { /* note: this routine should not be used for range requests * unless the total size of ranges requested is small */ /* note: future: could read into existing MEM_CHUNK in cq->last if @@ -70,9 +70,9 @@ static int http_chunk_append_read_fd_range(connection * const con, const buffer * offset in for cq->bytes_in in chunkqueue_append_buffer_commit() */ UNUSED(fn); - chunkqueue * const cq = con->write_queue; + chunkqueue * const cq = r->write_queue; - if (con->response.send_chunked) + if (r->resp_send_chunked) http_chunk_len_append(cq, (uintmax_t)len); if (0 != offset && -1 == lseek(fd, offset, SEEK_SET)) return -1; @@ -84,28 +84,28 @@ static int http_chunk_append_read_fd_range(connection * const con, const buffer } while (rd > 0 ? (offset += rd, len -= rd) : errno == EINTR); buffer_commit(b, offset); - if (con->response.send_chunked) + if (r->resp_send_chunked) buffer_append_string_len(b, CONST_STR_LEN("\r\n")); chunkqueue_append_buffer_commit(cq); return (rd >= 0) ? 0 : -1; } -static void http_chunk_append_file_fd_range(connection * const con, const buffer * const fn, const int fd, const off_t offset, const off_t len) { - chunkqueue * const cq = con->write_queue; +static void http_chunk_append_file_fd_range(request_st * const r, const buffer * const fn, const int fd, const off_t offset, const off_t len) { + chunkqueue * const cq = r->write_queue; - if (con->response.send_chunked) + if (r->resp_send_chunked) http_chunk_len_append(cq, (uintmax_t)len); chunkqueue_append_file_fd(cq, fn, fd, offset, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) chunkqueue_append_mem(cq, CONST_STR_LEN("\r\n")); } -int http_chunk_append_file_range(connection * const con, const buffer * const fn, const off_t offset, off_t len) { +int http_chunk_append_file_range(request_st * const r, const buffer * const fn, const off_t offset, off_t len) { struct stat st; - const int fd = http_chunk_append_file_open_fstat(con, fn, &st); + const int fd = http_chunk_append_file_open_fstat(r, fn, &st); if (fd < 0) return -1; if (-1 == len) { @@ -120,42 +120,42 @@ int http_chunk_append_file_range(connection * const con, const buffer * const fn return -1; } - http_chunk_append_file_fd_range(con, fn, fd, offset, len); + http_chunk_append_file_fd_range(r, fn, fd, offset, len); return 0; } -int http_chunk_append_file(connection * const con, const buffer * const fn) { +int http_chunk_append_file(request_st * const r, const buffer * const fn) { struct stat st; - const int fd = http_chunk_append_file_open_fstat(con, fn, &st); + const int fd = http_chunk_append_file_open_fstat(r, fn, &st); if (fd < 0) return -1; - http_chunk_append_file_fd(con, fn, fd, st.st_size); + http_chunk_append_file_fd(r, fn, fd, st.st_size); return 0; } -int http_chunk_append_file_fd(connection * const con, const buffer * const fn, const int fd, const off_t sz) { +int http_chunk_append_file_fd(request_st * const r, const buffer * const fn, const int fd, const off_t sz) { if (sz > 32768) { - http_chunk_append_file_fd_range(con, fn, fd, 0, sz); + http_chunk_append_file_fd_range(r, fn, fd, 0, sz); return 0; } /*(read small files into memory)*/ - int rc = (0 != sz) ? http_chunk_append_read_fd_range(con,fn,fd,0,sz) : 0; + int rc = (0 != sz) ? http_chunk_append_read_fd_range(r,fn,fd,0,sz) : 0; close(fd); return rc; } -static int http_chunk_append_to_tempfile(connection * const con, const char * const mem, const size_t len) { - chunkqueue * const cq = con->write_queue; - log_error_st * const errh = con->conf.errh; +static int http_chunk_append_to_tempfile(request_st * const r, const char * const mem, const size_t len) { + chunkqueue * const cq = r->write_queue; + log_error_st * const errh = r->conf.errh; - if (con->response.send_chunked + if (r->resp_send_chunked && 0 != http_chunk_len_append_tempfile(cq, len, errh)) return -1; if (0 != chunkqueue_append_mem_to_tempfile(cq, mem, len, errh)) return -1; - if (con->response.send_chunked + if (r->resp_send_chunked && 0 != chunkqueue_append_mem_to_tempfile(cq, CONST_STR_LEN("\r\n"), errh)) return -1; @@ -163,18 +163,18 @@ static int http_chunk_append_to_tempfile(connection * const con, const char * co return 0; } -static int http_chunk_append_cq_to_tempfile(connection * const con, chunkqueue * const src, const size_t len) { - chunkqueue * const cq = con->write_queue; - log_error_st * const errh = con->conf.errh; +static int http_chunk_append_cq_to_tempfile(request_st * const r, chunkqueue * const src, const size_t len) { + chunkqueue * const cq = r->write_queue; + log_error_st * const errh = r->conf.errh; - if (con->response.send_chunked + if (r->resp_send_chunked && 0 != http_chunk_len_append_tempfile(cq, len, errh)) return -1; if (0 != chunkqueue_steal_with_tempfiles(cq, src, len, errh)) return -1; - if (con->response.send_chunked + if (r->resp_send_chunked && 0 != chunkqueue_append_mem_to_tempfile(cq, CONST_STR_LEN("\r\n"), errh)) return -1; @@ -183,7 +183,7 @@ static int http_chunk_append_cq_to_tempfile(connection * const con, chunkqueue * } __attribute_pure__ -static int http_chunk_uses_tempfile(const connection * const con, const chunkqueue * const cq, const size_t len) { +static int http_chunk_uses_tempfile(const request_st * const r, const chunkqueue * const cq, const size_t len) { /* current usage does not append_mem or append_buffer after appending * file, so not checking if users of this interface have appended large @@ -198,72 +198,72 @@ static int http_chunk_uses_tempfile(const connection * const con, const chunkque return ((c && c->type == FILE_CHUNK && c->file.is_temp) || cq->bytes_in - cq->bytes_out + len - > ((con->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) + > ((r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) ? 128*1024 : 64*1024)); } -int http_chunk_append_buffer(connection * const con, buffer * const mem) { +int http_chunk_append_buffer(request_st * const r, buffer * const mem) { size_t len = buffer_string_length(mem); if (0 == len) return 0; - chunkqueue * const cq = con->write_queue; + chunkqueue * const cq = r->write_queue; - if (http_chunk_uses_tempfile(con, cq, len)) - return http_chunk_append_to_tempfile(con, mem->ptr, len); + if (http_chunk_uses_tempfile(r, cq, len)) + return http_chunk_append_to_tempfile(r, mem->ptr, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) http_chunk_len_append(cq, len); /*(chunkqueue_append_buffer() might steal buffer contents)*/ chunkqueue_append_buffer(cq, mem); - if (con->response.send_chunked) + if (r->resp_send_chunked) chunkqueue_append_mem(cq, CONST_STR_LEN("\r\n")); return 0; } -int http_chunk_append_mem(connection * const con, const char * const mem, const size_t len) { +int http_chunk_append_mem(request_st * const r, const char * const mem, const size_t len) { if (0 == len) return 0; force_assert(NULL != mem); - chunkqueue * const cq = con->write_queue; + chunkqueue * const cq = r->write_queue; - if (http_chunk_uses_tempfile(con, cq, len)) - return http_chunk_append_to_tempfile(con, mem, len); + if (http_chunk_uses_tempfile(r, cq, len)) + return http_chunk_append_to_tempfile(r, mem, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) http_chunk_len_append(cq, len); chunkqueue_append_mem(cq, mem, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) chunkqueue_append_mem(cq, CONST_STR_LEN("\r\n")); return 0; } -int http_chunk_transfer_cqlen(connection * const con, chunkqueue * const src, const size_t len) { +int http_chunk_transfer_cqlen(request_st * const r, chunkqueue * const src, const size_t len) { if (0 == len) return 0; - chunkqueue * const cq = con->write_queue; + chunkqueue * const cq = r->write_queue; - if (http_chunk_uses_tempfile(con, cq, len)) - return http_chunk_append_cq_to_tempfile(con, src, len); + if (http_chunk_uses_tempfile(r, cq, len)) + return http_chunk_append_cq_to_tempfile(r, src, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) http_chunk_len_append(cq, len); chunkqueue_steal(cq, src, len); - if (con->response.send_chunked) + if (r->resp_send_chunked) chunkqueue_append_mem(cq, CONST_STR_LEN("\r\n")); return 0; } -void http_chunk_close(connection * const con) { - if (con->response.send_chunked) - chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("0\r\n\r\n")); +void http_chunk_close(request_st * const r) { + if (r->resp_send_chunked) + chunkqueue_append_mem(r->write_queue, CONST_STR_LEN("0\r\n\r\n")); } |