Skip to content

Commit

Permalink
Merge pull request #218 from jessie-murray/empty-header
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasff authored Feb 22, 2022
2 parents 73f2905 + 055363d commit 1b6e3a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void
http_response_set_header(struct http_response *r, const char *k, const char *v, header_copy copy) {

int i, pos = r->header_count;
int replaced = 0; /* whether we overwrote a previous value */
size_t key_sz = strlen(k);
size_t val_sz = strlen(v);

Expand All @@ -104,6 +105,7 @@ http_response_set_header(struct http_response *r, const char *k, const char *v,
/* free old value before replacing it. */
if(r->headers[i].copy & HEADER_COPY_KEY) free(r->headers[i].key);
if(r->headers[i].copy & HEADER_COPY_VALUE) free(r->headers[i].val);
replaced = 1;
break;
}
}
Expand All @@ -116,7 +118,9 @@ http_response_set_header(struct http_response *r, const char *k, const char *v,
sizeof(struct http_header)*(r->headers_array_size + 1));
r->headers_array_size++;
}
r->header_count++;
if(!replaced) {
r->header_count++;
}

/* copy key if needed */
if(copy & HEADER_COPY_KEY) {
Expand Down
14 changes: 14 additions & 0 deletions tests/curl-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ function test_large_put_upload() {
fi
}

# GitHub issue #217 (empty header ":" returned for OPTIONS)
function test_options_headers() {
echo -n 'Sending an OPTIONS request... '
empty_header_present=$(curl -v -X OPTIONS "http://127.0.0.1:7379/" 2>&1 | grep -cE '^< : ' || true) # || true to avoid false-positive exit code from grep

if [[ $empty_header_present != 0 ]]; then
echo "failed! Found an empty header entry"
exit 1
else
echo 'OK'
fi
}

test_large_put_upload
test_options_headers

0 comments on commit 1b6e3a9

Please sign in to comment.