File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ function apiProxy(dataAdapter) {
24
24
'x-forwarded-for' : apiProxy . getXForwardedForHeader ( req . headers , req . ip )
25
25
} ;
26
26
27
+ api . headers = apiProxy . setXHTTPMethodOverride ( req . headers , api . headers ) ;
28
+
27
29
dataAdapter . request ( req , api , {
28
30
convertErrorCode : false
29
31
} , function ( err , response , body ) {
@@ -65,3 +67,10 @@ apiProxy.getXForwardedForHeader = function (headers, clientIp) {
65
67
66
68
return newHeaderValue ;
67
69
} ;
70
+
71
+ apiProxy . setXHTTPMethodOverride = function ( requestHeaders , apiHeaders ) {
72
+ if ( requestHeaders [ 'x-http-method-override' ] ) {
73
+ apiHeaders [ 'x-http-method-override' ] = requestHeaders [ 'x-http-method-override' ] ;
74
+ }
75
+ return apiHeaders ;
76
+ } ;
Original file line number Diff line number Diff line change @@ -85,6 +85,33 @@ describe('apiProxy', function() {
85
85
incomingHeaders [ 'x-forwarded-for' ] ) ;
86
86
} ) ;
87
87
88
+ it ( 'should add an x-http-method-override header to the request if there is one' , function ( ) {
89
+ var incomingHeaders = { 'x-http-method-override' : 'PUT' } ,
90
+ outgoingHeaders ;
91
+
92
+ requestFromClient . headers = incomingHeaders ;
93
+
94
+ proxy ( requestFromClient , responseToClient ) ;
95
+
96
+ requestToApi . should . have . been . calledOnce ;
97
+ outgoingHeaders = requestToApi . firstCall . args [ 1 ] . headers ;
98
+ outgoingHeaders [ 'x-http-method-override' ] . should . eq ( incomingHeaders [ 'x-http-method-override' ] ) ;
99
+ } ) ;
100
+
101
+ it ( 'should not add an x-http-method-override header to the request if there is not one' , function ( ) {
102
+ var incomingHeaders = { } ,
103
+ outgoingHeaders ;
104
+
105
+ requestFromClient . headers = incomingHeaders ;
106
+
107
+ proxy ( requestFromClient , responseToClient ) ;
108
+
109
+ requestToApi . should . have . been . calledOnce ;
110
+ outgoingHeaders = requestToApi . firstCall . args [ 1 ] . headers ;
111
+
112
+ expect ( outgoingHeaders [ 'x-http-method-override' ] ) . to . be . undefined ;
113
+ } ) ;
114
+
88
115
89
116
it ( 'should not pass through the host header' , function ( ) {
90
117
proxy ( requestFromClient , responseToClient ) ;
You can’t perform that action at this time.
0 commit comments