private Header readHeader(DataInputStream ins) {
        Header out = new Header();
        try {
            byte[] oldInput = new byte[3];
            oldInput[0]=0;
            oldInput[1]=0;
            oldInput[2]=0;
            byte input = 0;
            input = ins.readByte();
            int bufferSize = 0;
            byte[] buffer = new byte[BUFFER_SIZE];
            StringBuffer line = new StringBuffer();
            while(!isBreakEnd(oldInput, input)) {
                // Save the read data
                buffer[bufferSize] = input;
                bufferSize = (bufferSize +1) % BUFFER_SIZE;
                if (bufferSize==0) {
                    out.addRawArray(buffer);
                }
                // Parse the content                
                if (isBreak(oldInput, input)) {
                	String lineStr = line.toString();
                    if (lineStr.contains(":")) {
                        // We are not in first line
                        String [] tokens = lineStr.split(":");
                        if (tokens[0].toLowerCase().trim().equals("content-length")) {
                            Long len = Long.parseLong(tokens[1].trim());
                            out.setContentLength(len);
                        } else if (tokens[0].toLowerCase().trim().equals("host")) {
                            out.setHost(tokens[1] + ":" +tokens[2]);
                        } else if (tokens[0].toLowerCase().equals("transfer-encoding")) {
                            out.setChunked(tokens[1].toLowerCase().trim().equals("chunked"));
                        }
                    } else {
                        // we are in the first line of HTTP protocol
                        String [] tokens = lineStr.split(" ");
                        out.setOperation(tokens[0].trim());
                        out.setUrl(tokens[1].trim());
                        out.setPostfix(tokens[2].trim());
                    }
                    line = new StringBuffer();
                } else {
                	byte[] aux = new byte[1];
                	aux[0] = input;
                    line.append(new String(aux, "UTF-8"));
                }
                oldInput[0] = oldInput[1];
                oldInput[1] = oldInput[2];
                oldInput[2] = input;
                input = ins.readByte();
            }
            buffer[bufferSize] = input;
            bufferSize = (bufferSize +1) % BUFFER_SIZE;
            if (bufferSize==0) {
                out.addRawArray(buffer);
            } else {
            	byte []last = new byte[bufferSize];
                System.arraycopy(buffer, 0, last, 0, bufferSize);
                out.addRawArray(last);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return out;
    }