コード例 #1
0
        public void TomcatSendHeadersConstructorTest()
        {
            byte[]            content = null; // TODO: Initialize to an appropriate value
            TomcatSendHeaders target  = new TomcatSendHeaders(content);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
コード例 #2
0
        public void GetHeadersTest()
        {
            TomcatSendHeaders   target   = new TomcatSendHeaders(); // TODO: Initialize to an appropriate value
            NameValueCollection expected = null;                    // TODO: Initialize to an appropriate value
            NameValueCollection actual;

            actual = target.GetHeaders();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #3
0
        public void TestHeaderTest()
        {
            TomcatSendHeaders target   = new TomcatSendHeaders(); // TODO: Initialize to an appropriate value
            string            expected = string.Empty;            // TODO: Initialize to an appropriate value
            string            actual;

            actual = target.TestHeader();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #4
0
        public void GetStatusTest()
        {
            TomcatSendHeaders target = new TomcatSendHeaders(); // TODO: Initialize to an appropriate value
            int expected             = 0;                       // TODO: Initialize to an appropriate value
            int actual;

            actual = target.GetStatus();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #5
0
        //this will be passed in as delegate
        static void PrintFlush(BonCodeAJP13PacketCollection flushCollection)
        {
            foreach (TomcatReturn flushPacket in flushCollection)
            {
                //TODO: check by packet type and do different processing before calling flush
                //TomcatSendHeaders tcsh = new TomcatSendHeaders();
                if (flushPacket is TomcatSendHeaders)
                {
                    TomcatSendHeaders   tcsh      = (TomcatSendHeaders)flushPacket;
                    NameValueCollection tcHeaders = tcsh.GetHeaders();

                    for (int i = 0; i < tcHeaders.AllKeys.Length; i++)
                    {
                        Console.WriteLine(tcHeaders[i]);
                    }
                }
                else
                {
                    //generic flush of data
                    string outString = flushPacket.GetUserDataString();
                    Console.WriteLine(outString);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Function to be passed as delegate to BonCodeAJP13 process
        /// Will pass packet collection content to user browser and flush
        /// </summary>
        void PrintFlush(BonCodeAJP13PacketCollection flushCollection)
        {
            p_FlushInProgress = true;

            string keyName  = "";
            string keyValue = "";


            bool isBinary         = false;
            long contentLength    = 0; //only assigned if content is known
            long transferredBytes = 0;



            foreach (TomcatReturn flushPacket in flushCollection)
            {
                try
                {
                    //check by packet type and do different processing before calling flush
                    if (flushPacket is TomcatSendHeaders)
                    {
                        TomcatSendHeaders tcshPackage = (TomcatSendHeaders)flushPacket;
                        //get Headers
                        NameValueCollection tomcatHeaders = tcshPackage.GetHeaders();
                        //iterate through headers and set
                        for (int i = 0; i < tomcatHeaders.AllKeys.Length; i++)
                        {
                            keyName  = tomcatHeaders.AllKeys[i];
                            keyValue = tomcatHeaders[keyName];


                            //check for repeated headers of the same type they are seperated by pipe+comma combination
                            string[] sHeaders  = keyValue.Split(new string[] { "|," }, StringSplitOptions.None);
                            string   tempValue = "";
                            if (sHeaders.Length > 1)
                            {
                                //check for multiple headers of same type returned, e.g. cookies
                                for (int i2 = 0; i2 < sHeaders.Length; i2++)
                                {
                                    if (i2 == sHeaders.Length - 1)
                                    {
                                        tempValue = sHeaders[i2].Substring(0, sHeaders[i2].Length - 1); //last array element
                                    }
                                    else
                                    {
                                        tempValue = sHeaders[i2]; //regular array element
                                    }
                                    p_Context.Response.AddHeader(keyName, tempValue);
                                }
                            }


                            else
                            {
                                //single header remove pipe character at the end
                                tempValue = keyValue.Substring(0, keyValue.Length - 1);
                                p_Context.Response.AddHeader(keyName, tempValue);
                            }

                            //check for binary or text disposition
                            if (!isBinary && (keyName == "Content-Type" || keyName == "Content-Encoding"))
                            {
                                //set encoding seperatly if needed
                                if (keyName == "Content-Encoding" && (tempValue.Contains("gzip") || tempValue.Contains("deflate")))
                                {
                                    isBinary = true;
                                }
                                else
                                {
                                    isBinary = TestBinary(keyValue);
                                }
                            }
                            //check for known content length
                            if (keyName == "Content-Length")
                            {
                                try
                                {
                                    contentLength = System.Convert.ToInt64(tempValue);
                                }
                                catch (Exception) {
                                    contentLength = 0;
                                };
                            }


                            //check whether we can represent a given header in native IIS Response context
                            IISNativeHeaders(keyName, tempValue);
                        }
                        //set response status code
                        p_Context.Response.StatusCode = tcshPackage.GetStatus();
                    }
                    else if (flushPacket is TomcatEndResponse)
                    {
                        //if this is the last package and we know the content length we need to write empty strings
                        //this is a fix if content-length is misrepresented by tomcat
                        if (contentLength > 0 && transferredBytes < contentLength)
                        {
                            string fillEmpty = new string(' ', System.Convert.ToInt32(contentLength - transferredBytes));
                            p_Context.Response.Write(fillEmpty);
                        }
                    }
                    else if (flushPacket is TomcatSendBodyChunk)
                    {
                        transferredBytes = transferredBytes + flushPacket.GetUserDataBytes().Length;
                        p_Context.Response.BinaryWrite(flushPacket.GetUserDataBytes());
                    }
                }
                catch (Exception)
                {
                    //TODO: add exception handler logging
                    p_Context.Response.Write("Error in transfer of data from tomcat to browser.");
                }
            } //loop over packets

            //attempt to flush now
            try
            {
                p_Context.Response.Flush();
            }
            catch (Exception)
            {
                //do nothing. Mostly this occurs if the browser already closed connection with server or headers were already transferred
                bool errFlag = true;
            }

            p_FlushInProgress = false;
        } //end print flush
コード例 #7
0
        public void TomcatSendHeadersConstructorTest1()
        {
            TomcatSendHeaders target = new TomcatSendHeaders();

            Assert.Inconclusive("TODO: Implement code to verify target");
        }