Http data server Fixed binary data retrieval
This commit is contained in:
parent
90474d1523
commit
7452813da7
7 changed files with 28 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
BIN
test/clixon.png
Normal file
BIN
test/clixon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -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" "<title>404 Not Found</title>"
|
||||
|
|
|
|||
|
|
@ -144,11 +144,12 @@ if [ $r -ne 0 ]; then
|
|||
err1 "retval 0" $r
|
||||
fi
|
||||
|
||||
# XXX ftest har \n
|
||||
# Only compare relevant data line
|
||||
echo -n "<data>">> $ftest
|
||||
cat $fdataxml >> $ftest
|
||||
echo "</data>
" >> $ftest
|
||||
# -i dont always work properly
|
||||
echo -n "</data>" >> $ftest
|
||||
# -i (ignore case) dont always work properly
|
||||
sed '/<data>/!d' $foutput > $foutput2
|
||||
mv $foutput2 $foutput
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,8 @@ fi
|
|||
# Only compare relevant data line
|
||||
echo -n "<data>">> $ftest
|
||||
cat $fdataxml >> $ftest
|
||||
echo "</data>
" >> $ftest
|
||||
#echo "</data>
" >> $ftest
|
||||
echo -n "</data>" >> $ftest
|
||||
sed '/<data>/!d' $foutput > $foutput2
|
||||
mv $foutput2 $foutput
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue