curl-library
Re: proxy tunnel and custom headers
Date: Sun, 25 Jul 2010 00:14:59 +0200
On Thu, Jul 22, 2010 at 11:29 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Thu, 22 Jul 2010, Patricia Muscalu wrote:
>
> Without supplying Transfer-Encoding header, curl sets Content-Length: -1.
>>
>
> Giving more details, I send as well the following headers to the HTTP
>> server:
>> Content-Type: image/jpeg
>> Content-Disposition: attachment; filename="image.jpg"
>>
>
> Is that a bit like a multipart formpost? That last header looks unusual to
> me.
>
It is described by http://www.ietf.org/rfc/rfc2183.txt
>
> Can you please provide a full example that makes curl set Content-Length:
> to -1 in the outgoing request as that sounds like a possible bug or misuse
> of libcurl option(s).
>
>
> Temporarily, I send Content-length: 0 header with the CONNECT request and
>> wait for the 200 Connection Established response
>> from the proxy. After the proxy tunnel has been established, I set
>> Transfer-Encoding header plus other custom headers according to:
>>
>
> If this works, it is by pure luck. libcurl does not really support changing
> options after a handle has already been set in use.
>
>
> Is this a correct approach? Is there any other way of achieving this
>> behavior?
>>
>
> The file tests/libtest/lib510.c shows how we test POST using
> Transfer-Encoding: chunked, but as you can see it _does_ set the header
> manually! Is this similar to what you do, but you also use CONNECT through a
> proxy (that then gets the Transfer-Encoding: header) ?
>
Thank you for your advice. I have looked into the suggested example.
Depending on the digest option and the transfer type I've got the following
results:
1. CURLAUTH_DIGEST + transfer chunked just hangs my HTTP server.
2. CURLAUTH_ANY + transfer chunked combination results in:
* About to connect() to 192.168.0.1 port 8080 (#0)
* Trying 192.168.0.1... * connected
* Connected to 192.168.0.1 (192.168.0.1) port 8080 (#0)
> POST /cgi-bin/upload.cgi HTTP/1.1
Host: 192.168.0.1:8080
Accept: */*
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
data: one, len:3
data: two
, len:3
data: three, len:5
data: and a final longer crap: four, len:29
< HTTP/1.1 401 Authorization Required
< Date: Sat, 24 Jul 2010 21:58:58 GMT
< Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8g
< WWW-Authenticate: Digest realm="RealmXXX",
nonce="7gUvQimMBAA=06b8c52058f521fa4d9117f878aa4d4314790b04", algorithm=MD5,
qop="auth"
< Content-Length: 401
< Content-Type: text/html; charset=iso-8859-1
* necessary data rewind wasn't possible
* Closing connection #0
* Send failed since rewinding of the data stream failed
3. Disabling transfer chunked gives the Content-Length: 0 header.
Are the test results correct? Am I missing something here (just a
libcurl-newbe ;-)) ? Thanks for any response!
---- Code ----
static const char *post[]={D
"one",
"two",
"three",
"and a final longer crap: four",
NULL
};
struct WriteThis {
int counter;
};
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void
*userp)
{
struct WriteThis *pooh = (struct WriteThis *)userp;
const char *data;
if(size*nmemb < 1)
return 0;
data = post[pooh->counter];
if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
pooh->counter++; /* advance pointer */
printf ("data: %s, len:%d\n", ptr, len);
return len;
}
return 0; /* no more data left to deliver */
}
int main()
{
CURL *curl;
CURLcode res=CURLE_OK;
struct curl_slist *slist = NULL;
struct WriteThis pooh;
pooh.counter = 0;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "
http://192.168.0.1:8080/cgi-bin/upload.cgi");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
/* Convert the POST data to ASCII */
//curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#if 1
slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
#endif
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
//curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_USERPWD, "test:test");
res = curl_easy_perform(curl);
if(slist)
curl_slist_free_all(slist);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
>
> --
>
> / daniel.haxx.se
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-25