cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: CURLOPT_HTTPAUTH question

From: Jonathan C. <well.bad_at_hotmail.com>
Date: Thu, 5 Mar 2015 18:30:42 -0300

> 1. If I DO NOT set the CURLOPT_HTTPAUTH option and then use the
> curl_easy_perform to send a URL, will CURL default to send BASIC or
> will CURL not send any authentication at all?
>
> 2. If no authentication is sent in question 1 and the server
> responds with a message dictating the need for authentication, for
> example BASIC, will CURL then respond with BASIC authentication? Or
> will it hold to the fact that authentication has not been set and close
> the connection?

Let's see:

127.0.0.1:3000 is a local server with basic auth.

* Rebuilt URL to: 127.0.0.1:3000/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
Host: 127.0.0.1:3000
Accept: */*

< HTTP/1.1 401 Unauthorized
< X-Powered-By: Express
< Content-Type: text/plain
< WWW-Authenticate: Basic realm="basic"
< Date: Thu, 05 Mar 2015 21:26:02 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact

there you go, connection closed.

> 3. If the CURLOPT_USERPWD is set with a username/password I
> understand how it is used when specifying CURLOPT_HTTPAUTH, but back to
> my first two questions, is it dependent on CURLOPT_HTTPAUTH? Or is
> there a case where it is provisioned without CURLOPT_HTTPAUTH and will
> still be used to help default to BASIC Authentication.

Same than above, but setting userpwd:

* Rebuilt URL to: 127.0.0.1:3000/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
* Server auth using Basic with user 'user'
> GET / HTTP/1.1
Authorization: Basic dXNlcjpwYXNz
Host: 127.0.0.1:3000
Accept: */*

< HTTP/1.1 200 OK
< X-Powered-By: Express
< content-type: text/html; charset=utf-8
< content-length: 4
< etag: "-1919691191"
< Date: Thu, 05 Mar 2015 21:29:19 GMT
< Connection: keep-alive
<
* Connection #0 to host 127.0.0.1 left intact

libcurl used the given user/pass and connected to the server.
                                               
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-05