示例#1
0
        public void MultipleValuesUseLast()
        {
            var actual = @"jonas=king&sara=queen&sara=wife";

            var decoder = new UrlDecoder();
            var result = decoder.Parse(actual);

            Assert.Equal("wife", result["sara"]);
        }
示例#2
0
        public void TwoValuesCheckBoth()
        {
            var actual = @"jonas=king&sara=queen&sara=wife";

            var decoder = new UrlDecoder();
            var result = decoder.Parse(actual);

            Assert.Equal("queen", result.Get("sara")[0]);
            Assert.Equal("wife", result.Get("sara")[1]);
        }
示例#3
0
        public void EncodedString()
        {
            var actual = @"jonas=king&sara=queen%26wife%20hmmz!";

            var decoder = new UrlDecoder();
            var result = decoder.Parse(actual);

            Assert.Equal("king", result["jonas"]);
            Assert.Equal("queen&wife hmmz!", result["sara"]);
        }
示例#4
0
        public void TwoSimplePairs()
        {
            var actual = @"jonas=king&sara=queen";

            var decoder = new UrlDecoder();
            var result = decoder.Parse(actual);

            Assert.Equal("king", result["jonas"]);
            Assert.Equal("queen", result["sara"]);
        }
        /// <summary>
        /// Decode body stream
        /// </summary>
        /// <param name="message">Contains the body to decode.</param>
        /// <exception cref="FormatException">Body format is invalid for the specified content type.</exception>
        public bool Decode(IHttpRequest message)
        {
            if (message == null) throw new ArgumentNullException("message");
            var msg = message as HttpRequest;
            if (msg == null)
                throw new NotSupportedException("Body decoders expect messages of type 'HttpRequest'.");

            if (!message.ContentType.StartsWith(MimeType, StringComparison.OrdinalIgnoreCase))
                return false;

            try
            {
                var decoder = new UrlDecoder();
                decoder.Parse(new StreamReader(message.Body), msg.Form);
                message.Body.Position = 0;
                return true;
            }
            catch (ArgumentException err)
            {
                throw new DecoderFailureException(err.Message, err);
            }
        }
        /// <summary>
        /// Deserialize the content from the stream.
        /// </summary>
        /// <param name="contentType">Used to identify the object which is about to be deserialized. Specified by the <c>Serialize()</c> method when invoked in the other end point.</param>
        /// <param name="source">Stream that contains the object to deserialize.</param>
        /// <returns>Created object</returns>
        /// <exception cref="SerializationException">Deserialization failed</exception>
        public object Deserialize(string contentType, Stream source)
        {
            if (contentType == null) throw new ArgumentNullException("contentType");
            if (source == null) throw new ArgumentNullException("source");

            if (!contentType.StartsWith(MimeType, StringComparison.OrdinalIgnoreCase))
                return null;

            try
            {
                var result = new FormAndFilesResult()
                {
                    Form = new ParameterCollection()
                };
                var decoder = new UrlDecoder();
                decoder.Parse(new StreamReader(source), result.Form);
                source.Position = 0;
                return result;
            }
            catch (ArgumentException err)
            {
                throw new DecoderFailureException(err.Message, err);
            }
        }