used only when posting data */
| 359 | |
| 360 | /* used only when posting data */ |
| 361 | static int http_write(URLContext *h, uint8_t *buf, int size) |
| 362 | { |
| 363 | char temp[11]; /* 32-bit hex + CRLF + nul */ |
| 364 | int ret; |
| 365 | char crlf[] = "\r\n"; |
| 366 | HTTPContext *s = h->priv_data; |
| 367 | |
| 368 | if (s->chunksize == -1) { |
| 369 | /* headers are sent without any special encoding */ |
| 370 | return url_write(s->hd, buf, size); |
| 371 | } |
| 372 | |
| 373 | /* silently ignore zero-size data since chunk encoding that would |
| 374 | * signal EOF */ |
| 375 | if (size > 0) { |
| 376 | /* upload data using chunked encoding */ |
| 377 | snprintf(temp, sizeof(temp), "%x\r\n", size); |
| 378 | |
| 379 | if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 || |
| 380 | (ret = url_write(s->hd, buf, size)) < 0 || |
| 381 | (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) |
| 382 | return ret; |
| 383 | } |
| 384 | return size; |
| 385 | } |
| 386 | |
| 387 | static int http_close(URLContext *h) |
| 388 | { |
no test coverage detected