1
0
mirror of synced 2024-11-22 01:13:49 +00:00

Tapeti.Cmd: support for url-encoded messages on the command line

This commit is contained in:
Mark van Renswoude 2021-09-06 13:32:55 +02:00
parent 3009eec0d4
commit eaaae6d2a9

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Net;
using System.Text; using System.Text;
using CommandLine; using CommandLine;
using RabbitMQ.Client; using RabbitMQ.Client;
@ -18,9 +19,12 @@ namespace Tapeti.Cmd.Verbs
[Option('m', "message", Group = "Input", HelpText = "Single message to be sent, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")] [Option('m', "message", Group = "Input", HelpText = "Single message to be sent, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")]
public string InputMessage { get; set; } public string InputMessage { get; set; }
[Option('c', "pipe", Group = "Input", HelpText = "Messages are read from the standard input pipe, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")] [Option('c', "pipe", Group = "Input", HelpText = "Messages are read from the standard input pipe, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")]
public bool InputPipe { get; set; } public bool InputPipe { get; set; }
[Option("urlencoded", HelpText = "Indicates the message is URL encoded. Only applies to messages passed directly with --message as quotes are very quirky on the command-line, even more so in PowerShell.")]
public bool UrlEncoded { get; set; }
[Option('e', "exchange", HelpText = "If specified publishes to the originating exchange using the original routing key. By default these are ignored and the message is published directly to the originating queue.")] [Option('e', "exchange", HelpText = "If specified publishes to the originating exchange using the original routing key. By default these are ignored and the message is published directly to the originating queue.")]
public bool PublishToExchange { get; set; } public bool PublishToExchange { get; set; }
@ -133,8 +137,12 @@ namespace Tapeti.Cmd.Verbs
if (!string.IsNullOrEmpty(options.InputMessage)) if (!string.IsNullOrEmpty(options.InputMessage))
{ {
var inputMessage = options.UrlEncoded
? WebUtility.UrlDecode(options.InputMessage)
: options.InputMessage;
disposeStream = true; disposeStream = true;
return new MemoryStream(Encoding.UTF8.GetBytes(options.InputMessage)); return new MemoryStream(Encoding.UTF8.GetBytes(inputMessage));
} }
disposeStream = true; disposeStream = true;