Skip to content

Commit

Permalink
Add debug lines & check if headers contains application/json
Browse files Browse the repository at this point in the history
  • Loading branch information
ShroomAgent27 committed Mar 22, 2024
1 parent deceb9a commit 4e3297e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions WebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ private void buildWebApp(string[] args)
Email email = await GetEmailAndSetResponse(context.Request, context.Response);
if (email is null)
{
Console.WriteLine("email object is null.");
return;
}
if (email.zipcode == 0)
if (email.zipcode <= 0)
{
Console.WriteLine("Provided zipcode is 0 (or less).");
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
return;
}
Expand Down Expand Up @@ -87,8 +89,10 @@ private void buildWebApp(string[] args)
private async Task<Email> GetEmailAndSetResponse(HttpRequest request, HttpResponse response)
{
Email email;
if (request.ContentType != "application/json")
if (request.ContentType.Contains("application/json"))
{
Console.WriteLine("Invalid ContentType. ContentType is \"" + request.ContentType + "\"");
Console.WriteLine("No application/json in Header.");
response.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
Expand All @@ -99,11 +103,14 @@ private async Task<Email> GetEmailAndSetResponse(HttpRequest request, HttpRespon
}
catch (Exception e)
{
Console.WriteLine("Exception decoding Json.");
Console.WriteLine(e.ToString());
response.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
if (email is null || String.IsNullOrEmpty(email.email))
{
Console.WriteLine("Bad email.");
response.StatusCode = (int)HttpStatusCode.BadRequest;
return null;
}
Expand Down

0 comments on commit 4e3297e

Please sign in to comment.