Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="index">The index of the request, by which the Client object identifies it.</param>
 /// <param name="requestHandler">The client callback, which handles the incoming HTTP requests.</param>
 /// <param name="maxHeaderSize">The maximum allowed HTTP header size.</param>
 public Request(int index, Client.RequestHandlerDelegate requestHandler, int maxHeaderSize)
 {
     this.index          = index;
     this.inputRecord    = new Record();
     this.outputRecord   = new Record();
     this.requestHandler = requestHandler;
     this.maxHeaderSize  = maxHeaderSize;
     this.inputBuffer    = new FifoStream(maxHeaderSize);
     this.outputBuffer   = new FifoStream(maxHeaderSize);
 }
Esempio n. 2
0
        /// <summary>
        /// Converts the record buffer into an STDOUT record, and fills it with data.
        /// </summary>
        /// <param name="requestID">FastCGI request ID</param>
        /// <param name="fifo">Data source. Pass null to create an empty closing record.</param>
        /// <returns>Number of bytes transferred from the FIFO stream.</returns>
        public int STDOUT(UInt16 requestID, FifoStream fifo)
        {
            /*
             *  Set content
             */
            UInt16 length;

            if (fifo == null)
            {
                length = 0;
            }
            else
            {
                length = (UInt16)fifo.Read(Record.MAX_CONTENT_SIZE, this.buffer, 8);
            }

            /*
             *  Set header
             */
            this.buffer[0] = (byte)1;               // Version
            this.buffer[1] = (byte)TYPE_STDOUT;     // Type

            if (isLittleEndian)
            {
                this.buffer[2] = (byte)(requestID >> 8);      // Request ID 1
                this.buffer[3] = (byte)(requestID & 0x00FF);  // Request ID 0

                this.buffer[4] = (byte)(length >> 8);         // Content Length 1
                this.buffer[5] = (byte)(length & 0x00FF);     // Content Length 0
            }
            else
            {
                this.buffer[2] = (byte)(requestID << 8);      // Request ID 1
                this.buffer[3] = (byte)(requestID & 0xFF00);  // Request ID 0

                this.buffer[4] = (byte)(length << 8);         // Content Length 1
                this.buffer[5] = (byte)(length & 0xFF00);     // Content Length 0
            }

            this.buffer[6] = 0;     // Padding
            this.buffer[7] = 0;     // Reserved

            this.bufferEnd = 8 + length;

            return(length);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="socket">The socket of the client request</param>
        /// <param name="stream">A stream that is associated with the socket in the first parameter</param>
        /// <param name="inputRecord">An instance of the Record class to be used</param>
        /// <param name="maxHeaderSize">Maximum size of the HTTP header</param>
        public Input(Socket socket, NetworkStream stream, Record inputRecord, FifoStream inputBuffer, int maxHeaderSize)
        {
            this.socket      = socket;
            this.inputRecord = inputRecord;
            this.inputRecord.Reset();
            this.stream      = stream;
            this.inputBuffer = inputBuffer;
            this.inputBuffer.Reset();
            this.maxHeaderSize    = maxHeaderSize;
            this.fastCgiRequestID = 0;
            this.role             = 0;
            this.keepConnection   = false;

            this.parametersReceived = false;
            this.initialized        = false;
            this.inputCompleted     = false;
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="request">Socket of the client connection.</param>
        /// <param name="requestID">FastCGI request ID</param>
        public Output(Input input, Socket request, NetworkStream stream, UInt16 requestID, Record record, FifoStream outputBuffer)
        {
            this.input        = input;
            this.connection   = request;
            this.stream       = stream;
            this.requestID    = requestID;
            this.header       = new Dictionary <string, string>();
            this.outputBuffer = outputBuffer;
            this.outputBuffer.Reset();
            this.record = record;

            this.ended      = false;
            this.headerSent = false;

            // Default headers (can be overwritten)
            this.header["Content-Type"]  = "text/html; charset=utf-8";
            this.header["Cache-Control"] = "no-cache";
            this.header["Date"]          = DateTime.Today.ToUniversalTime().ToString("r");
            this.header["Server"]        = "AsyncFastCGI.NET";
        }
Esempio n. 5
0
 /// <summary>
 /// Makes a copy of the content data, and pushes it into
 /// the passed FIFO stream.
 /// </summary>
 /// <param name="stream">The stream which receives the data</param>
 public void CopyContentTo(FifoStream stream)
 {
     byte[] data = new byte[this.recordContentLength];
     Array.Copy(this.buffer, HEADER_SIZE, data, 0, this.recordContentLength);
     stream.Write(data);
 }