Hello,
I'm testing libcurl with a small program (attached test.c) and with a
HTTP server written in Python (attached serv.py).
I'm noticing different behaviour when test.c is linked with
libcurl 7.19.5 from when it's linked with 7.18.2 (which is installed in
my Ubuntu - i also believe that in 7.19.2 the behaviour was ok).
More exactly, when using 7.19.5, I'm getting:
[...]
CURL-debug: Informational data
------------------------------
transfer closed with 4 bytes remaining to read
[...]
and the callback is never called.
I've also noticed that when I send a larger response from serv.py, it
works ok.
Can anybody help me here?
Thanks
import cgi
import time
from random import randint, randrange
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class TestRtpsServer(BaseHTTPRequestHandler):
def do_POST(self):
try:
l = int(cgi.parse_header(self.headers.getheader('content-length'))[0])
data = self.rfile.read(l)
http_code = 123
http_output = 'blax'
print "Returning http_code=[%d] http_data=[%s] http_data_len=%d" % (http_code, http_output, len(http_output))
self.send_response(http_code)
self.send_header("Content-type", "text/plain")
self.send_header("Content-Length", '%d' % len(http_output))
self.end_headers()
self.wfile.write(http_output)
return
except StandardError, e:
print "EXCEPTION: %s" % e
def main():
try:
serv = TestRtpsServer
print 'Running server on port 18000...'
server = HTTPServer(('', 18000), serv)
server.handle_request()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
if __name__ == '__main__':
main()
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <curl/curl.h>
size_t cb(void* buffer, size_t size, size_t nmemb, void* user_data)
{
printf("\nsize=%u nmemb=%u\n", size, nmemb);
return size * nmemb;
}
int dbgcb (CURL* curl_handle, curl_infotype infotype, char* chr, size_t size, void* unused)
{
size_t i, written;
char* c = chr;
(void)sizeof(unused);
if (!curl_handle || !chr)
{
return -1;
}
fprintf(stderr, "\n\n");
switch (infotype)
{
case CURLINFO_TEXT:
fprintf(stderr, "CURL-debug: Informational data\n");
fprintf(stderr, "------------------------------\n");
break;
case CURLINFO_HEADER_IN:
fprintf(stderr, "CURL-debug: Incoming header\n");
fprintf(stderr, "---------------------------\n");
break;
case CURLINFO_HEADER_OUT:
fprintf(stderr, "CURL-debug: Outgoing header\n");
fprintf(stderr, "---------------------------\n");
break;
case CURLINFO_DATA_IN:
fprintf(stderr, "CURL-debug: Incoming data\n");
fprintf(stderr, "-------------------------\n");
break;
case CURLINFO_DATA_OUT:
fprintf(stderr, "CURL-debug: Outgoing data\n");
fprintf(stderr, "-------------------------\n");
break;
default:
fprintf(stderr, "CURL-debug: Unknown\n");
fprintf(stderr, "-------------------\n");
break;
}
written = 0;
for (i = 0; i < size; i++)
{
written++;
if (isprint(*c))
{
fprintf(stderr,"%c", *c);
}
else if (*c == '\n')
{
fprintf(stderr, "\n");
written = 0;
}
else
{
fprintf(stderr, ".");
}
if (written == 70)
{
fprintf(stderr, "\n");
}
c++;
}
return 0;
}
int main()
{
CURL* handle = NULL;
char* data = "INFO\n";
int rc;
handle = curl_easy_init();
if (!handle)
{
return -1;
}
if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cb))
{
return -2;
}
if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_URL, "http://localhost:18000"))
{
return -3;
}
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, dbgcb);
/* if (CURLE_OK != curl_easy_setopt(data->curl_handle, CURLOPT_WRITEDATA, data))
{
rtps_log(LOG_ERR, "Error setting CURLOPT_WRITEDATA");
return RTPS_ERROR;
} */
/* Set the data for HTTP POST and its size */
if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_POSTFIELDS, data))
{
return -4;
}
if (CURLE_OK != curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(data)))
{
return -5;
}
if (CURLE_OK != (rc = curl_easy_perform(handle)))
{
return -6;
}
curl_easy_cleanup(handle);
return 0;
}