@@ -26,20 +26,20 @@ module Fastify {
26
26
/**
27
27
* A function used as a Fastify route handler.
28
28
*
29
- * By default, only handlers installed by an Fastify route setup are recognized,
29
+ * By default, only handlers installed by a Fastify route setup are recognized,
30
30
* but support for other kinds of route handlers can be added by implementing
31
31
* additional subclasses of this class.
32
32
*/
33
33
abstract class RouteHandler extends HTTP:: Servers:: StandardRouteHandler , DataFlow:: ValueNode {
34
34
/**
35
35
* Gets the parameter of the route handler that contains the request object.
36
36
*/
37
- abstract SimpleParameter getRequestParameter ( ) ;
37
+ abstract DataFlow :: ParameterNode getRequestParameter ( ) ;
38
38
39
39
/**
40
40
* Gets the parameter of the route handler that contains the reply object.
41
41
*/
42
- abstract SimpleParameter getReplyParameter ( ) ;
42
+ abstract DataFlow :: ParameterNode getReplyParameter ( ) ;
43
43
}
44
44
45
45
/**
@@ -48,9 +48,9 @@ module Fastify {
48
48
class StandardRouteHandler extends RouteHandler , DataFlow:: FunctionNode {
49
49
StandardRouteHandler ( ) { this = any ( RouteSetup setup ) .getARouteHandler ( ) }
50
50
51
- override SimpleParameter getRequestParameter ( ) { result = this .getParameter ( 0 ) . getParameter ( ) }
51
+ override DataFlow :: ParameterNode getRequestParameter ( ) { result = this .getParameter ( 0 ) }
52
52
53
- override SimpleParameter getReplyParameter ( ) { result = this .getParameter ( 1 ) . getParameter ( ) }
53
+ override DataFlow :: ParameterNode getReplyParameter ( ) { result = this .getParameter ( 1 ) }
54
54
}
55
55
56
56
/**
@@ -60,7 +60,7 @@ module Fastify {
60
60
private class ReplySource extends HTTP:: Servers:: ResponseSource {
61
61
RouteHandler rh ;
62
62
63
- ReplySource ( ) { this = DataFlow :: parameterNode ( rh .getReplyParameter ( ) ) }
63
+ ReplySource ( ) { this = rh .getReplyParameter ( ) }
64
64
65
65
/**
66
66
* Gets the route handler that provides this response.
@@ -75,7 +75,7 @@ module Fastify {
75
75
private class RequestSource extends HTTP:: Servers:: RequestSource {
76
76
RouteHandler rh ;
77
77
78
- RequestSource ( ) { this = DataFlow :: parameterNode ( rh .getRequestParameter ( ) ) }
78
+ RequestSource ( ) { this = rh .getRequestParameter ( ) }
79
79
80
80
/**
81
81
* Gets the route handler that handles this request.
@@ -132,7 +132,9 @@ module Fastify {
132
132
string kind ;
133
133
134
134
RequestInputAccess ( ) {
135
- exists ( string name | this .( DataFlow:: PropRead ) .accesses ( rh .getARequestExpr ( ) .flow ( ) , name ) |
135
+ exists ( DataFlow:: PropRead read , string name |
136
+ this = read and read = rh .getARequestSource ( ) .ref ( ) .getAPropertyRead ( name )
137
+ |
136
138
kind = "parameter" and
137
139
name = [ "params" , "query" ]
138
140
or
@@ -153,10 +155,7 @@ module Fastify {
153
155
RouteHandler rh ;
154
156
155
157
RequestHeaderAccess ( ) {
156
- exists ( DataFlow:: PropRead headers |
157
- headers .accesses ( rh .getARequestExpr ( ) .flow ( ) , "headers" ) and
158
- this = headers .getAPropertyRead ( )
159
- )
158
+ this = rh .getARequestSource ( ) .ref ( ) .getAPropertyRead ( "headers" ) .getAPropertyRead ( )
160
159
}
161
160
162
161
override string getAHeaderName ( ) {
@@ -175,16 +174,9 @@ module Fastify {
175
174
RouteHandler rh ;
176
175
177
176
ResponseSendArgument ( ) {
178
- exists ( MethodCallExpr mce |
179
- mce .calls ( rh .getAResponseExpr ( ) , "send" ) and
180
- this = mce .getArgument ( 0 )
181
- )
177
+ this = rh .getAResponseSource ( ) .ref ( ) .getAMethodCall ( "send" ) .getArgument ( 0 ) .asExpr ( )
182
178
or
183
- exists ( Function f |
184
- f = rh .( DataFlow:: FunctionNode ) .getFunction ( ) and
185
- f .isAsync ( ) and
186
- f .getAReturnedExpr ( ) = this
187
- )
179
+ this = rh .( DataFlow:: FunctionNode ) .getAReturn ( ) .asExpr ( )
188
180
}
189
181
190
182
override RouteHandler getRouteHandler ( ) { result = rh }
@@ -196,7 +188,9 @@ module Fastify {
196
188
private class RedirectInvocation extends HTTP:: RedirectInvocation , MethodCallExpr {
197
189
RouteHandler rh ;
198
190
199
- RedirectInvocation ( ) { this .calls ( rh .getAResponseExpr ( ) , "redirect" ) }
191
+ RedirectInvocation ( ) {
192
+ this = rh .getAResponseSource ( ) .ref ( ) .getAMethodCall ( "redirect" ) .asExpr ( )
193
+ }
200
194
201
195
override Expr getUrlArgument ( ) { result = this .getLastArgument ( ) }
202
196
@@ -206,12 +200,13 @@ module Fastify {
206
200
/**
207
201
* An invocation that sets a single header of the HTTP response.
208
202
*/
209
- private class SetOneHeader extends HTTP:: Servers:: StandardHeaderDefinition {
203
+ private class SetOneHeader extends HTTP:: Servers:: StandardHeaderDefinition ,
204
+ DataFlow:: MethodCallNode {
210
205
RouteHandler rh ;
211
206
212
207
SetOneHeader ( ) {
213
- astNode . calls ( rh . getAResponseExpr ( ) , "header" ) and
214
- astNode .getNumArgument ( ) = 2
208
+ this = rh . getAResponseSource ( ) . ref ( ) . getAMethodCall ( "header" ) and
209
+ this .getNumArgument ( ) = 2
215
210
}
216
211
217
212
override RouteHandler getRouteHandler ( ) { result = rh }
@@ -224,7 +219,7 @@ module Fastify {
224
219
RouteHandler rh ;
225
220
226
221
SetMultipleHeaders ( ) {
227
- this . calls ( rh .getAResponseExpr ( ) .flow ( ) , "headers" ) and
222
+ this = rh .getAResponseSource ( ) .ref ( ) . getAMethodCall ( "headers" ) and
228
223
this .getNumArgument ( ) = 1
229
224
}
230
225
0 commit comments