-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script had special logic to allow this for CSX; but VS tooling and direct SDK users didn't have the same logic. Add the httprequest binding logic in the binding.
- Loading branch information
Showing
7 changed files
with
169 additions
and
10 deletions.
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
Binary file not shown.
96 changes: 96 additions & 0 deletions
96
src/WebJobs.Extensions.Http/HttpDirectRequestBindingProvider.cs
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,96 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Description; | ||
using Microsoft.Azure.WebJobs.Host.Bindings; | ||
using Microsoft.Azure.WebJobs.Host.Protocols; | ||
using static Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider.HttpTriggerBinding; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Http | ||
{ | ||
// support allowing binding any non-attributed HttpRequestMessage parameter to the incoming http request. | ||
// Foo([HttpTrigger] Poco x, HttpRequestMessage y); | ||
internal class HttpDirectRequestBindingProvider : IBindingProvider | ||
{ | ||
public Task<IBinding> TryCreateAsync(BindingProviderContext context) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException("context"); | ||
} | ||
|
||
ParameterInfo parameter = context.Parameter; | ||
if (parameter.ParameterType == typeof(HttpRequestMessage)) | ||
{ | ||
// Not already claimed by another trigger? | ||
if (!HasBindingAttributes(parameter)) | ||
{ | ||
return Task.FromResult<IBinding>(new HttpRequestBinding()); | ||
} | ||
} | ||
return Task.FromResult<IBinding>(null); | ||
} | ||
|
||
private static bool HasBindingAttributes(ParameterInfo parameter) | ||
{ | ||
foreach (Attribute attr in parameter.GetCustomAttributes(false)) | ||
{ | ||
if (IsBindingAttribute(attr)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static bool IsBindingAttribute(Attribute attribute) | ||
{ | ||
return attribute.GetType().GetCustomAttribute<BindingAttribute>() != null; | ||
} | ||
|
||
public class HttpRequestBinding : IBinding | ||
{ | ||
public bool FromAttribute | ||
{ | ||
get | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public Task<IValueProvider> BindAsync(BindingContext context) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
var request = context.BindingData[HttpTriggerAttributeBindingProvider.RequestBindingName]; | ||
|
||
return BindAsync(request, context.ValueContext); | ||
} | ||
|
||
public Task<IValueProvider> BindAsync(object value, ValueBindingContext context) | ||
{ | ||
var request = value as HttpRequestMessage; | ||
if (request != null) | ||
{ | ||
var binding = new SimpleValueProvider(typeof(HttpRequestMessage), request, "request"); | ||
return Task.FromResult<IValueProvider>(binding); | ||
} | ||
throw new InvalidOperationException("value must be a HttpRequestMessage"); | ||
} | ||
|
||
public ParameterDescriptor ToParameterDescriptor() | ||
{ | ||
return new ParameterDescriptor | ||
{ | ||
Name = "request" | ||
}; | ||
} | ||
} | ||
} | ||
} |
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
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