public string readLine() { string result = next.readLine(); if (save_writer != null) { save_writer.Write("{0}\n", result); } return(result); }
public void handleParametersAndBody(HTTPHandler handler, HTTPRawReader reader) { while (true) { string this_line = reader.readLine(); if ((this_line == null) || (this_line.Length == 0)) { break; } handle_header_line(this_line, handler); } handler.handleHeaderDone(); byte[] buffer = new byte[256]; if (chunked) { while (true) { long chunk_byte_count = 0; while (true) { int num = reader.read_bytes(buffer, 1); if (num < 1) { throw new Exception("Unexpected end of chunk header."); } if (buffer[0] == '\r') { break; } if (buffer[0] == ' ') { continue; } long digit; if ((buffer[0] >= '0') && (buffer[0] <= '9')) { digit = buffer[0] - '0'; } else if ((buffer[0] >= 'a') && (buffer[0] <= 'f')) { digit = (buffer[0] - 'a') + 0xa; } else if ((buffer[0] >= 'A') && (buffer[0] <= 'F')) { digit = (buffer[0] - 'A') + 0xa; } else { throw new Exception("Bad digit in chunk header."); } if (chunk_byte_count >= (Int64.MaxValue - digit) / 16) { throw new Exception("Overflow in chunk header."); } chunk_byte_count = (chunk_byte_count * 16) + digit; } if (chunk_byte_count == 0) { break; } { int num = reader.read_bytes(buffer, 1); if (num < 1) { throw new Exception("Unexpected end of chunk header."); } if (buffer[0] != '\n') { throw new Exception("Bad end-of-line in chunk header."); } } while (chunk_byte_count > 0) { int num = reader.read_bytes(buffer, ((chunk_byte_count > 256) ? 256 : (int)chunk_byte_count)); if (num < 1) { break; } handler.handleContent(num, buffer); chunk_byte_count -= num; } { int num = reader.read_bytes(buffer, 1); if (num < 1) { throw new Exception("Unexpected end of chunk."); } if (buffer[0] != '\r') { throw new Exception("Bad end-of-line in chunk."); } } { int num = reader.read_bytes(buffer, 1); if (num < 1) { throw new Exception("Unexpected end of chunk."); } if (buffer[0] != '\n') { throw new Exception("Bad end-of-line in chunk."); } } } /* @@@ */ /* @@@ -- Read the trailer. */ /* @@@ */ } else if (have_content_length) { while (content_length > 0) { int num = reader.read_bytes(buffer, ((content_length > 256) ? 256 : (int)content_length)); if (num < 1) { break; } Debug.Assert(num <= content_length); handler.handleContent(num, buffer); content_length -= num; } } else { while (true) { int num = reader.read_bytes(buffer, 256); if (num < 1) { break; } handler.handleContent(num, buffer); } } handler.handleContentEnd(); }