Changeset 58199 in vbox
- Timestamp:
- Oct 12, 2015 3:27:00 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/iprt/http.h (modified) (5 diffs)
-
src/VBox/Runtime/generic/http-curl.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/http.h
r57926 r58199 73 73 74 74 /** 75 * Perform a simple blocking HTTP request.75 * Perform a simple blocking HTTP GET request. 76 76 * 77 77 * This is a just a convenient wrapper around RTHttpGetBinary that returns a … … 82 82 * @param hHttp The HTTP client instance. 83 83 * @param pszUrl URL. 84 * @param ppszNotUtf8 Where to return the poi tner to the HTTP response.84 * @param ppszNotUtf8 Where to return the pointer to the HTTP response. 85 85 * The string is of course zero terminated. Use 86 86 * RTHttpFreeReponseText to free. … … 102 102 103 103 /** 104 * Perform a simple blocking HTTP HEAD request. 105 * 106 * This is a just a convenient wrapper around RTHttpGetBinary that returns a 107 * different type and sheds a parameter. 108 * 109 * @returns iprt status code. 110 * 111 * @param hHttp The HTTP client instance. 112 * @param pszUrl URL. 113 * @param ppszNotUtf8 Where to return the pointer to the HTTP response. 114 * The string is of course zero terminated. Use 115 * RTHttpFreeReponseText to free. 116 * 117 * @remarks BIG FAT WARNING! 118 * 119 * This function does not guarantee the that returned string is valid UTF-8 or 120 * any other kind of text encoding! 121 * 122 * The caller must determine and validate the string encoding _before_ 123 * passing it along to functions that expect UTF-8! 124 * 125 * Also, this function does not guarantee that the returned string 126 * doesn't have embedded zeros and provides the caller no way of 127 * finding out! If you are worried about the response from the HTTPD 128 * containing embedded zero's, use RTHttpGetHeaderBinary instead. 129 */ 130 RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8); 131 132 /** 104 133 * Frees memory returned by RTHttpGetText. 105 134 * … … 109 138 110 139 /** 111 * Perform a simple blocking HTTP request.140 * Perform a simple blocking HTTP GET request. 112 141 * 113 142 * @returns iprt status code. … … 120 149 */ 121 150 RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb); 151 152 /** 153 * Perform a simple blocking HTTP HEAD request. 154 * 155 * @returns iprt status code. 156 * 157 * @param hHttp The HTTP client instance. 158 * @param pszUrl The URL. 159 * @param ppvResponse Where to store the HTTP response data. Use 160 * RTHttpFreeResponse to free. 161 * @param pcb Size of the returned buffer. 162 */ 163 RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb); 122 164 123 165 /** -
trunk/src/VBox/Runtime/generic/http-curl.cpp
r57974 r58199 2210 2210 } 2211 2211 2212 /* 2213 * Use GET by default. 2214 */ 2215 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_NOBODY, 0L); 2216 if (CURL_FAILURE(rcCurl)) 2217 return VERR_HTTP_CURL_ERROR; 2218 2212 2219 return VINF_SUCCESS; 2213 2220 } … … 2281 2288 * @param hHttp The HTTP/HTTPS client instance. 2282 2289 * @param pszUrl The URL. 2290 * @param fNoBody Set to suppress the body. 2283 2291 * @param ppvResponse Where to return the pointer to the allocated 2284 2292 * response data (RTMemFree). There will always be … … 2290 2298 * threads, because that will probably blow up! 2291 2299 */ 2292 static int rtHttpGetToMem(RTHTTP hHttp, const char *pszUrl, uint8_t **ppvResponse, size_t *pcb)2300 static int rtHttpGetToMem(RTHTTP hHttp, const char *pszUrl, bool fNoBody, uint8_t **ppvResponse, size_t *pcb) 2293 2301 { 2294 2302 PRTHTTPINTERNAL pThis = hHttp; … … 2322 2330 if (!CURL_FAILURE(rcCurl)) 2323 2331 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, (void *)pThis); 2332 if ( fNoBody 2333 && !CURL_FAILURE(rcCurl)) 2334 rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_NOBODY, 1L); 2324 2335 if (!CURL_FAILURE(rcCurl)) 2325 2336 { … … 2355 2366 uint8_t *pv; 2356 2367 size_t cb; 2357 int rc = rtHttpGetToMem(hHttp, pszUrl, &pv, &cb);2368 int rc = rtHttpGetToMem(hHttp, pszUrl, false /*fNoBody*/, &pv, &cb); 2358 2369 if (RT_SUCCESS(rc)) 2359 2370 { … … 2369 2380 2370 2381 2382 RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8) 2383 { 2384 Log(("RTHttpGetText: hHttp=%p pszUrl=%s\n", hHttp, pszUrl)); 2385 uint8_t *pv; 2386 size_t cb; 2387 int rc = rtHttpGetToMem(hHttp, pszUrl, true /*fNoBody*/, &pv, &cb); 2388 if (RT_SUCCESS(rc)) 2389 { 2390 if (pv) /* paranoia */ 2391 *ppszNotUtf8 = (char *)pv; 2392 else 2393 *ppszNotUtf8 = (char *)RTMemDup("", 1); 2394 } 2395 else 2396 *ppszNotUtf8 = NULL; 2397 return rc; 2398 2399 } 2400 2401 2371 2402 RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8) 2372 2403 { … … 2378 2409 { 2379 2410 Log(("RTHttpGetBinary: hHttp=%p pszUrl=%s\n", hHttp, pszUrl)); 2380 return rtHttpGetToMem(hHttp, pszUrl, (uint8_t **)ppvResponse, pcb); 2411 return rtHttpGetToMem(hHttp, pszUrl, false /*fNoBody*/, (uint8_t **)ppvResponse, pcb); 2412 } 2413 2414 2415 RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb) 2416 { 2417 Log(("RTHttpGetBinary: hHttp=%p pszUrl=%s\n", hHttp, pszUrl)); 2418 return rtHttpGetToMem(hHttp, pszUrl, true /*fNoBody*/, (uint8_t **)ppvResponse, pcb); 2381 2419 } 2382 2420
Note:
See TracChangeset
for help on using the changeset viewer.

