-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Argument passing from Fake.Deploy.Web
Currently, no arguments are passed to the agent from Deploy.Web. This pull request passes env=EnvironmentName for the agent. This lets us parameterize deployments. Currently, the mechanism of passing multiple arguments alongside a package POST adds them as a ; separated string, which is then available in the deployment script verbatim. This pull request changes to the approach outlined by RFC 2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html) where multiple values are added to the header comma separated and quoted, with only quote characters percent encoded. To support existing clients, POSTs without comma separated quoted format are still passed verbatim.
- Loading branch information
Showing
7 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[<AutoOpen>] | ||
module Fake.HttpHeaderHelper | ||
open System | ||
open System.Text.RegularExpressions | ||
|
||
let toHeaderValue (values:string []) : string = | ||
values | ||
|> Array.map (fun x -> | ||
x.Replace("\"", "%22") | ||
|> sprintf "\"%s\"" | ||
) | ||
|> fun strs -> System.String.Join(",", strs | ||
) | ||
|
||
let private regex = Regex("(\"[^\"]*\")(?:,(\"[^\"]*\"))*", RegexOptions.Compiled) | ||
let fromHeaderValue (value:string) : string [] = | ||
let matches = regex.Matches(value) | ||
//back compat: existing agents not expecting quoted params will continue to function. | ||
if matches.Count = 0 then [|value|] | ||
else | ||
matches |> Seq.cast | ||
|> Seq.collect (fun (m:Match) -> m.Groups |> Seq.cast) | ||
|> Seq.skip 1 | ||
|> Seq.collect (fun (g:Group) -> | ||
g.Captures |> Seq.cast |> Seq.map (fun (c:Capture) -> c.Value) | ||
|> Seq.map (fun (x:string) -> | ||
x.Substring(1, x.Length - 2) | ||
|> fun y -> y.Replace("%22", "\"") | ||
) | ||
) | ||
|> Array.ofSeq | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Fake; | ||
using Machine.Specifications; | ||
|
||
namespace Test.Fake.Deploy.Http | ||
{ | ||
public class when_parsing_values_without_commas | ||
{ | ||
private static string[] _results; | ||
|
||
private Because of = () => _results = HttpHeaderHelper.fromHeaderValue("\"param%22one\",\"second\""); | ||
|
||
private It should_parse_params_with_quotes = () => | ||
_results[0].ShouldEqual("param\"one"); | ||
private It should_parse_params_without_quotes = () => | ||
_results[1].ShouldEqual("second"); | ||
} | ||
|
||
|
||
public class when_parsing_values_with_commas | ||
{ | ||
private static string[] _results; | ||
|
||
private Because of = () => _results = HttpHeaderHelper.fromHeaderValue("\"param,%22one\",\"second\",\"another, %22 parameter\""); | ||
|
||
private It should_parse_params_with_comma_and_quotes = () => | ||
_results[0].ShouldEqual("param,\"one"); | ||
private It should_parse_params_without_quotes = () => | ||
_results[1].ShouldEqual("second"); | ||
private It should_parse_third_param = () => | ||
_results[2].ShouldEqual("another, \" parameter"); | ||
} | ||
|
||
public class when_parsing_unquoted_params | ||
{ | ||
private static string[] _results; | ||
|
||
private Because of = () => _results = HttpHeaderHelper.fromHeaderValue("simple command"); | ||
|
||
private It should_parse_exact_value = () => | ||
_results[0].ShouldEqual("simple command"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters