diff --git a/src/lib/lwan-mod-fastcgi.c b/src/lib/lwan-mod-fastcgi.c index 79ca6736d..f409cc291 100644 --- a/src/lib/lwan-mod-fastcgi.c +++ b/src/lib/lwan-mod-fastcgi.c @@ -475,10 +475,7 @@ try_initiating_chunked_response(struct lwan_request *request) char *header_start[N_HEADER_START]; char *next_request; enum lwan_http_status status_code = HTTP_OK; - struct lwan_value buffer = { - .value = lwan_strbuf_get_buffer(response->buffer), - .len = lwan_strbuf_get_length(response->buffer), - }; + struct lwan_value buffer = lwan_strbuf_to_value(response->buffer); assert(!(request->flags & (RESPONSE_CHUNKED_ENCODING | RESPONSE_SENT_HEADERS))); diff --git a/src/lib/lwan-mod-serve-files.c b/src/lib/lwan-mod-serve-files.c index 8baafcb37..2e88829d5 100644 --- a/src/lib/lwan-mod-serve-files.c +++ b/src/lib/lwan-mod-serve-files.c @@ -663,10 +663,7 @@ static bool dirlist_init(struct file_cache_entry *ce, ce->mime_type = "text/html"; - struct lwan_value rendered = { - .value = lwan_strbuf_get_buffer(&dd->rendered), - .len = lwan_strbuf_get_length(&dd->rendered), - }; + struct lwan_value rendered = lwan_strbuf_to_value(&dd->rendered); deflate_value(&rendered, &dd->deflated); #if defined(LWAN_HAVE_BROTLI) brotli_value(&rendered, &dd->brotli, &dd->deflated); diff --git a/src/lib/lwan-strbuf.c b/src/lib/lwan-strbuf.c index 5d4f8a111..43d726a96 100644 --- a/src/lib/lwan-strbuf.c +++ b/src/lib/lwan-strbuf.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "lwan-private.h" @@ -438,3 +439,15 @@ struct lwan_strbuf *lwan_strbuf_new_from_file(const char *path) free(strbuf); return NULL; } + +struct lwan_value lwan_strbuf_to_value(const struct lwan_strbuf *s) +{ + return (struct lwan_value){.value = lwan_strbuf_get_buffer(s), + .len = lwan_strbuf_get_length(s)}; +} + +struct iovec lwan_strbuf_to_iovec(const struct lwan_strbuf *s) +{ + return (struct iovec){.iov_base = lwan_strbuf_get_buffer(s), + .iov_len = lwan_strbuf_get_length(s)}; +} diff --git a/src/lib/lwan-strbuf.h b/src/lib/lwan-strbuf.h index 7e691d138..991c32d05 100644 --- a/src/lib/lwan-strbuf.h +++ b/src/lib/lwan-strbuf.h @@ -104,9 +104,5 @@ static inline char *lwan_strbuf_get_buffer(const struct lwan_strbuf *s) bool lwan_strbuf_init_from_file(struct lwan_strbuf *s, const char *path); struct lwan_strbuf *lwan_strbuf_new_from_file(const char *path); -static inline struct iovec -lwan_strbuf_to_iovec(const struct lwan_strbuf *s) -{ - return (struct iovec){.iov_base = lwan_strbuf_get_buffer(s), - .iov_len = lwan_strbuf_get_length(s)}; -} +struct iovec lwan_strbuf_to_iovec(const struct lwan_strbuf *s); +struct lwan_value lwan_strbuf_to_value(const struct lwan_strbuf *s); diff --git a/src/lib/lwan.c b/src/lib/lwan.c index c63bac5a4..2cba18e44 100644 --- a/src/lib/lwan.c +++ b/src/lib/lwan.c @@ -192,8 +192,7 @@ static void build_response_headers(struct lwan *l, lwan_strbuf_append_strz(&strbuf, "\r\n\r\n"); - l->headers = (struct lwan_value){.value = lwan_strbuf_get_buffer(&strbuf), - .len = lwan_strbuf_get_length(&strbuf)}; + l->headers = lwan_strbuf_to_value(&strbuf); } static void parse_global_headers(struct config *c,