Skip to content

Commit a264219

Browse files
committed
Add back method and marked as obsolete
1 parent 8855239 commit a264219

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

nanoFramework.WebServer/WebServer.cs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ public static UrlParameter[] ExtractRouteParameters(string route, string rawUrl,
176176
// Remove query parameters from the URL for matching
177177
var urlParam = rawUrl.IndexOf(ParamStart);
178178
var urlPath = urlParam > 0 ? rawUrl.Substring(0, urlParam) : rawUrl;
179-
179+
180180
// Normalize the URL path and route for comparison
181181
var urlToCompare = caseSensitive ? urlPath : urlPath.ToLower();
182182
var routeToCompare = caseSensitive ? route : route.ToLower();
183-
183+
184184
// Ensure both paths start with '/' for consistent segment splitting
185185
if (!urlToCompare.StartsWith("/"))
186186
{
@@ -190,67 +190,67 @@ public static UrlParameter[] ExtractRouteParameters(string route, string rawUrl,
190190
{
191191
routeToCompare = "/" + routeToCompare;
192192
}
193-
193+
194194
// Split into segments
195195
var urlSegments = urlToCompare.Split('/');
196196
var routeSegments = routeToCompare.Split('/');
197-
197+
198198
// Number of segments must match
199199
if (urlSegments.Length != routeSegments.Length)
200200
{
201201
return null;
202202
}
203-
203+
204204
ArrayList parameters = new ArrayList();
205-
205+
206206
// Compare each segment and extract parameters
207207
for (int i = 0; i < routeSegments.Length; i++)
208208
{
209209
var routeSegment = routeSegments[i];
210210
var urlSegment = urlSegments[i];
211-
211+
212212
// Skip empty segments (from leading slash)
213213
if (string.IsNullOrEmpty(routeSegment) && string.IsNullOrEmpty(urlSegment))
214214
{
215215
continue;
216216
}
217-
217+
218218
// Check if this is a parameter segment (starts and ends with curly braces)
219-
if (routeSegment.Length > 2 &&
220-
routeSegment.StartsWith("{") &&
219+
if (routeSegment.Length > 2 &&
220+
routeSegment.StartsWith("{") &&
221221
routeSegment.EndsWith("}"))
222222
{
223223
// Parameter segment matches any non-empty segment that doesn't contain '/'
224224
if (string.IsNullOrEmpty(urlSegment) || urlSegment.IndexOf('/') >= 0)
225225
{
226226
return null;
227227
}
228-
228+
229229
// Extract parameter name (remove curly braces)
230230
var paramName = routeSegment.Substring(1, routeSegment.Length - 2);
231231
parameters.Add(new UrlParameter { Name = paramName, Value = urlSegments[i] }); // Use original case for value
232232
continue;
233233
}
234-
234+
235235
// Exact match required for non-parameter segments
236236
if (routeSegment != urlSegment)
237237
{
238238
return null;
239239
}
240240
}
241-
241+
242242
// Convert ArrayList to array
243243
if (parameters.Count == 0)
244244
{
245245
return null;
246246
}
247-
247+
248248
var result = new UrlParameter[parameters.Count];
249249
for (int i = 0; i < parameters.Count; i++)
250250
{
251251
result[i] = (UrlParameter)parameters[i];
252252
}
253-
253+
254254
return result;
255255
}
256256

@@ -531,6 +531,14 @@ public void Stop()
531531
Debug.WriteLine("Stopped server in thread ");
532532
}
533533

534+
/// <summary>
535+
/// Output a stream
536+
/// </summary>
537+
/// <param name="response">the socket stream</param>
538+
/// <param name="strResponse">the stream to output</param>
539+
[Obsolete("Use OutputAsStream instead. This method will be removed in a future version.")]
540+
public static void OutPutStream(HttpListenerResponse response, string strResponse) => OutputAsStream(response, strResponse);
541+
534542
/// <summary>
535543
/// Output a string content as a stream.
536544
/// </summary>
@@ -827,47 +835,47 @@ public static bool IsRouteMatch(CallbackRoutes route, string method, string rawU
827835
// Remove query parameters from the URL for matching
828836
var urlParam = rawUrl.IndexOf(ParamStart);
829837
var urlPath = urlParam > 0 ? rawUrl.Substring(0, urlParam) : rawUrl;
830-
838+
831839
// Normalize the URL path and route for comparison
832840
var urlToCompare = route.CaseSensitive ? urlPath : urlPath.ToLower();
833841
var routeToCompare = route.CaseSensitive ? route.Route : route.Route.ToLower();
834-
842+
835843
// Ensure both paths start with '/' for consistent segment splitting
836844
if (!urlToCompare.StartsWith("/"))
837845
{
838846
urlToCompare = "/" + urlToCompare;
839847
}
840-
848+
841849
if (!routeToCompare.StartsWith("/"))
842850
{
843851
routeToCompare = "/" + routeToCompare;
844852
}
845-
853+
846854
// Split into segments
847855
var urlSegments = urlToCompare.Split('/');
848856
var routeSegments = routeToCompare.Split('/');
849-
857+
850858
// Number of segments must match
851859
if (urlSegments.Length != routeSegments.Length)
852860
{
853861
return false;
854862
}
855-
863+
856864
// Compare each segment
857865
for (int i = 0; i < routeSegments.Length; i++)
858866
{
859867
var routeSegment = routeSegments[i];
860868
var urlSegment = urlSegments[i];
861-
869+
862870
// Skip empty segments (from leading slash)
863871
if (string.IsNullOrEmpty(routeSegment) && string.IsNullOrEmpty(urlSegment))
864872
{
865873
continue;
866874
}
867-
875+
868876
// Check if this is a parameter segment (starts and ends with curly braces)
869-
if (routeSegment.Length > 2 &&
870-
routeSegment.StartsWith("{") &&
877+
if (routeSegment.Length > 2 &&
878+
routeSegment.StartsWith("{") &&
871879
routeSegment.EndsWith("}"))
872880
{
873881
// Parameter segment matches any non-empty segment that doesn't contain '/'
@@ -878,14 +886,14 @@ public static bool IsRouteMatch(CallbackRoutes route, string method, string rawU
878886
// Parameter matches, continue to next segment
879887
continue;
880888
}
881-
889+
882890
// Exact match required for non-parameter segments
883891
if (routeSegment != urlSegment)
884892
{
885893
return false;
886894
}
887895
}
888-
896+
889897
return true;
890898
}
891899

@@ -898,12 +906,12 @@ protected virtual void InvokeRoute(CallbackRoutes route, HttpListenerContext con
898906
{
899907
// Extract route parameters if the route contains parameter placeholders
900908
var routeParameters = ExtractRouteParameters(route.Route, context.Request.RawUrl, route.CaseSensitive);
901-
909+
902910
// Create WebServerEventArgs with or without route parameters
903-
var eventArgs = routeParameters != null
911+
var eventArgs = routeParameters != null
904912
? new WebServerEventArgs(context, routeParameters)
905913
: new WebServerEventArgs(context);
906-
914+
907915
route.Callback.Invoke(null, new object[] { eventArgs });
908916
}
909917

0 commit comments

Comments
 (0)