diff --git a/apps/restconf/clixon_http_data.c b/apps/restconf/clixon_http_data.c index 2aef39b1..4a203e7f 100644 --- a/apps/restconf/clixon_http_data.c +++ b/apps/restconf/clixon_http_data.c @@ -288,7 +288,7 @@ api_http_data_file(clicon_handle h, char *suffix; char *media; int ret; - char *str = NULL; + char *buf = NULL; size_t sz; clicon_debug(1, "%s", __FUNCTION__); @@ -347,11 +347,11 @@ api_http_data_file(clicon_handle h, /* Unoptimized, no direct read but requires an extra copy, * the cligen buf API should have some mechanism for this case without the extra copy. */ - if ((str = malloc(fsize + 1)) == NULL){ + if ((buf = malloc(fsize)) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; } - if ((sz = fread(str, fsize, 1, f)) < 0){ + if ((sz = fread(buf, fsize, 1, f)) < 0){ clicon_err(OE_UNIX, errno, "fread"); goto done; } @@ -361,8 +361,7 @@ api_http_data_file(clicon_handle h, goto done; goto ok; } - str[fsize] = 0; - if (cbuf_append_str(cbdata, str) < 0){ + if (cbuf_append_buf(cbdata, buf, fsize) < 0){ clicon_err(OE_UNIX, errno, "cbuf_append_str"); goto done; } @@ -375,8 +374,8 @@ api_http_data_file(clicon_handle h, ok: retval = 0; done: - if (str) - free(str); + if (buf) + free(buf); if (f) fclose(f); if (cbfile) diff --git a/apps/restconf/restconf_api_native.c b/apps/restconf/restconf_api_native.c index 4bbd800b..4d26fa7c 100644 --- a/apps/restconf/restconf_api_native.c +++ b/apps/restconf/restconf_api_native.c @@ -145,7 +145,6 @@ restconf_reply_send(void *req0, sd->sd_code = code; if (cb != NULL){ if (cbuf_len(cb)){ - cprintf(cb, "\r\n"); sd->sd_body_len = cbuf_len(cb); if (head){ cbuf_free(cb); diff --git a/apps/restconf/restconf_http1.c b/apps/restconf/restconf_http1.c index ae01df35..6a73307f 100644 --- a/apps/restconf/restconf_http1.c +++ b/apps/restconf/restconf_http1.c @@ -329,7 +329,10 @@ restconf_http1_reply(restconf_conn *rc, cprintf(sd->sd_outp_buf, "\r\n"); /* Write a body */ if (sd->sd_body){ - cbuf_append_str(sd->sd_outp_buf, cbuf_get(sd->sd_body)); + if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){ + clicon_err(OE_RESTCONF, errno, "cbuf_append_buf"); + goto done; + } } retval = 0; done: diff --git a/test/clixon.png b/test/clixon.png new file mode 100644 index 00000000..a06ddb42 Binary files /dev/null and b/test/clixon.png differ diff --git a/test/test_http_data.sh b/test/test_http_data.sh index 7e766fda..699c3f1d 100755 --- a/test/test_http_data.sh +++ b/test/test_http_data.sh @@ -116,6 +116,9 @@ EOF # remove read access chmod 660 $dir/www/data/noread.html +# bitmap +cp ./clixon.png $dir/www/data/ + # Http test routine with arguments: # 1. proto:http/https function testrun() @@ -221,6 +224,15 @@ EOF new "WWW options" expectpart "$(curl $CURLOPTS -X OPTIONS $proto://localhost/data/index.html)" 0 "HTTP/$HVER 200" "allow: OPTIONS,HEAD,GET" + # Remove -i option for binary transfer + CURLOPTS2=$(echo $CURLOPTS | sed 's/i//') + new "WWW binary bitmap" + curl $CURLOPTS2 -X GET $proto://localhost/data/clixon.png -o $dir/foo.png + cmp $dir/foo.png $dir/www/data/clixon.png + if [ $? -ne 0 ]; then + err1 "$dir/foo.png $dir/www/data/example.css should be equal" "Not equal" + fi + # negative errors new "WWW get http not found" expectpart "$(curl $CURLOPTS -X GET -H 'Accept: text/html' $proto://localhost/data/notfound.html)" 0 "HTTP/$HVER 404" "Content-Type: text/html" "