166 {
167 const int prefixLength = 9;
168 int keyLength = 0;
169
170 for (const auto& [key, value] : queries) {
171 keyLength = std::max(keyLength, static_cast<int>(key.size()));
172 }
173 for (const auto& [key, value] : header) {
174 keyLength = std::max(keyLength, static_cast<int>(key.size()));
175 }
176 for (const auto& [key, value] : cookies) {
177 keyLength = std::max(keyLength, static_cast<int>(key.size()));
178 }
179
180 std::stringstream requestStream;
181
182 requestStream << std::setw(prefixLength) << "Request"
183 << ": " << std::setw(keyLength) << "Method"
184 << " : " << method << "\n";
185 requestStream << std::setw(prefixLength) << ""
186 << ": " << std::setw(keyLength) << "Url"
187 << " : " << url << "\n";
188 requestStream << std::setw(prefixLength) << ""
189 << ": " << std::setw(keyLength) << "Version"
190 << " : " << version << "\n";
191
192 std::string prefix;
193
194 if (!queries.empty()) {
195 prefix = "Queries";
196 for (const auto& [query, value] : queries) {
197 requestStream << std::setw(prefixLength) << prefix << ": " << std::setw(keyLength) << query << " : " << value << "\n";
198 prefix = "";
199 }
200 }
201
202 if (!header.empty()) {
203 prefix = "Header";
204 for (const auto& [field, value] : header) {
205 requestStream << std::setw(prefixLength) << prefix << ": " << std::setw(keyLength) << field << " : " << value << "\n";
206 prefix = "";
207 }
208 }
209
210 if (!cookies.empty()) {
211 prefix = "Cookies";
212 for (const auto& [cookie, value] : cookies) {
213 requestStream << std::setw(prefixLength) << prefix << ": " << std::setw(keyLength) << cookie << " : " << value << "\n";
214 prefix = "";
215 }
216 }
217
218 if (!body.empty()) {
219 prefix = "Body";
220 requestStream << std::setw(prefixLength) << prefix <<
utils::hexDump(body, prefixLength) <<
"\n";
221 }
222
223 std::string string = requestStream.str();
224 if (!string.empty()) {
225 string.pop_back();
226 }
227
228 return string;
229 }
std::string hexDump(const std::vector< char > &bytes, int prefixLength, bool prefixAtFirstLine)