Skip to content

Commit b0c653d

Browse files
committed
No need to have next_request_empty!
1 parent a75db17 commit b0c653d

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/lib/lwan-request.c

+16-22
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
#define HEADER_TERMINATOR_LEN (sizeof("\r\n") - 1)
5151
#define MIN_REQUEST_SIZE (sizeof("GET / HTTP/1.1\r\n\r\n") - 1)
5252

53-
static const char *next_request_empty = "";
54-
5553
enum lwan_read_finalizer {
5654
FINALIZER_DONE,
5755
FINALIZER_TRY_AGAIN,
@@ -948,25 +946,20 @@ static enum lwan_http_status client_read(
948946
int n_packets = 0;
949947

950948
if (helper->next_request) {
951-
if (UNLIKELY(helper->next_request == next_request_empty)) {
949+
const size_t next_request_len =
950+
(size_t)(helper->next_request - buffer->value);
951+
size_t new_len;
952+
953+
if (__builtin_sub_overflow(buffer->len, next_request_len, &new_len)) {
952954
helper->next_request = NULL;
953-
} else {
954-
const size_t next_request_len =
955-
(size_t)(helper->next_request - buffer->value);
956-
size_t new_len;
957-
958-
if (__builtin_sub_overflow(buffer->len, next_request_len,
959-
&new_len)) {
960-
helper->next_request = NULL;
961-
} else if (new_len) {
962-
/* FIXME: This memmove() could be eventually removed if a better
963-
* stucture (maybe a ringbuffer, reading with readv(), and each
964-
* pointer is coro_strdup() if they wrap around?) were used for
965-
* the request buffer. */
966-
buffer->len = new_len;
967-
memmove(buffer->value, helper->next_request, new_len);
968-
goto try_to_finalize;
969-
}
955+
} else if (new_len) {
956+
/* FIXME: This memmove() could be eventually removed if a better
957+
* stucture (maybe a ringbuffer, reading with readv(), and each
958+
* pointer is coro_strdup() if they wrap around?) were used for
959+
* the request buffer. */
960+
buffer->len = new_len;
961+
memmove(buffer->value, helper->next_request, new_len);
962+
goto try_to_finalize;
970963
}
971964
}
972965

@@ -1297,7 +1290,7 @@ get_remaining_body_data_length(struct lwan_request *request,
12971290
if (UNLIKELY((size_t)parsed_size >= max_size))
12981291
return HTTP_TOO_LARGE;
12991292
if (UNLIKELY(!parsed_size)) {
1300-
helper->next_request = (char *)next_request_empty;
1293+
helper->next_request = NULL;
13011294
*total = *have = 0;
13021295
} else {
13031296
*total = (size_t)parsed_size;
@@ -1313,11 +1306,12 @@ get_remaining_body_data_length(struct lwan_request *request,
13131306

13141307
if (*have < *total)
13151308
return HTTP_PARTIAL_CONTENT;
1309+
1310+
helper->next_request += *total;
13161311
}
13171312

13181313
helper->body_data.value = helper->next_request;
13191314
helper->body_data.len = *total;
1320-
helper->next_request += *total;
13211315
return HTTP_OK;
13221316
}
13231317

0 commit comments

Comments
 (0)