Skip to content

Commit

Permalink
refs #272: auto-detect the mode in HTTP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Apr 15, 2021
1 parent 933bbd5 commit 86d4f57
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/extlib/kxnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,28 +359,35 @@ static size_t Net_headerCallback(void *ptr, size_t size, size_t nmemb, void *use
}

ks_append_n(sv, (char *)ptr, bufsz);
if (ks_string(ct)[0] == 0) {
const char *p = strstr(ks_string(sv), "Content-Type: ");
if (p) {
p += strlen("Content-Type: ");
const char *e = strchr(p, ';');
const char *p = strstr(ks_string(sv), "Content-Type: ");
if (p) {
p += strlen("Content-Type: ");
const char *e = strchr(p, ';');
if (!e) {
e = strchr(p, '\r');
if (!e) {
e = strchr(p, '\r');
if (!e) {
e = strchr(p, '\n');
}
e = strchr(p, '\n');
}
if (e) {
}
if (e) {
kstr_t *s = ks_new();
ks_append_n(s, (char *)p, e - p);
if (!ks_equals(s, ct)) {
ks_clear(ct);
ks_append_n(ct, (char *)p, e - p);
KX_NET_GET_BUFFER(ctt, obj, "isContentTypeText");
// If a user sets it already, there's no change here.
// '-' means a user did no mode change at the moment.
if (ks_string(ctt)[0] == '-') {
// '*a' means a user did no mode change at the moment.
if (ks_string(ctt)[1] == 'a') {
ks_clear(ctt);
if (strcmp(ks_string(ct), "application/json") == 0 || strncmp(ks_string(ct), "text/", 5) == 0) {
ks_string(ctt)[0] = '1';
ks_append(ctt, "1a");
} else {
ks_append(ctt, "0a");
}
}
}
ks_free(s);
}
}
return bufsz;
Expand Down Expand Up @@ -539,7 +546,7 @@ int Net_createCurlHandler(int args, kx_frm_t *frmv, kx_frm_t *lexv, kx_context_t
KEX_SET_PROP_INT(obj, "isRunning", 0);
KEX_SET_PROP_CSTR(obj, "header", "");
KEX_SET_PROP_CSTR(obj, "contentType", "");
KEX_SET_PROP_CSTR(obj, "isContentTypeText", "-");
KEX_SET_PROP_CSTR(obj, "isContentTypeText", "0a");
KEX_SET_PROP_CSTR(obj, "received", "");
KEX_SET_PROP_BIN(obj, "receivedbin", allocate_bin(ctx));
KEX_SET_PROP_CSTR(obj, "debugInfo", "");
Expand Down

0 comments on commit 86d4f57

Please sign in to comment.