@@ -12,8 +12,8 @@ private import Response::Private as RP
1212 * A callable node that takes a single argument and, if it has a method name,
1313 * is called "call".
1414 */
15- private class PotentialCallNode extends DataFlow:: CallableNode {
16- PotentialCallNode ( ) {
15+ private class PotentialRequestHandler extends DataFlow:: CallableNode {
16+ PotentialRequestHandler ( ) {
1717 this .getNumberOfParameters ( ) = 1 and
1818 (
1919 this .( DataFlow:: MethodNode ) .getMethodName ( ) = "call"
@@ -32,26 +32,14 @@ private class PotentialCallNode extends DataFlow::CallableNode {
3232 }
3333}
3434
35- /**
36- * A callable node that looks like it implements the rack specification.
37- */
38- private class CallNode extends PotentialCallNode {
39- private RP:: PotentialResponseNode resp ;
40-
41- CallNode ( ) { resp = trackRackResponse ( this ) }
42-
43- /** Gets a response returned from a request to this application. */
44- RP:: PotentialResponseNode getAResponse ( ) { result = resp }
45- }
46-
47- private DataFlow:: LocalSourceNode trackRackResponse ( TypeBackTracker t , PotentialCallNode call ) {
35+ private DataFlow:: LocalSourceNode trackRackResponse ( TypeBackTracker t , PotentialRequestHandler call ) {
4836 t .start ( ) and
4937 result = call .getAReturnNode ( ) .getALocalSource ( )
5038 or
5139 exists ( TypeBackTracker t2 | result = trackRackResponse ( t2 , call ) .backtrack ( t2 , t ) )
5240}
5341
54- private RP:: PotentialResponseNode trackRackResponse ( PotentialCallNode call ) {
42+ private RP:: PotentialResponseNode trackRackResponse ( PotentialRequestHandler call ) {
5543 result = trackRackResponse ( TypeBackTracker:: end ( ) , call )
5644}
5745
@@ -66,7 +54,7 @@ module App {
6654 * (traditionally called `env`) and returns a rack-compatible response.
6755 */
6856 deprecated class AppCandidate extends DataFlow:: ClassNode {
69- private CallNode call ;
57+ private RequestHandler call ;
7058 private RP:: PotentialResponseNode resp ;
7159
7260 AppCandidate ( ) {
@@ -84,64 +72,18 @@ module App {
8472 RP:: PotentialResponseNode getResponse ( ) { result = resp }
8573 }
8674
87- private newtype TApp =
88- TClassApp ( DataFlow:: ClassNode cn , CallNode call ) or
89- TAnonymousApp ( CallNode call )
90-
9175 /**
92- * A rack application. This is either some object that responds to `call`
93- * taking a single argument and returns a rack response, or a lambda or
94- * proc that takes a single `env` argument and returns a rack response.
76+ * A callable node that looks like it implements the rack specification.
9577 */
96- abstract class RackApplication extends TApp {
97- /** Gets a textual representation of this element. */
98- string toString ( ) { result = "Rack application" }
99-
100- /** Gets the `DataFlow::CallableNode` that will handle requests to this app. */
101- abstract CallNode getCall ( ) ;
102-
103- /** Gets a response returned from a request to this app. */
104- RP:: PotentialResponseNode getAResponse ( ) { result = this .getCall ( ) .getAResponse ( ) }
105-
106- /** Gets the `env` parameter passed to this app when it handles a request. */
107- DataFlow:: ParameterNode getEnv ( ) { result = this .getCall ( ) .getParameter ( 0 ) }
108- }
109-
110- /**
111- * A rack application using a `DataFlow::ClassNode`. The class has either
112- * an instance method or a singleton method named "call" which takes a
113- * single `env` argument and returns a rack response.
114- */
115- private class ClassRackApplication extends TApp , RackApplication {
116- private DataFlow:: ClassNode cn ;
117- private CallNode call ;
118-
119- ClassRackApplication ( ) {
120- this = TClassApp ( cn , call ) and
121- call = [ cn .getInstanceMethod ( "call" ) , cn .getSingletonMethod ( "call" ) ]
122- }
123-
124- override string toString ( ) { result = "Rack application: " + cn .toString ( ) }
125-
126- override CallNode getCall ( ) { result = call }
127- }
128-
129- /**
130- * A rack application that is either a lambda or a proc, which takes a
131- * single `env` argument and returns a rack response.
132- */
133- private class AnonymousRackApplication extends TApp , RackApplication {
134- private CallNode call ;
78+ class RequestHandler extends PotentialRequestHandler {
79+ private RP:: PotentialResponseNode resp ;
13580
136- AnonymousRackApplication ( ) {
137- this = TAnonymousApp ( call ) and
138- not exists ( DataFlow:: ClassNode cn |
139- call = [ cn .getInstanceMethod ( _) , cn .getSingletonMethod ( _) ]
140- )
141- }
81+ RequestHandler ( ) { resp = trackRackResponse ( this ) }
14282
143- override string toString ( ) { result = "Rack application: " + call .toString ( ) }
83+ /** Gets the `env` parameter passed to this request handler. */
84+ DataFlow:: ParameterNode getEnv ( ) { result = this .getParameter ( 0 ) }
14485
145- override CallNode getCall ( ) { result = call }
86+ /** Gets a response returned from this request handler. */
87+ RP:: PotentialResponseNode getAResponse ( ) { result = resp }
14688 }
14789}
0 commit comments