This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Function5.cs
84 lines (69 loc) · 2.74 KB
/
Function5.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Converters;
namespace FunctionApp
{
public class Function5
{
private readonly IHttpResponderService _responderService;
public Function5(IHttpResponderService responderService)
{
_responderService = responderService;
}
[FunctionName(nameof(Function5))]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
FunctionExecutionContext executionContext)
{
var logger = executionContext.Logger;
logger.LogInformation("message logged");
return _responderService.ProcessRequest(req);
}
}
public interface IHttpResponderService
{
HttpResponseData ProcessRequest(HttpRequestData httpRequest);
}
public class DefaultHttpResponderService : IHttpResponderService
{
public DefaultHttpResponderService()
{
}
public HttpResponseData ProcessRequest(HttpRequestData httpRequest)
{
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
headers.Add("Content", "Content - Type: text / html; charset = utf - 8");
response.Headers = headers;
var responseBuilder = new StringBuilder();
responseBuilder.AppendLine($"Method: {httpRequest.Method}");
responseBuilder.AppendLine($"Request URL: {httpRequest.Url}");
responseBuilder.AppendLine($"Original request: {httpRequest.ReadAsString()}");
responseBuilder.AppendLine($"Headers:");
foreach (var item in httpRequest.Headers)
{
responseBuilder.AppendLine($"\t{item.Key} = {item.Value}");
}
responseBuilder.AppendLine($"Identities:");
foreach (var item in httpRequest.Identities)
{
responseBuilder.AppendLine($"\tAuth type: {item.AuthenticationType}");
responseBuilder.AppendLine($"\tClaims:");
foreach (var claim in item.Claims)
{
responseBuilder.AppendLine($"\t\tType: {claim.Type}, Value: {claim.Value}");
}
}
response.Body = responseBuilder.ToString();
return response;
}
}
}