<< "HTTP Options:" << std::endl
<< " -a Do NOT include Accept: header." << std::endl
<< " -A User-Agent: header. Use \"\" to omit." << std::endl
- << " -H 'string' Extra headers to send. Use '\\n' for new lines." << std::endl
+ << " -H 'string' Extra headers to send. Supports '\\\\', '\\n', '\\r' and '\\t'." << std::endl
<< " -i IMS If-Modified-Since time (in Epoch seconds)." << std::endl
<< " -j hosthdr Host header content" << std::endl
<< " -k Keep the connection active. Default is to do only one request then close." << std::endl
exit(1);
}
+static void
+shellUnescape(char *buf)
+{
+ if (!buf)
+ return;
+
+ unsigned char *p, *d;
+
+ d = p = reinterpret_cast<unsigned char *>(buf);
+
+ while (auto ch = *p) {
+
+ if (ch == '\\') {
+ ++p;
+
+ switch (*p) {
+ case 'n':
+ ch = '\n';
+ break;
+ case 'r':
+ ch = '\r';
+ break;
+ case 't':
+ ch = '\t';
+ break;
+ case '\\':
+ ch = '\\';
+ break;
+ default:
+ ch = *p;
+ debugVerbose(1, "Warning: unsupported shell code '\\" << ch << "'");
+ break;
+ }
+
+ *d = ch;
+
+ if (!ch)
+ continue;
+
+ } else {
+ *d = *p;
+ }
+
+ ++p;
+ ++d;
+ }
+
+ *d = '\0';
+}
+
int
main(int argc, char *argv[])
{
case 'H':
if (strlen(optarg)) {
- char *t;
strncpy(extra_hdrs, optarg, sizeof(extra_hdrs));
- while ((t = strstr(extra_hdrs, "\\n")))
- *t = '\r', *(t + 1) = '\n';
+ shellUnescape(extra_hdrs);
}
break;