@@ -131,71 +131,78 @@ export function buildRuleFromExchange(exchange: HttpExchange): HtkMockRule {
131131 } ;
132132}
133133
134- export const buildDefaultGroup = ( items : HtkMockItem [ ] ) : HtkMockRuleGroup => ( {
134+ export const buildDefaultGroupWrapper = ( items : HtkMockItem [ ] ) : HtkMockRuleGroup => ( {
135135 id : 'default-group' ,
136136 title : "Default rules" ,
137137 collapsed : true ,
138138 items : items
139- } )
139+ } ) ;
140+
141+ export const buildDefaultGroupRules = (
142+ rulesStore : RulesStore ,
143+ proxyStore : ProxyStore
144+ ) : HtkMockItem [ ] => [
145+ // Respond to amiusing.httptoolkit.tech with an emphatic YES
146+ {
147+ id : 'default-amiusing' ,
148+ type : 'http' ,
149+ activated : true ,
150+ matchers : [
151+ new HttpRule . MethodMatchers . GET ( ) ,
152+ new HttpRule . AmIUsingMatcher ( )
153+ ] ,
154+ completionChecker : new completionCheckers . Always ( ) ,
155+ handler : new HttpRule . StaticResponseHandler ( 200 , undefined , amIUsingHtml , {
156+ 'content-type' : 'text/html' ,
157+ 'cache-control' : 'no-store' ,
158+ 'httptoolkit-active' : 'true'
159+ } )
160+ } ,
161+
162+ // Share the server certificate on a convenient URL, assuming it supports that
163+ ...( versionSatisfies ( proxyStore . serverVersion , FROM_FILE_HANDLER_SERVER_RANGE )
164+ ? [ {
165+ id : 'default-certificate' ,
166+ type : 'http' as 'http' ,
167+ activated : true ,
168+ matchers : [
169+ new HttpRule . MethodMatchers . GET ( ) ,
170+ new matchers . SimplePathMatcher ( "amiusing.httptoolkit.tech/certificate" )
171+ ] ,
172+ completionChecker : new completionCheckers . Always ( ) ,
173+ handler : new HttpRule . FromFileResponseHandler ( 200 , undefined , proxyStore . certPath , {
174+ 'content-type' : 'application/x-x509-ca-cert'
175+ } )
176+ } ] : [ ]
177+ ) ,
178+
179+ // Pass through all other traffic to the real target
180+ {
181+ id : 'default-wildcard' ,
182+ type : 'http' ,
183+ activated : true ,
184+ matchers : [ new HttpRule . DefaultWildcardMatcher ( ) ] ,
185+ completionChecker : new completionCheckers . Always ( ) ,
186+ handler : new HttpRule . PassThroughHandler ( rulesStore )
187+ } ,
188+ {
189+ id : 'default-ws-wildcard' ,
190+ type : 'websocket' ,
191+ activated : true ,
192+ matchers : [ new DefaultWebSocketWildcardMatcher ( ) ] ,
193+ completionChecker : new completionCheckers . Always ( ) ,
194+ handler : new WebSocketPassThroughHandler ( rulesStore )
195+ }
196+ ] ;
140197
141- export const buildDefaultRules = ( rulesStore : RulesStore , proxyStore : ProxyStore ) => ( {
198+ export const buildDefaultRulesRoot = ( rulesStore : RulesStore , proxyStore : ProxyStore ) => ( {
142199 id : 'root' ,
143200 title : "HTTP Toolkit Rules" ,
144201 isRoot : true ,
145202 items : [
146- buildDefaultGroup ( [
147- // Respond to amiusing.httptoolkit.tech with an emphatic YES
148- {
149- id : 'default-amiusing' ,
150- type : 'http' ,
151- activated : true ,
152- matchers : [
153- new HttpRule . MethodMatchers . GET ( ) ,
154- new HttpRule . AmIUsingMatcher ( )
155- ] ,
156- completionChecker : new completionCheckers . Always ( ) ,
157- handler : new HttpRule . StaticResponseHandler ( 200 , undefined , amIUsingHtml , {
158- 'content-type' : 'text/html' ,
159- 'cache-control' : 'no-store' ,
160- 'httptoolkit-active' : 'true'
161- } )
162- } ,
163-
164- // Share the server certificate on a convenient URL, assuming it supports that
165- ...( versionSatisfies ( proxyStore . serverVersion , FROM_FILE_HANDLER_SERVER_RANGE )
166- ? [ {
167- id : 'default-certificate' ,
168- type : 'http' as 'http' ,
169- activated : true ,
170- matchers : [
171- new HttpRule . MethodMatchers . GET ( ) ,
172- new matchers . SimplePathMatcher ( "amiusing.httptoolkit.tech/certificate" )
173- ] ,
174- completionChecker : new completionCheckers . Always ( ) ,
175- handler : new HttpRule . FromFileResponseHandler ( 200 , undefined , proxyStore . certPath , {
176- 'content-type' : 'application/x-x509-ca-cert'
177- } )
178- } ] : [ ]
179- ) ,
180-
181- // Pass through all other traffic to the real target
182- {
183- id : 'default-wildcard' ,
184- type : 'http' ,
185- activated : true ,
186- matchers : [ new HttpRule . DefaultWildcardMatcher ( ) ] ,
187- completionChecker : new completionCheckers . Always ( ) ,
188- handler : new HttpRule . PassThroughHandler ( rulesStore )
189- } ,
190- {
191- id : 'default-ws-wildcard' ,
192- type : 'websocket' ,
193- activated : true ,
194- matchers : [ new DefaultWebSocketWildcardMatcher ( ) ] ,
195- completionChecker : new completionCheckers . Always ( ) ,
196- handler : new WebSocketPassThroughHandler ( rulesStore )
197- }
198- ] )
203+ buildDefaultGroupWrapper (
204+ buildDefaultGroupRules ( rulesStore , proxyStore )
205+ )
199206 ]
200207} as HtkMockRuleRoot ) ;
201208
0 commit comments