Exemplo n.º 1
0
        private void TriggerMessageReceived(HttpMessage message)
        {
            var request = message as HttpRequest;

            if (_messageSerializer != null && request != null)
            {
                if (message.Body != null && message.Body.Length > 0)
                {
                    var result = _messageSerializer.Deserialize(message.Headers["Content-Type"], message.Body);
                    if (result == null)
                    {
                        throw new BadRequestException("Unsupported content-type: " + message.ContentType);
                    }

                    var formAndFiles = result as FormAndFilesResult;
                    if (formAndFiles != null)
                    {
                        request.Form  = formAndFiles.Form;
                        request.Files = formAndFiles.Files;
                    }
                    else
                    {
                        throw new HttpException(500, "Unknown decoder result: " + result);
                    }
                }
                var cookies = request.Headers["Cookie"];
                if (cookies != null)
                {
                    request.Cookies = _cookieParser.Parse(cookies);
                }
            }

            _messageReceived(message);
        }
        public void Test_empty_name()
        {
            var parser  = new HttpCookieParser();
            var cookies = parser.Parse("=abc");

            Assert.Equal(0, cookies.Count);
        }
        public void Test()
        {
            var parser  = new HttpCookieParser();
            var cookies = parser.Parse(@"__qca=P0-1267122445-1340133197581; gauthed=1; km_lv=x; km_uq=; kvcd=1348223997344; km_ai=28603; km_ni=28603; usr=t=XXjSGVAt1Euf&s=ng3ePzX9NUKq; __utma=140029553.1710528871.1340133198.1355396765.1355406563.180; __utmb=140029553.1.10.1355406563; __utmc=140029553; __utmz=140029553.1355396765.179.62.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)");

            Assert.Equal(12, cookies.Count);
            Assert.Equal("P0-1267122445-1340133197581", cookies["__qca"].Value);
            Assert.Equal("1", cookies["gauthed"].Value);
            Assert.Equal("x", cookies["km_lv"].Value);
            Assert.Equal("", cookies["km_uq"].Value);
            Assert.Equal("1348223997344", cookies["kvcd"].Value);
            Assert.Equal("28603", cookies["km_ai"].Value);
            Assert.Equal("28603", cookies["km_ni"].Value);
            Assert.Equal("140029553.1355396765.179.62.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)", cookies["__utmz"].Value);
        }
        private void TriggerMessageReceived(HttpMessage message)
        {
            var request = message as HttpRequest;

            if (_messageSerializer != null && request != null)
            {
                if (message.Body != null && message.Body.Length > 0)
                {
                    var result = _messageSerializer.Deserialize(message.Headers["Content-Type"], message.Body);
                    if (result == null)
                    {
                        //it's a so simple protocol, we can expect that the client can handle it.
                        if (!"text/plain".Equals(message.Headers["Content-Type"], StringComparison.OrdinalIgnoreCase))
                        {
                            throw new BadRequestException("Unsupported content-type: " + message.ContentType);
                        }
                    }
                    else
                    {
                        var formAndFiles = result as FormAndFilesResult;
                        if (formAndFiles != null)
                        {
                            request.Form  = formAndFiles.Form;
                            request.Files = formAndFiles.Files;
                        }
                        else
                        {
                            throw new HttpException(500, "Unknown decoder result: " + result);
                        }
                    }
                }

                var cookies = request.Headers["Cookie"];
                if (cookies != null)
                {
                    request.Cookies = _cookieParser.Parse(cookies);
                }
            }

            _messageReceived(message);
        }
        private void TriggerMessageReceived(HttpMessage message)
        {
            var request = message as HttpRequest;

            if (BodyDecoder != null && request != null)
            {
                if (message.Body != null && message.Body.Length > 0)
                {
                    var result = BodyDecoder.Decode(request);
                    if (!result)
                    {
                        throw new BadRequestException("Unknown body content-type.");
                    }
                }
                var cookies = request.Headers["Cookie"];
                if (cookies != null)
                {
                    request.Cookies = _cookieParser.Parse(cookies);
                }
            }

            _messageReceived(message);
        }