"\n"-separated "Key: Value" lines into a curl slist (nullptr => none).
| 103 | |
| 104 | // "\n"-separated "Key: Value" lines into a curl slist (nullptr => none). |
| 105 | struct curl_slist* headerSlist(const char* headers) |
| 106 | { |
| 107 | struct curl_slist* hl = nullptr; |
| 108 | if (headers && headers[0]) { |
| 109 | std::string all(headers); |
| 110 | size_t start = 0; |
| 111 | while (start < all.size()) { |
| 112 | const size_t nl = all.find('\n', start); |
| 113 | std::string line = all.substr(start, nl == std::string::npos ? std::string::npos : nl - start); |
| 114 | if (!line.empty()) { |
| 115 | hl = curl_slist_append(hl, line.c_str()); |
| 116 | } |
| 117 | if (nl == std::string::npos) { |
| 118 | break; |
| 119 | } |
| 120 | start = nl + 1; |
| 121 | } |
| 122 | } |
| 123 | return hl; |
| 124 | } |
| 125 | |
| 126 | // Everything the four bindings used to spell out one at a time. The only |
| 127 | // conditional options are the ones a transfer genuinely varies: verb, |