You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
I would like to suggest adding the following recipe for reading HTTP headers, I created and tested this sample code for a customer who was asking for an example code on how to get the client IP address from the HTTP headers. Think this would be helpful to include with the "HTTP and webhooks" recipes for any customer who are looking for the same:
############################################
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Net.Http;
using System.Net;
using Microsoft.Extensions.Logging;
using System;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("ReadingRequestHeaders")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = null)]HttpRequestMessage req, ILogger log)
{
log.LogTrace("Reading the request headers in HTTP Triggers");
// Read headers
try
{
System.Collections.Generic.IEnumerable<string> data = req.Headers.GetValues("x-forwarded-for");
// Echo request data back in the response
return req.CreateResponse(HttpStatusCode.OK, data);
}catch (Exception ex){
log.LogTrace(ex.Message);
return req.CreateResponse(HttpStatusCode.OK, "x-forwarded-for header is not available when testing Functions locally, Try Publishing the function to Azure then invoke it from there!");
}
}
}
}
############################################
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 95af34b2-d4ad-112a-47fb-856759a7c561
Version Independent ID: 70c25e21-ff7b-3d87-d085-6e1683ca6948
Dears,
I would like to suggest adding the following recipe for reading HTTP headers, I created and tested this sample code for a customer who was asking for an example code on how to get the client IP address from the HTTP headers. Think this would be helpful to include with the "HTTP and webhooks" recipes for any customer who are looking for the same:
############################################
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Net.Http;
using System.Net;
using Microsoft.Extensions.Logging;
using System;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("ReadingRequestHeaders")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = null)]HttpRequestMessage req, ILogger log)
{
log.LogTrace("Reading the request headers in HTTP Triggers");
// Read headers
try
{
System.Collections.Generic.IEnumerable<string> data = req.Headers.GetValues("x-forwarded-for");
// Echo request data back in the response
return req.CreateResponse(HttpStatusCode.OK, data);
}catch (Exception ex){
log.LogTrace(ex.Message);
return req.CreateResponse(HttpStatusCode.OK, "x-forwarded-for header is not available when testing Functions locally, Try Publishing the function to Azure then invoke it from there!");
}
}
}
}
############################################
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: