-
Notifications
You must be signed in to change notification settings - Fork 193
Closed
Description
When xhr is reused without any headers, CURLOPT_HTTPHEADER needs to points to NULL.
Othrewise, tjs will be segfault.
This is test case:
// tests/test-xhr-headers.js
import assert from 'tjs:assert';
const url = 'https://postman-echo.com/get';
const xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send();
xhr.open('POST', url, false);
xhr.send(); // <== segfault
The following is explicitly set to NULL when there is no header.
I am not sure this is curl bug or not.
diff --git a/src/xhr.c b/src/xhr.c
index 8171c90..291b604 100644
--- a/src/xhr.c
+++ b/src/xhr.c
@@ -744,9 +744,7 @@ static JSValue tjs_xhr_send(JSContext *ctx, JSValue this_val, int argc, JSValue
curl_easy_setopt(x->curl_h, CURLOPT_POSTFIELDSIZE_LARGE, size);
curl_easy_setopt(x->curl_h, CURLOPT_COPYPOSTFIELDS, buf);
}
- if (x->slist) {
- curl_easy_setopt(x->curl_h, CURLOPT_HTTPHEADER, x->slist);
- }
+ curl_easy_setopt(x->curl_h, CURLOPT_HTTPHEADER, x->slist);
if (x->async) {
curl_multi_add_handle(x->curlm_h, x->curl_h);
} else {
xland
Metadata
Metadata
Assignees
Labels
No labels