Exemplo n.º 1
0
 public void run()
 {
     if (handler == null)
     {
         return;
     }
     try
     {
         byte[] buffer = new byte[2560];
         while (true)
         {
             int actual = reader.read_bytes(buffer, 2560);
             Debug.Assert(actual <= 2560);
             if (actual <= 0)
             {
                 break;
             }
             fetch.handle_incremental_bytes(actual, buffer);
         }
     }
     catch (Exception e1)
     {
         exception = e1;
     }
 }
Exemplo n.º 2
0
        public int read_bytes(byte[] buffer, int byte_count)
        {
            int result = next.read_bytes(buffer, byte_count);

            if ((save_stream != null) && (result > 0))
            {
                save_stream.Write(buffer, 0, result);
            }
            return(result);
        }
Exemplo n.º 3
0
 public override int read(byte[] buffer, int byte_count)
 {
     return(reader.read_bytes(buffer, byte_count));
 }
    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();
    }