@@ -37,7 +37,7 @@ public static String join(Object[] array, char delimiter) {
3737 return sb .deleteCharAt (sb .length () - 1 ).toString ();
3838 }
3939
40- private final TreeMap <String , String > head = new TreeMap <String ,String >(String .CASE_INSENSITIVE_ORDER );
40+ private final TreeMap <String , String > head = new TreeMap <String , String >(String .CASE_INSENSITIVE_ORDER );
4141
4242 public HttpHead () {
4343 }
@@ -68,7 +68,9 @@ public String get(String key) {
6868 }
6969
7070 public HttpHead setValues (String key , String [] values ) {
71- if (values == null ) return this ;
71+ if (values == null ) {
72+ return this ;
73+ }
7274 return set (key , join (values , ',' ));
7375 }
7476
@@ -97,22 +99,23 @@ public List<String> nameList() {
9799 public Map <String , String > headMap () {
98100 return head ;
99101 }
100-
101- String readLine (InputStream is ) throws IOException {
102+
103+ String readHeaderLine (InputStream is ) throws IOException {
102104 byte [] bb = new byte [1024 ];
103105 int i = 0 ;
104106 int b = is .read ();
105107 while (b != '\n' && b != -1 ) {
106108 bb [i ++] = (byte ) b ;
107109 b = is .read ();
108110 }
109- return (new String (bb , 0 , i )).replace ("\r " , "" );
111+ if (b == '\n' && bb [i - 1 ] == '\r' ) {
112+ return new String (bb , 0 , i - 1 ); // header line MUST ended CRLF
113+ }
114+ throw new ProtocolException ();
110115 }
111-
116+
112117 public HttpHead read (InputStream is ) throws IOException {
113- // BufferedReader br = new BufferedReader(
114- // new InputStreamReader(is));
115- String line = readLine (is );
118+ String line = readHeaderLine (is );
116119// if (line.startsWith("\u0016\u0003\u0003")) {
117120// throw new javax.net.ssl.SSLHandshakeException("Plain socket");
118121// }
@@ -124,7 +127,7 @@ public HttpHead read(InputStream is) throws IOException {
124127 set (START_LINE , line );
125128 String key = null ;
126129 while (true ) {
127- line = readLine (is );
130+ line = readHeaderLine (is );
128131 if (line == null || line .isEmpty ()) {
129132 break ;
130133 }
0 commit comments