@@ -145,43 +145,27 @@ templates._response = function(response, is_last_response, do_raw)
145145 ]
146146} ;
147147
148- templates . _make_header_template_func = function ( is_request_headers )
148+ templates . _make_header_token_templ_func = function ( state )
149149{
150- // add data-spec attributes on certain firstline tokens, depending on if it's request_headers.
151- // todo: while this has firstline_tokens, it can't be reused.
152- // todo: not looking too good.
153- var firstline_tokens = 0 ;
154- var add_data_spec ;
155- if ( is_request_headers )
156- {
157- add_data_spec = {
158- 0 : true
159- } ;
160- }
161- else
162- {
163- add_data_spec = {
164- 1 : true
165- } ;
166- }
167-
168150 return function ( token )
169151 {
170152 var TYPE = 0 ;
171153 var STR = 1 ;
172154 var attrs = [ "class" , "header-token-type-" + cls . HTTPHeaderTokenizer . classnames [ token [ TYPE ] ] ] ;
155+
173156 if ( token [ TYPE ] === cls . HTTPHeaderTokenizer . types . NAME )
174157 {
175158 attrs . extend ( [ "data-spec" , "http#" + ( token [ STR ] ) . trim ( ) ] ) ;
176159 }
177160 else
178161 if ( token [ TYPE ] === cls . HTTPHeaderTokenizer . types . FIRST_LINE_PART )
179162 {
180- if ( firstline_tokens in add_data_spec )
163+ if ( state . data_spec_firstline_tokens . contains ( state . firstline_tokens ) )
181164 {
165+ // Add data-spec attributes on certain firstline tokens, tracked in state
182166 attrs . extend ( [ "data-spec" , "http#" + ( token [ STR ] ) . trim ( ) ] ) ;
183167 }
184- firstline_tokens ++ ;
168+ state . firstline_tokens ++ ;
185169 }
186170 return [ "span" , token [ STR ] ] . concat ( attrs ) ;
187171 }
@@ -192,6 +176,12 @@ templates._token_receiver = function(tokens, token_type, token)
192176 tokens . push ( [ token_type , token ] ) ;
193177} ;
194178
179+ templates . TokenStateholder = function ( data_spec_firstline_tokens )
180+ {
181+ this . data_spec_firstline_tokens = data_spec_firstline_tokens ;
182+ this . firstline_tokens = 0 ;
183+ }
184+
195185templates . _request_headers = function ( req , do_raw )
196186{
197187 if ( do_raw )
@@ -207,7 +197,8 @@ templates._request_headers = function(req, do_raw)
207197 }
208198 if ( req . header_tokens . length )
209199 {
210- var map_func = this . _make_header_template_func ( true ) ;
200+ var state_holder = new this . TokenStateholder ( [ 0 ] ) ;
201+ var map_func = this . _make_header_token_templ_func ( state_holder ) ;
211202 return [
212203 [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_REQUEST_TITLE ] ,
213204 this . _wrap_pre ( req . header_tokens . map ( map_func ) )
@@ -254,7 +245,8 @@ templates._response_headers = function(resp, do_raw)
254245 }
255246 if ( resp . header_tokens . length )
256247 {
257- var map_func = this . _make_header_template_func ( false ) ;
248+ var state_holder = new this . TokenStateholder ( [ 1 ] ) ;
249+ var map_func = this . _make_header_token_templ_func ( state_holder ) ;
258250 return [
259251 [ "h2" , ui_strings . S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE ] ,
260252 this . _wrap_pre ( resp . header_tokens . map ( map_func ) )
0 commit comments