1- unit uRESTDWServerMethodClass;
1+ unit uRESTDWServerMethodClass;
22
33{ $I ..\Includes\uRESTDW.inc}
44
@@ -149,43 +149,64 @@ implementation
149149 vTempValue,
150150 vTempParamsURI,
151151 vTempURL,
152+ vParamChar,
152153 ParamsURI : String;
153154 vParamMethods : TRESTDWParamsMethods;
154155 Procedure ParseParams ;
155156 Var
156157 lst : TStringList;
157158 pAux1,
158159 cAux1 : Integer;
160+ ctempURI,
161+ sAux,
159162 sAux1,
160163 sAux2 : string;
161164 JSONParam : TRESTDWJSONParam;
162165 Begin
163166 lst := TStringList.Create;
164167 Try
165- pAux1 := Pos(' ?' , ParamsURI);
168+ ctempURI := ParamsURI;
169+ pAux1 := Pos(' ?' , ctempURI);
166170 // params com /
167- sAux1 := Copy(ParamsURI, 1 , pAux1 - 1 );
171+ If vIsQuery Then
172+ Begin
173+ If Pos(' /' , ctempURI) > 0 Then
174+ Begin
175+ sAux2 := Copy(ctempURI, pAux1 + 1 , Pos(' /' , ctempURI) -2 );
176+ Delete(ctempURI, pAux1, Pos(' /' , ctempURI));
177+ End
178+ Else
179+ Begin
180+ sAux2 := Copy(ctempURI, pAux1 + 1 , Length(ctempURI));
181+ Delete(ctempURI, pAux1, Length(ctempURI));
182+ End ;
183+ End
184+ Else
185+ sAux2 := ' ' ;
168186 // params com &
169- sAux2 := Copy(ParamsURI, pAux1 + 1 , Length(ParamsURI));
187+ If ctempURI <> ' ' Then
188+ sAux1 := Copy(ctempURI, InitStrPos, Length(ctempURI))
189+ Else
190+ sAux1 := ' ' ;
191+ While (sAux2 <> ' ' ) Do
192+ Begin
193+ pAux1 := Pos(' &' , sAux2);
194+ If pAux1 = 0 then
195+ pAux1 := Length(sAux2) + 1 ;
196+ sAux := Copy(sAux2, InitStrPos, pAux1 - 1 );
197+ If Pos(' dwmark:' , sAux) = 0 then
198+ lst.Add(sAux);
199+ Delete(sAux2, InitStrPos, pAux1);
200+ End ;
170201 cAux1 := 0 ;
171202 While (sAux1 <> ' ' ) Do
172203 Begin
173204 pAux1 := Pos(' /' , sAux1);
174205 If pAux1 = 0 Then
175206 pAux1 := Length(sAux1) + 1 ;
176- lst.Add(IntToStr(cAux1) + ' =' + Copy(sAux1, 1 , pAux1 - 1 ));
177- cAux1 := cAux1 + 1 ;
178- Delete(sAux1, 1 , pAux1);
179- End ;
180- While (sAux2 <> ' ' ) Do
181- Begin
182- pAux1 := Pos(' &' , sAux2);
183- If pAux1 = 0 then
184- pAux1 := Length(sAux2) + 1 ;
185- sAux1 := Copy(sAux2, 1 , pAux1 - 1 );
186- If Pos(' dwmark:' , sAux1) = 0 then
187- lst.Add(sAux1);
188- Delete(sAux2, 1 , pAux1);
207+ lst.Add(IntToStr(cAux1) + ' =' + Copy(sAux1, InitStrPos, pAux1 - 1 ));
208+ Inc(cAux1);
209+ Delete(sAux1, InitStrPos, pAux1);
189210 End ;
190211 While lst.Count > 0 Do
191212 Begin
@@ -198,15 +219,14 @@ implementation
198219 JSONParam.SetValue(lst.ValueFromIndex[0 ]);
199220 Params.Add(JSONParam);
200221 End
201- Else If JSONParam.IsNull Then
222+ Else
202223 JSONParam.SetValue(lst.ValueFromIndex[0 ]);
203224 lst.Delete(0 );
204225 End ;
205226 Finally
206227 FreeAndNil(lst);
207228 End ;
208229 End ;
209-
210230 Procedure CopyParams (SourceParams : TRESTDWParamsMethods);
211231 Var
212232 isrc : Integer;
@@ -225,7 +245,6 @@ implementation
225245 End ;
226246 End ;
227247 End ;
228-
229248 Procedure ParseURL ;
230249 Begin
231250 vPosQuery := Pos(' ?' , URL);
@@ -250,7 +269,6 @@ implementation
250269 If URL = ' ' Then
251270 URL := ' /' ;
252271 End ;
253-
254272Begin
255273 Result := False;
256274 If Length(URL) = 0 Then
@@ -263,8 +281,16 @@ implementation
263281 Begin
264282 For A := 0 To TRESTDWServerEvents(Components[I]).Events.Count -1 Do
265283 Begin
284+ If Pos(' ?' , vTempValue) > 0 Then
285+ vParamChar := ' ?'
286+ Else
287+ vParamChar := ' /' ;
288+ If vParamChar = ' /' Then
289+ If Length(vTempValue) > 0 Then
290+ If vTempValue[Length(vTempValue) - FinalStrPos] <> vParamChar Then
291+ vTempValue := vTempValue + vParamChar;
266292 vTempRoute := TRESTDWServerEvents(Components[I]).Events[A].BaseURL +
267- TRESTDWServerEvents(Components[I]).Events[A].EventName;
293+ TRESTDWServerEvents(Components[I]).Events[A].EventName + vParamChar ;
268294 If ((vTempValue = ' /' ) or (vTempValue = ' ' )) Then
269295 Begin
270296 If TRESTDWServerEvents(Components[I]).DefaultEvent <> ' ' Then
@@ -274,55 +300,55 @@ implementation
274300 vTempValue := ' /' + vTempValue;
275301 End ;
276302 End ;
277- If SameText(vTempRoute, vTempValue) Then
303+ If SameText(vTempRoute, Copy( vTempValue, InitStrPos, Length(vTempRoute)) ) Then
278304 Begin
279305 Result := True;
280306 vTempURL := vTempRoute;
281- vTempParamsURI := ' ' ;
307+ Delete(vTempValue, InitStrPos, Length(vTempRoute));
308+ vTempParamsURI := vTempValue;
282309 vParamMethods := TRESTDWServerEvents(Components[I]).Events[A].Params;
283310 BuildCORS(TRESTDWServerEvents(Components[I]).Events[A].Routes, CORS_CustomHeaders);
284311 Break;
285- End
286- Else If SameText(vTempRoute + ' /' , Copy(vTempValue + ' /' , InitStrPos, Length(vTempRoute + ' /' ) - FinalStrPos)) Then
287- Begin
288- Result := True;
289- vTempURL := vTempRoute;
290- vTempParamsURI := Copy(vTempValue, Length(vTempRoute) + 2 , Length(vTempValue));
291- vParamMethods := TRESTDWServerEvents(Components[I]).Events[A].Params;
292- BuildCORS(TRESTDWServerEvents(Components[I]).Events[A].Routes, CORS_CustomHeaders);
293312 End ;
294313 End ;
295314 End
296315 Else If (Components[i] Is TRESTDWServerContext) Then
297316 Begin
298317 For A := 0 To TRESTDWServerContext(Components[I]).ContextList.Count - 1 Do
299318 Begin
319+ If Pos(' ?' , vTempValue) > 0 Then
320+ vParamChar := ' ?'
321+ Else
322+ vParamChar := ' /' ;
323+ If vParamChar = ' /' Then
324+ If Length(vTempValue) > 0 Then
325+ If vTempValue[Length(vTempValue) - FinalStrPos] <> vParamChar Then
326+ vTempValue := vTempValue + vParamChar;
300327 vTempRoute := TRESTDWServerContext(Components[I]).ContextList[A].BaseURL +
301- TRESTDWServerContext(Components[I]).ContextList[A].ContextName;
302- If SameText(vTempRoute, vTempValue) Then
328+ TRESTDWServerContext(Components[I]).ContextList[A].ContextName + vParamChar ;
329+ If SameText(vTempRoute, Copy( vTempValue, InitStrPos, Length(vTempRoute)) ) Then
303330 Begin
304331 Result := True;
305332 vTempURL := vTempRoute;
306- vTempParamsURI := ' ' ;
333+ Delete(vTempValue, InitStrPos, Length(vTempRoute));
334+ vTempParamsURI := vTempValue;
307335 vParamMethods := TRESTDWServerContext(Components[I]).ContextList[A].Params;
308336 BuildCORS(TRESTDWServerContext(Components[I]).ContextList[A].Routes, CORS_CustomHeaders);
309337 Break;
310- End
311- Else If SameText(vTempRoute+' /' , Copy(vTempValue+' /' , 1 , Length(vTempRoute+' /' ))) Then
312- Begin
313- Result := True;
314- vTempURL := vTempRoute;
315- vTempParamsURI := Copy(vTempValue, Length(vTempRoute) + 2 , Length(vTempValue));
316- vParamMethods := TRESTDWServerContext(Components[I]).ContextList[A].Params;
317- BuildCORS(TRESTDWServerContext(Components[I]).ContextList[A].Routes, CORS_CustomHeaders);
318338 End ;
319339 End ;
320340 End ;
321341 If Result Then
322342 Begin
323343 CopyParams(vParamMethods);
324344 URL := vTempURL;
325- ParamsURI := ' ?' + ParamsURI;
345+ If Not vIsQuery Then
346+ ParamsURI := vParamChar + ParamsURI
347+ Else
348+ ParamsURI := ' ?' + ParamsURI;
349+ If vTempParamsURI <> ' ' Then
350+ If vTempParamsURI[Length(vTempParamsURI) - FinalStrPos] = ' /' Then
351+ Delete(vTempParamsURI, Length(vTempParamsURI) - FinalStrPos, 1 );
326352 ParamsURI := vTempParamsURI + ParamsURI;
327353 ParseParams;
328354 Break;
0 commit comments