Now printing Multipart data to the log.

This commit is contained in:
ruri
2019-05-29 13:56:54 +02:00
parent 59a421876d
commit 9e4f7af84c
+21 -11
View File
@@ -180,15 +180,13 @@ namespace RuriLib
break; break;
case "STRINGCONTENT": case "STRINGCONTENT":
var sCont = LineParser.ParseLiteral(ref input, "STRING CONTENT"); var stringContentPair = ParsePair(LineParser.ParseLiteral(ref input, "STRING CONTENT"));
var sSplit = sCont.Split(new char[] { ':' }, 2); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.String, Name = stringContentPair.Key, Value = stringContentPair.Value });
MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.String, Name = sSplit[0].Trim(), Value = sSplit[1].Trim() });
break; break;
case "FILECONTENT": case "FILECONTENT":
var fCont = LineParser.ParseLiteral(ref input, "FILE CONTENT"); var fileContentPair = ParsePair(LineParser.ParseLiteral(ref input, "FILE CONTENT"));
var fSplit = fCont.Split(new char[] { ':' }, 2); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.File, Name = fileContentPair.Key, Value = fileContentPair.Value });
MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.File, Name = fSplit[0].Trim(), Value = fSplit[1].Trim() });
break; break;
case "COOKIE": case "COOKIE":
@@ -408,18 +406,30 @@ namespace RuriLib
content = new StringContent(pData); content = new StringContent(pData);
content.ContentType = cType; content.ContentType = cType;
data.Log(new LogEntry(string.Format("Post Data: {0}", pData), Colors.MediumTurquoise)); data.Log(new LogEntry($"Post Data: {pData}", Colors.MediumTurquoise));
} }
break; break;
case RequestType.Multipart: case RequestType.Multipart:
if (multipartBoundary != "") content = new Extreme.Net.MultipartContent(multipartBoundary); var bdry = multipartBoundary != "" ? multipartBoundary : GenerateMultipartBoundary();
else content = new Extreme.Net.MultipartContent(GenerateMultipartBoundary()); content = new Extreme.Net.MultipartContent(bdry);
var mContent = content as Extreme.Net.MultipartContent; var mContent = content as Extreme.Net.MultipartContent;
data.Log(new LogEntry("Multipart Data:", Colors.MediumTurquoise));
data.Log(new LogEntry($"{(content as Extreme.Net.MultipartContent)}", Colors.MediumTurquoise));
foreach (var c in MultipartContents) foreach (var c in MultipartContents)
{ {
if (c.Type == MultipartContentType.String) mContent.Add(new StringContent(ReplaceValues(c.Value, data)), ReplaceValues(c.Name, data)); var rValue = ReplaceValues(c.Value, data);
else if (c.Type == MultipartContentType.File) mContent.Add(new FileContent(ReplaceValues(c.Value, data)), ReplaceValues(c.Name, data)); var rName = ReplaceValues(c.Name, data);
if (c.Type == MultipartContentType.String)
{
mContent.Add(new StringContent(rValue), rName);
data.Log(new LogEntry($"Content-Disposition: form-data; name=\"{rName}\"{Environment.NewLine}{Environment.NewLine}{rValue}", Colors.MediumTurquoise));
}
else if (c.Type == MultipartContentType.File)
{
mContent.Add(new FileContent(rValue), rName);
data.Log(new LogEntry($"Content-Disposition: form-data; name=\"{rName}\"; filename=\"{rValue}\"{Environment.NewLine}{Environment.NewLine}[FILE CONTENT OMITTED]", Colors.MediumTurquoise));
}
} }
break; break;