| 766 | } |
| 767 | |
| 768 | static xnet_result DoraXrtHttpExecuteStreamOnce( |
| 769 | const char* method, |
| 770 | const char* url, |
| 771 | const char* const* headerNames, |
| 772 | const char* const* headerValues, |
| 773 | size_t headerCount, |
| 774 | const void* body, |
| 775 | size_t bodyLen, |
| 776 | unsigned int timeoutMs, |
| 777 | int verifyPeer, |
| 778 | DoraXrtHttpShouldCancel shouldCancel, |
| 779 | void* cancelUserData, |
| 780 | DoraXrtHttpStreamHandler onChunk, |
| 781 | void* streamUserData, |
| 782 | int* statusCode, |
| 783 | char* redirectLocation, |
| 784 | size_t redirectLocationCap) { |
| 785 | xhttprequest request; |
| 786 | xnetengine* engine; |
| 787 | xnetconnectconfig connectConfig; |
| 788 | xtlsconfig tlsConfig; |
| 789 | DoraXrtHttpStreamContext ctx; |
| 790 | xnet_result status = XRT_NET_ERROR; |
| 791 | double startTime = xrtTimer(); |
| 792 | |
| 793 | if (statusCode) { |
| 794 | *statusCode = 0; |
| 795 | } |
| 796 | if (redirectLocation && redirectLocationCap > 0u) { |
| 797 | redirectLocation[0] = '\0'; |
| 798 | } |
| 799 | if (!method || !url) { |
| 800 | return XRT_NET_ERROR; |
| 801 | } |
| 802 | |
| 803 | memset(&ctx, 0, sizeof(ctx)); |
| 804 | ctx.finalStatus = XRT_NET_AGAIN; |
| 805 | ctx.onChunk = onChunk; |
| 806 | ctx.streamUserData = streamUserData; |
| 807 | ctx.future = xrtNetFutureCreate(); |
| 808 | if (!ctx.future) { |
| 809 | return XRT_NET_ERROR; |
| 810 | } |
| 811 | |
| 812 | xrtHttpRequestInit(&request); |
| 813 | if (!xrtHttpRequestSetMethod(&request, method) || |
| 814 | !xrtHttpRequestSetURL(&request, url)) { |
| 815 | xrtHttpRequestUnit(&request); |
| 816 | xrtNetFutureDestroy(ctx.future); |
| 817 | return XRT_NET_ERROR; |
| 818 | } |
| 819 | for (size_t i = 0; i < headerCount; ++i) { |
| 820 | if (headerNames && headerValues && headerNames[i] && headerValues[i]) { |
| 821 | (void)xrtHttpRequestSetHeader(&request, headerNames[i], headerValues[i]); |
| 822 | } |
| 823 | } |
| 824 | if (!DoraXrtHttpHasHeader(headerNames, headerCount, "User-Agent")) { |
| 825 | (void)xrtHttpRequestSetHeader(&request, "User-Agent", DORA_XRT_HTTP_USER_AGENT); |
no test coverage detected