-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab921d1
commit 0e199a5
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Net; | ||
|
||
namespace SAPI.Utilities.Cookies | ||
{ | ||
public static class Cookies | ||
{ | ||
public static bool CheckForCookie(string cookieName, out Cookie? cookie, ref HttpListenerRequest request) | ||
{ | ||
cookie = request.Cookies[cookieName]; | ||
|
||
return cookie != null; | ||
} | ||
public static void GiveCookie(string cookieName, string cookieValue, ref HttpListenerResponse response) | ||
{ | ||
Cookie cookie = new(cookieName, cookieValue); | ||
response.AppendCookie(cookie); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Net; | ||
using SAPI.Endpoints; | ||
using SAPI.Utilities; | ||
using SAPI.Utilities.Cookies; | ||
|
||
namespace Testing.Endpoints | ||
{ | ||
public class Cookies : IEndpoint | ||
{ | ||
public string url { get; set; } = "cookies"; | ||
public Method method { get; set; } = Method.GET; | ||
public void Task(ref HttpListenerRequest request, ref HttpListenerResponse response, Dictionary<string, string> parameters) | ||
{ | ||
if (SAPI.Utilities.Cookies.Cookies.CheckForCookie("visit", out Cookie cookie, ref request)) | ||
{ | ||
SAPI.Utilities.Cookies.Cookies.GiveCookie("visit", "false", ref response); | ||
Utilities.Error(HttpStatus.OK, ref response); | ||
} | ||
else | ||
{ | ||
SAPI.Utilities.Cookies.Cookies.GiveCookie("visit", "true", ref response); | ||
Utilities.Error(HttpStatus.Forbidden, ref response); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters