@@ -306,8 +306,8 @@ private static Dictionary<string, object> GetFunctionArguments(FunctionDescripto
306306
307307 if ( triggerParameter . Type != typeof ( HttpRequestMessage ) )
308308 {
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 ) )
311311 {
312312 WebHookHandlerContext webHookContext ;
313313 if ( request . Properties . TryGetValue ( ScriptConstants . AzureFunctionsWebHookContextKey , out webHookContext ) )
@@ -423,13 +423,7 @@ protected override void OnInitializeConfig(ScriptHostConfiguration config)
423423
424424 protected override void OnHostCreated ( )
425425 {
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 ( ) ;
433427
434428 base . OnHostCreated ( ) ;
435429 }
@@ -442,22 +436,42 @@ protected override void OnHostStarted()
442436 base . OnHostStarted ( ) ;
443437 }
444438
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 )
446455 {
447456 // we must initialize the route factory here AFTER full configuration
448457 // 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 ) ;
450459
451460 _httpFunctions = new Dictionary < IHttpRoute , FunctionDescriptor > ( ) ;
452461 _httpRoutes = new HttpRouteCollection ( ) ;
453462
454463 foreach ( var function in functions )
455464 {
456- var httpTriggerBinding = function . Metadata . InputBindings . OfType < HttpTriggerBindingMetadata > ( ) . SingleOrDefault ( ) ;
457- if ( httpTriggerBinding != null )
465+ var httpTrigger = function . GetTriggerAttributeOrNull < HttpTriggerAttribute > ( ) ;
466+ if ( httpTrigger != null )
458467 {
459468 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 ) )
461475 {
462476 _httpFunctions . Add ( httpRoute , function ) ;
463477 }
0 commit comments