I'm sending a http request with C++ and libcurl (Version 7.72) to an IP Camera where Digest authentication is enabled. I have registered a callback function to handle data that is received as a result of the request (by using CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA). I also set the option CURLOPT_HEADER because I need some information from the headers of the response.
Usually, I would expect to receive one response after sending out one request. But because of Digest authentication, I get the data of two responses from libcurl in the write callback:
48 54 54 50 2f 31 2e 31 20 34 30 31 20 55 6e 61 HTTP/1.1 401 Una
75 74 68 6f 72 69 7a 65 64 0d 0a uthorized..
44 61 74 65 3a 20 4d 6f 6e 2c 20 32 38 20 41 75 Date: Mon, 28 Au
67 20 32 30 32 33 20 31 31 3a 35 30 3a 35 31 20 g 2023 11:50:51
47 4d 54 0d 0a GMT..
53 65 72 76 65 72 3a 20 77 65 62 73 65 72 76 65 Server: webserve
72 0d 0a r..
58 2d 46 72 61 6d 65 2d 4f 70 74 69 6f 6e 73 3a X-Frame-Options:
20 53 41 4d 45 4f 52 49 47 49 4e 0d 0a SAMEORIGIN..
43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content-Length:
31 37 38 0d 0a 178..
43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 Content-Type: te
78 74 2f 68 74 6d 6c 0d 0a xt/html..
43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73 Connection: clos
65 0d 0a e..
57 57 57 2d 41 75 74 68 65 6e 74 69 63 61 74 65 WWW-Authenticate
3a 20 44 69 67 65 73 74 20 71 6f 70 3d 22 61 75 : Digest qop="au
74 68 22 2c 20 72 65 61 6c 6d 3d 22 49 50 20 43 th", realm="IP C
61 6d 65 72 61 28 50 31 31 34 39 29 22 2c 20 6e amera(P1149)", n
6f 6e 63 65 3d 22 35 61 35 34 34 35 33 30 34 65 once="5a5445304e
33 32 34 64 37 61 34 66 34 37 35 39 33 36 34 64 324d7a4f4759364d
33 32 34 61 36 64 35 39 36 61 36 34 36 61 34 65 324a6d596a646a4e
36 61 36 62 33 64 22 2c 20 73 74 61 6c 65 3d 22 6a6b3d", stale="
46 41 4c 53 45 22 0d 0a FALSE"..
0d 0a ..
48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK.
0a .
43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 69 6d Content-Type: im
61 67 65 2f 6a 70 65 67 3b 20 63 68 61 72 73 65 age/jpeg; charse
74 3d 22 55 54 46 2d 38 22 0d 0a t="UTF-8"..
43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73 Connection: clos
65 0d 0a e..
43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 37 Content-Length:7
32 39 37 37 0d 0a 2977..
0d 0a ..
ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 ......JFIF......
If I don't set the option CURLOPT_HEADER then libcurl gives me only the data of the body of the second response. But in this situation I am missing the status code and the headers of the response, which is not a good solution for me.
I would like to ask libcurl to give me in the write callback the status code, the headers and the content of the SECOND response only. Is there a way to do this?
Use
CURLOPT_HEADERFUNCTIONinstead ofCURLOPT_HEADER