@@ -22,6 +22,7 @@ limitations under the License.
2222using Newtonsoft . Json . Linq ;
2323using TinCan . Documents ;
2424using TinCan . LRSResponses ;
25+ using System . Linq ;
2526
2627namespace TinCan
2728{
@@ -30,7 +31,7 @@ public class RemoteLRS : ILRS
3031 public Uri endpoint { get ; set ; }
3132 public TCAPIVersion version { get ; set ; }
3233 public String auth { get ; set ; }
33- public Dictionary < String , String > extended { get ; set ; }
34+ public Dictionary < String , String > extended { get ; set ; } = new Dictionary < String , String > ( ) ;
3435
3536 public void SetAuth ( String username , String password )
3637 {
@@ -51,8 +52,8 @@ private class MyHTTPRequest
5152 {
5253 public String method { get ; set ; }
5354 public String resource { get ; set ; }
54- public Dictionary < String , String > queryParams { get ; set ; }
55- public Dictionary < String , String > headers { get ; set ; }
55+ public Dictionary < String , String > queryParams { get ; set ; } = new Dictionary < String , String > ( ) ;
56+ public Dictionary < String , String > headers { get ; set ; } = new Dictionary < String , String > ( ) ;
5657 public String contentType { get ; set ; }
5758 public byte [ ] content { get ; set ; }
5859 }
@@ -81,6 +82,20 @@ public MyHTTPResponse(HttpWebResponse webResp)
8182 }
8283 }
8384
85+ private string AppendParamsToExistingQueryString ( string currentQueryString , IEnumerable < KeyValuePair < string , string > > parameters )
86+ {
87+ foreach ( KeyValuePair < String , String > entry in parameters )
88+ {
89+ if ( currentQueryString != "" )
90+ {
91+ currentQueryString += "&" ;
92+ }
93+ currentQueryString += HttpUtility . UrlEncode ( entry . Key ) + "=" + HttpUtility . UrlEncode ( entry . Value ) ;
94+ }
95+
96+ return currentQueryString ;
97+ }
98+
8499 private MyHTTPResponse MakeSyncRequest ( MyHTTPRequest req )
85100 {
86101 String url ;
@@ -97,21 +112,13 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req)
97112 url += req . resource ;
98113 }
99114
100- if ( req . queryParams != null )
115+ String qs = "" ;
116+ qs = AppendParamsToExistingQueryString ( qs , req . queryParams ) ;
117+ qs = AppendParamsToExistingQueryString ( qs , extended . Where ( w => ! req . queryParams . ContainsKey ( w . Key ) ) ) ;
118+
119+ if ( qs != "" )
101120 {
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- }
121+ url += "?" + qs ;
115122 }
116123
117124 // TODO: handle special properties we recognize, such as content type, modified since, etc.
@@ -123,13 +130,11 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req)
123130 {
124131 webReq . Headers . Add ( "Authorization" , auth ) ;
125132 }
126- if ( req . headers != null )
133+ foreach ( KeyValuePair < String , String > entry in req . headers )
127134 {
128- foreach ( KeyValuePair < String , String > entry in req . headers )
129- {
130- webReq . Headers . Add ( entry . Key , entry . Value ) ;
131- }
135+ webReq . Headers . Add ( entry . Key , entry . Value ) ;
132136 }
137+
133138
134139 if ( req . contentType != null )
135140 {
0 commit comments