Skip to content

Commit b1e4b7d

Browse files
committed
Append extra params to URL
1 parent 3919791 commit b1e4b7d

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

TinCan/RemoteLRS.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ public MyHTTPResponse(HttpWebResponse webResp)
8181
}
8282
}
8383

84+
private string AppendParamsToExistingQueryString(string currentQueryString, Dictionary<string, string> parameters)
85+
{
86+
foreach (KeyValuePair<String, String> entry in parameters)
87+
{
88+
if (currentQueryString != "")
89+
{
90+
currentQueryString += "&";
91+
}
92+
currentQueryString += HttpUtility.UrlEncode(entry.Key) + "=" + HttpUtility.UrlEncode(entry.Value);
93+
}
94+
95+
return currentQueryString;
96+
}
97+
8498
private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req)
8599
{
86100
String url;
@@ -97,21 +111,13 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req)
97111
url += req.resource;
98112
}
99113

100-
if (req.queryParams != null)
114+
String qs = "";
115+
qs = AppendParamsToExistingQueryString(qs, req.queryParams);
116+
qs = AppendParamsToExistingQueryString(qs, extended);
117+
118+
if (qs != "")
101119
{
102-
String qs = "";
103-
foreach (KeyValuePair<String, String> entry in req.queryParams)
104-
{
105-
if (qs != "")
106-
{
107-
qs += "&";
108-
}
109-
qs += HttpUtility.UrlEncode(entry.Key) + "=" + HttpUtility.UrlEncode(entry.Value);
110-
}
111-
if (qs != "")
112-
{
113-
url += "?" + qs;
114-
}
120+
url += "?" + qs;
115121
}
116122

117123
// TODO: handle special properties we recognize, such as content type, modified since, etc.
@@ -123,13 +129,11 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req)
123129
{
124130
webReq.Headers.Add("Authorization", auth);
125131
}
126-
if (req.headers != null)
132+
foreach (KeyValuePair<String, String> entry in req.headers)
127133
{
128-
foreach (KeyValuePair<String, String> entry in req.headers)
129-
{
130-
webReq.Headers.Add(entry.Key, entry.Value);
131-
}
134+
webReq.Headers.Add(entry.Key, entry.Value);
132135
}
136+
133137

134138
if (req.contentType != null)
135139
{

TinCanTests/RemoteLRSResourceTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,23 @@ public void TestDeleteAgentProfile()
339339
LRSResponse lrsRes = lrs.DeleteAgentProfile(doc);
340340
Assert.IsTrue(lrsRes.success);
341341
}
342+
343+
[Test]
344+
public void TestExtendedParameters()
345+
{
346+
// RemoteLRS doesn't provide a helpful interface for testing
347+
// that we successfully altered the request URL, but this test
348+
// is helpful in manual testing and it at least ensures that
349+
// specifying values in extended doesn't cause errors.
350+
lrs.extended.Add("test", "param");
351+
var doc = new StateDocument();
352+
doc.activity = Support.activity;
353+
doc.agent = Support.agent;
354+
doc.id = "test";
355+
doc.content = System.Text.Encoding.UTF8.GetBytes("Test value");
356+
357+
LRSResponse lrsRes = lrs.SaveState(doc);
358+
Assert.IsTrue(lrsRes.success);
359+
}
342360
}
343361
}

0 commit comments

Comments
 (0)