File tree Expand file tree Collapse file tree 3 files changed +69
-38
lines changed
src/WebJobs.Script/azurefunctions
test/WebJobs.Script.Tests.Integration
TestScripts/Node/HttpTrigger-Scenarios Expand file tree Collapse file tree 3 files changed +69
-38
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ function createFunction(f) {
6565 }
6666 else {
6767 var values = { } ;
68- if ( context . res ) {
68+ if ( context . res && context . bindings . res === undefined ) {
6969 context . bindings . res = context . res ;
7070 }
7171 for ( var name in context . bindings ) {
Original file line number Diff line number Diff line change @@ -584,6 +584,27 @@ public async Task HttpTriggerPromise_TestBinding()
584584 Assert . Equal ( "returned from promise" , body ) ;
585585 }
586586
587+ [ Fact ]
588+ public async Task HttpTrigger_Scenarios_ResBinding ( )
589+ {
590+ HttpRequestMessage request = new HttpRequestMessage
591+ {
592+ RequestUri = new Uri ( string . Format ( "http://localhost/api/httptrigger-scenarios" ) ) ,
593+ Method = HttpMethod . Post ,
594+ } ;
595+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
596+ request . Headers . Add ( "scenario" , "resbinding" ) ;
597+ Dictionary < string , object > arguments = new Dictionary < string , object >
598+ {
599+ { "req" , request }
600+ } ;
601+ await Fixture . Host . CallAsync ( "HttpTrigger-Scenarios" , arguments ) ;
602+
603+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
604+ Assert . Equal ( HttpStatusCode . Accepted , response . StatusCode ) ;
605+ Assert . Equal ( "test" , await response . Content . ReadAsAsync < string > ( ) ) ;
606+ }
607+
587608 [ Fact ]
588609 public async Task HttpTrigger_Scenarios_ScalarReturn_InBody ( )
589610 {
Original file line number Diff line number Diff line change 33module . exports = function ( context , req ) {
44 var scenario = ( req . headers && req . headers . scenario ) || req . body . scenario ;
55
6- if ( scenario == "echo" ) {
7- context . res = req . body . value ;
8- }
9- else if ( scenario == "buffer" )
10- {
11- context . res . send ( Buffer . from ( '0001' , 'hex' ) ) ;
12- }
13- else if ( scenario == "rawresponse" ) {
14- context . res = {
15- status : 200 ,
16- body : req . body . value ,
17- headers : {
18- 'Content-Type' : req . body . contenttype
19- } ,
20- isRaw : true
21- }
22- }
23- else if ( scenario == "rawresponsenocontenttype" ) {
24- context . res = {
25- status : 200 ,
26- body : req . body . value ,
27- isRaw : true
28- }
29- }
30- else if ( scenario == "content" ) {
31- if ( req . headers . return ) {
32- context . res = req . body ;
33- context . done ( ) ;
34- } else {
35- var sendFunc = req . headers . raw ? 'raw' : 'send' ;
36- context . res . type ( req . headers . type ) [ sendFunc ] ( req . body ) ;
37- }
38- }
39- else {
40- context . res = {
41- status : 400
42- } ;
6+ switch ( scenario ) {
7+ case "echo" :
8+ context . res = req . body . value ;
9+ break ;
10+
11+ case "buffer" :
12+ context . res . send ( Buffer . from ( '0001' , 'hex' ) ) ;
13+ break ;
14+
15+ case "rawresponse" :
16+ context . res = {
17+ status : 200 ,
18+ body : req . body . value ,
19+ headers : {
20+ 'Content-Type' : req . body . contenttype
21+ } ,
22+ isRaw : true
23+ }
24+ break ;
25+
26+ case "rawresponsenocontenttype" :
27+ context . res = {
28+ status : 200 ,
29+ body : req . body . value ,
30+ isRaw : true
31+ }
32+ break ;
33+
34+ case "content" :
35+ if ( req . headers . return ) {
36+ context . res = req . body ;
37+ context . done ( ) ;
38+ } else {
39+ var sendFunc = req . headers . raw ? 'raw' : 'send' ;
40+ context . res . type ( req . headers . type ) [ sendFunc ] ( req . body ) ;
41+ }
42+ break ;
43+
44+ case "resbinding" :
45+ context . bindings . res = { status : 202 , body : "test" } ;
46+ break ;
47+
48+ default :
49+ context . res = {
50+ status : 400
51+ } ;
52+ break ;
4353 }
4454
4555 context . done ( ) ;
You can’t perform that action at this time.
0 commit comments