-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathControllerTest.cs
47 lines (43 loc) · 1.66 KB
/
ControllerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// Copyright (c) 2020 Laurent Ellerbach and the project contributors
// See LICENSE file in the project root for full license information.
//
using System.Net;
using System.Web;
namespace nanoFramework.WebServer.Sample
{
public class ControllerTest
{
[Route("test"), Route("Test2"), Route("tEst42"), Route("TEST")]
[CaseSensitive]
[Method("GET")]
public void RoutePostTest(WebServerEventArgs e)
{
string route = $"The route asked is {e.Context.Request.RawUrl.TrimStart('/').Split('/')[0]}";
e.Context.Response.ContentType = "text/plain";
WebServer.OutPutStream(e.Context.Response, route);
}
[Route("test/any")]
public void RouteAnyTest(WebServerEventArgs e)
{
WebServer.OutputHttpCode(e.Context.Response, HttpStatusCode.OK);
}
[Route("urlencode")]
public void UrlEncode(WebServerEventArgs e)
{
var rawUrl = e.Context.Request.RawUrl;
var paramsUrl = WebServer.DecodeParam(rawUrl);
string ret = "Parameters | Encoded | Decoded";
foreach (var param in paramsUrl)
{
ret += $"{param.Name} | ";
ret += $"{param.Value} | ";
// Need to wait for latest version of System.Net
// See https://github.com/nanoframework/lib-nanoFramework.System.Net.Http/blob/develop/nanoFramework.System.Net.Http/Http/System.Net.HttpUtility.cs
ret += $"{HttpUtility.UrlDecode(param.Value)}";
ret += "\r\n";
}
WebServer.OutPutStream(e.Context.Response, ret);
}
}
}