@@ -4,13 +4,11 @@ window.cls = window.cls || {};
44
55cls . HTTPHeaderTokenizer = function ( )
66{
7- var CR = "\r" ;
87 var LF = "\n" ;
98 var PUNCTUATOR = ":" ;
10- var WHITESPACE_CHARS =
11- {
12- '\u0009' : 1 , // Tab <TAB>
13- '\u0020' : 1 , // Space <SP>
9+ var WHITESPACE_CHARS = {
10+ "\u0009" : 1 , // Tab <TAB>
11+ "\u0020" : 1 , // Space <SP>
1412 } ;
1513
1614 this . _buffer = "" ;
@@ -24,46 +22,39 @@ cls.HTTPHeaderTokenizer = function()
2422 this . _buffer = input_buffer ;
2523 this . _emitToken = ontoken ;
2624 while ( this . _state_handler !== this . _state_handlers . EOF )
27- {
2825 this . _state_handler . apply ( this ) ;
29- }
3026
3127 this . _state_handlers . EOF . apply ( this ) ;
3228 } ;
3329
34- this . _state_handlers =
30+ this . _state_handlers =
3531 {
3632 FIRST_LINE_PART : function ( )
3733 {
3834 if ( this . _is_EOF ( ) )
39- {
4035 return false ;
41- }
36+
4237 var c = this . _buffer . charAt ( this . _current_pos ++ ) ;
4338 this . _token_type = cls . HTTPHeaderTokenizer . types . FIRST_LINE_PART ;
4439 if ( c in WHITESPACE_CHARS )
4540 {
4641 this . _emitToken ( this . _token_type , this . _token_buffer ) ;
4742 this . _token_buffer = "" ;
48- // For now, LF and whitespace add to the next token. Visually that makes no difference.
4943 }
5044 else
5145 if ( c === LF )
5246 {
5347 this . _emitToken ( this . _token_type , this . _token_buffer ) ;
5448 this . _token_buffer = "" ;
55- this . _emitToken ( cls . HTTPHeaderTokenizer . types . LINE_SEPARATOR , c ) ; // todo: don't emit your own token.
5649 this . _state_handler = this . _state_handlers . NAME ;
57- return false ;
5850 }
5951 this . _token_buffer += c ;
6052 } ,
6153 NAME : function ( )
6254 {
6355 if ( this . _is_EOF ( ) )
64- {
6556 return false ;
66- }
57+
6758 var c = this . _buffer . charAt ( this . _current_pos ++ ) ;
6859 this . _token_type = cls . HTTPHeaderTokenizer . types . NAME ;
6960 if ( c === PUNCTUATOR )
@@ -79,9 +70,8 @@ cls.HTTPHeaderTokenizer = function()
7970 VALUE : function ( )
8071 {
8172 if ( this . _is_EOF ( ) )
82- {
8373 return false ;
84- }
74+
8575 var c = this . _buffer . charAt ( this . _current_pos ++ ) ;
8676 this . _token_type = cls . HTTPHeaderTokenizer . types . VALUE ;
8777 // LF only means switching to header when the following char is not whitespace.
@@ -90,7 +80,6 @@ cls.HTTPHeaderTokenizer = function()
9080 this . _emitToken ( this . _token_type , this . _token_buffer ) ;
9181 this . _token_buffer = "" ;
9282 this . _state_handler = this . _state_handlers . NAME ;
93- // For now, LF and whitespace add to the next token. Visually that makes no difference.
9483 }
9584 this . _token_buffer += c ;
9685 } ,
@@ -108,13 +97,12 @@ cls.HTTPHeaderTokenizer = function()
10897 return true ;
10998 }
11099 return false ;
111- }
100+ } ;
112101}
113102
114103cls . HTTPHeaderTokenizer . types = {
115104 FIRST_LINE_PART : 1 ,
116105 NAME : 2 ,
117106 VALUE : 3 ,
118- PUNCTUATOR : 4 ,
119- LINE_SEPARATOR : 5
107+ PUNCTUATOR : 4
120108} ;
0 commit comments