protected boolean parse ( String data ) throws Exception { if ( data == null || data . isEmpty ( ) ) { return true ; } // ZAP: Replace all "\n" with "\r\n" to parse correctly String newData = data . replaceAll ( "(?<!\r)\n" , CRLF ) ; // ZAP: always use CRLF to comply with HTTP specification // even if the data it's not directly used. mLineDelimiter = CRLF ; String [ ] split = patternCRLF . split ( newData ) ; mStartLine = split [ 0 ] ; String token = null , name = null , value = null ; int pos = 0 ; StringBuilder sb = new StringBuilder ( 2048 ) ; for ( int i = 1 ; i < split . length ; i ++ ) { token = split [ i ] ; if ( token . equals ( "" ) ) { continue ; } if ( ( pos = token . indexOf ( ":" ) ) < 0 ) { mMalformedHeader = true ; return false ; } name = token . substring ( 0 , pos ) . trim ( ) ; value = token . substring ( pos + 1 ) . trim ( ) ; if ( name . equalsIgnoreCase ( CONTENT_LENGTH ) ) { try { mContentLength = Integer . parseInt ( value ) ; } catch ( NumberFormatException nfe ) { } } /* if (name.equalsIgnoreCase(PROXY_CONNECTION)) { sb.append(name + ": " + _CLOSE + mLineDelimiter); } else if (name.equalsIgnoreCase(CONNECTION)) { sb.append(name + ": " + _CLOSE + mLineDelimiter); } else { */ sb . append ( name + ": " + value + mLineDelimiter ) ; //} addInternalHeaderFields ( name , value ) ; } mMsgHeader = sb . toString ( ) ; return true ; }
Parse this Http header using the String given .