private int findHeaderEnd ( final byte [ ] buf , int rlen ) { int splitbyte = 0 ; while ( splitbyte + 1 < rlen ) { // RFC2616 if ( buf [ splitbyte ] == ' ' && buf [ splitbyte + 1 ] == ' ' && splitbyte + 3 < rlen && buf [ splitbyte + 2 ] == ' ' && buf [ splitbyte + 3 ] == ' ' ) { return splitbyte + 4 ; } // tolerance if ( buf [ splitbyte ] == ' ' && buf [ splitbyte + 1 ] == ' ' ) { return splitbyte + 2 ; } splitbyte ++ ; } return 0 ; }
Find byte index separating header from body . It must be the last byte of the first two sequential new lines .