@@ -306,8 +306,8 @@ private static Dictionary<string, object> GetFunctionArguments(FunctionDescripto
306
306
307
307
if ( triggerParameter . Type != typeof ( HttpRequestMessage ) )
308
308
{
309
- HttpTriggerBindingMetadata httpFunctionMetadata = ( HttpTriggerBindingMetadata ) function . Metadata . InputBindings . FirstOrDefault ( p => string . Compare ( "HttpTrigger" , p . Type , StringComparison . OrdinalIgnoreCase ) == 0 ) ;
310
- if ( ! string . IsNullOrEmpty ( httpFunctionMetadata . WebHookType ) )
309
+ var httpTrigger = function . GetTriggerAttributeOrNull < HttpTriggerAttribute > ( ) ;
310
+ if ( httpTrigger != null && ! string . IsNullOrEmpty ( httpTrigger . WebHookType ) )
311
311
{
312
312
WebHookHandlerContext webHookContext ;
313
313
if ( request . Properties . TryGetValue ( ScriptConstants . AzureFunctionsWebHookContextKey , out webHookContext ) )
@@ -423,13 +423,7 @@ protected override void OnInitializeConfig(ScriptHostConfiguration config)
423
423
424
424
protected override void OnHostCreated ( )
425
425
{
426
- // whenever the host is created (or recreated) we build a cache map of
427
- // all http function routes
428
- InitializeHttpFunctions ( Instance . Functions ) ;
429
-
430
- // since the request manager is created based on configurable
431
- // settings, it has to be recreated when host config changes
432
- _httpRequestManager = new WebScriptHostRequestManager ( Instance . ScriptConfig . HttpConfiguration , PerformanceManager , _metricsLogger , _config . TraceWriter ) ;
426
+ InitializeHttp ( ) ;
433
427
434
428
base . OnHostCreated ( ) ;
435
429
}
@@ -442,22 +436,42 @@ protected override void OnHostStarted()
442
436
base . OnHostStarted ( ) ;
443
437
}
444
438
445
- internal void InitializeHttpFunctions ( IEnumerable < FunctionDescriptor > functions )
439
+ private void InitializeHttp ( )
440
+ {
441
+ // get the registered http configuration from the extension registry
442
+ var extensions = Instance . ScriptConfig . HostConfig . GetService < IExtensionRegistry > ( ) ;
443
+ var httpConfig = extensions . GetExtensions < IExtensionConfigProvider > ( ) . OfType < Microsoft . Azure . WebJobs . Script . Binding . Http . HttpConfiguration > ( ) . Single ( ) ;
444
+
445
+ // whenever the host is created (or recreated) we build a cache map of
446
+ // all http function routes
447
+ InitializeHttpFunctions ( Instance . Functions , httpConfig ) ;
448
+
449
+ // since the request manager is created based on configurable
450
+ // settings, it has to be recreated when host config changes
451
+ _httpRequestManager = new WebScriptHostRequestManager ( httpConfig , PerformanceManager , _metricsLogger , _config . TraceWriter ) ;
452
+ }
453
+
454
+ private void InitializeHttpFunctions ( IEnumerable < FunctionDescriptor > functions , Microsoft . Azure . WebJobs . Script . Binding . Http . HttpConfiguration httpConfig )
446
455
{
447
456
// we must initialize the route factory here AFTER full configuration
448
457
// has been resolved so we apply any route prefix customizations
449
- var httpRouteFactory = new HttpRouteFactory ( _config . HttpConfiguration . RoutePrefix ) ;
458
+ var httpRouteFactory = new HttpRouteFactory ( httpConfig . RoutePrefix ) ;
450
459
451
460
_httpFunctions = new Dictionary < IHttpRoute , FunctionDescriptor > ( ) ;
452
461
_httpRoutes = new HttpRouteCollection ( ) ;
453
462
454
463
foreach ( var function in functions )
455
464
{
456
- var httpTriggerBinding = function . Metadata . InputBindings . OfType < HttpTriggerBindingMetadata > ( ) . SingleOrDefault ( ) ;
457
- if ( httpTriggerBinding != null )
465
+ var httpTrigger = function . GetTriggerAttributeOrNull < HttpTriggerAttribute > ( ) ;
466
+ if ( httpTrigger != null )
458
467
{
459
468
IHttpRoute httpRoute = null ;
460
- if ( httpRouteFactory . TryAddRoute ( function . Metadata . Name , httpTriggerBinding . Route , httpTriggerBinding . Methods , _httpRoutes , out httpRoute ) )
469
+ IEnumerable < HttpMethod > httpMethods = null ;
470
+ if ( httpTrigger . Methods != null )
471
+ {
472
+ httpMethods = httpTrigger . Methods . Select ( p => new HttpMethod ( p ) ) . ToArray ( ) ;
473
+ }
474
+ if ( httpRouteFactory . TryAddRoute ( function . Metadata . Name , httpTrigger . Route , httpMethods , _httpRoutes , out httpRoute ) )
461
475
{
462
476
_httpFunctions . Add ( httpRoute , function ) ;
463
477
}
0 commit comments