/// <summary> /// Sets custom headers from an array of lines. /// </summary> /// <param name="lines">The lines containing the colon-separated name and value of the headers</param> public void SetCustomHeaders(string[] lines) { CustomHeaders.Clear(); foreach (var line in lines) { if (line.Contains(':')) { var split = line.Split(new[] { ':' }, 2); CustomHeaders[split[0].Trim()] = split[1].Trim(); } } }
/// <inheritdoc /> public override BlockBase FromLS(string line) { // Trim the line var input = line.Trim(); // Parse the label if (input.StartsWith("#")) { Label = LineParser.ParseLabel(ref input); } Method = (HttpMethod)LineParser.ParseEnum(ref input, "METHOD", typeof(HttpMethod)); Url = LineParser.ParseLiteral(ref input, "URL"); while (LineParser.Lookahead(ref input) == TokenType.Boolean) { LineParser.SetBool(ref input, this); } CustomHeaders.Clear(); // Remove the default headers while (input != "" && !input.StartsWith("->")) { var parsed = LineParser.ParseToken(ref input, TokenType.Parameter, true).ToUpper(); switch (parsed) { case "MULTIPART": RequestType = RequestType.Multipart; break; case "BASICAUTH": RequestType = RequestType.BasicAuth; break; case "STANDARD": RequestType = RequestType.Standard; break; case "CONTENT": PostData = LineParser.ParseLiteral(ref input, "POST DATA"); break; case "STRINGCONTENT": var sCont = LineParser.ParseLiteral(ref input, "STRING CONTENT"); var sSplit = sCont.Split(new char[] { ':' }, 2); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.String, Name = sSplit[0].Trim(), Value = sSplit[1].Trim() }); break; case "FILECONTENT": var fCont = LineParser.ParseLiteral(ref input, "FILE CONTENT"); var fSplit = fCont.Split(new char[] { ':' }, 2); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.File, Name = fSplit[0].Trim(), Value = fSplit[1].Trim() }); break; case "COOKIE": var cookiePair = ParsePair(LineParser.ParseLiteral(ref input, "COOKIE VALUE")); CustomCookies[cookiePair.Key] = cookiePair.Value; break; case "HEADER": var headerPair = ParsePair(LineParser.ParseLiteral(ref input, "HEADER VALUE")); CustomHeaders[headerPair.Key] = headerPair.Value; break; case "CONTENTTYPE": ContentType = LineParser.ParseLiteral(ref input, "CONTENT TYPE"); break; case "USERNAME": AuthUser = LineParser.ParseLiteral(ref input, "USERNAME"); break; case "PASSWORD": AuthPass = LineParser.ParseLiteral(ref input, "PASSWORD"); break; case "BOUNDARY": MultipartBoundary = LineParser.ParseLiteral(ref input, "BOUNDARY"); break; default: break; } } if (input.StartsWith("->")) { LineParser.EnsureIdentifier(ref input, "->"); var outType = LineParser.ParseToken(ref input, TokenType.Parameter, true); if (outType.ToUpper() == "STRING") { ResponseType = ResponseType.String; } else if (outType.ToUpper() == "FILE") { ResponseType = ResponseType.File; DownloadPath = LineParser.ParseLiteral(ref input, "DOWNLOAD PATH"); } } return(this); }
/// <inheritdoc /> public override BlockBase FromLS(string line) { // Trim the line var input = line.Trim(); // Parse the label if (input.StartsWith("#")) { Label = LineParser.ParseLabel(ref input); } Method = (HttpMethod)LineParser.ParseEnum(ref input, "METHOD", typeof(HttpMethod)); Url = LineParser.ParseLiteral(ref input, "URL"); while (LineParser.Lookahead(ref input) == TokenType.Boolean) { LineParser.SetBool(ref input, this); } CustomHeaders.Clear(); // Remove the default headers while (input != string.Empty && !input.StartsWith("->")) { var parsed = LineParser.ParseToken(ref input, TokenType.Parameter, true).ToUpper(); switch (parsed) { case "MULTIPART": RequestType = RequestType.Multipart; break; case "BASICAUTH": RequestType = RequestType.BasicAuth; break; case "STANDARD": RequestType = RequestType.Standard; break; case "RAW": RequestType = RequestType.Raw; break; case "CONTENT": PostData = LineParser.ParseLiteral(ref input, "POST DATA"); break; case "RAWDATA": RawData = LineParser.ParseLiteral(ref input, "RAW DATA"); break; case "STRINGCONTENT": var stringContentPair = ParseString(LineParser.ParseLiteral(ref input, "STRING CONTENT"), ':', 2); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.String, Name = stringContentPair[0], Value = stringContentPair[1] }); break; case "FILECONTENT": var fileContentTriplet = ParseString(LineParser.ParseLiteral(ref input, "FILE CONTENT"), ':', 3); MultipartContents.Add(new MultipartContent() { Type = MultipartContentType.File, Name = fileContentTriplet[0], Value = fileContentTriplet[1], ContentType = fileContentTriplet[2] }); break; case "COOKIE": var cookiePair = ParseString(LineParser.ParseLiteral(ref input, "COOKIE VALUE"), ':', 2); CustomCookies[cookiePair[0]] = cookiePair[1]; break; case "HEADER": var headerPair = ParseString(LineParser.ParseLiteral(ref input, "HEADER VALUE"), ':', 2); CustomHeaders[headerPair[0]] = headerPair[1]; break; case "CONTENTTYPE": ContentType = LineParser.ParseLiteral(ref input, "CONTENT TYPE"); break; case "USERNAME": AuthUser = LineParser.ParseLiteral(ref input, "USERNAME"); break; case "PASSWORD": AuthPass = LineParser.ParseLiteral(ref input, "PASSWORD"); break; case "BOUNDARY": MultipartBoundary = LineParser.ParseLiteral(ref input, "BOUNDARY"); break; case "SECPROTO": SecurityProtocol = LineParser.ParseEnum(ref input, "Security Protocol", typeof(SecurityProtocol)); break; default: break; } } if (input.StartsWith("->")) { LineParser.EnsureIdentifier(ref input, "->"); var outType = LineParser.ParseToken(ref input, TokenType.Parameter, true); if (outType.ToUpper() == "STRING") { ResponseType = ResponseType.String; } else if (outType.ToUpper() == "FILE") { ResponseType = ResponseType.File; DownloadPath = LineParser.ParseLiteral(ref input, "DOWNLOAD PATH"); while (LineParser.Lookahead(ref input) == TokenType.Boolean) { LineParser.SetBool(ref input, this); } } else if (outType.ToUpper() == "BASE64") { ResponseType = ResponseType.Base64String; OutputVariable = LineParser.ParseLiteral(ref input, "OUTPUT VARIABLE"); } } return(this); }