Beispiel #1
0
        public virtual void TestParseContentType()
        {
            Encoding utf8 = Sharpen.Extensions.GetEncoding("UTF-8");
            Dictionary <string, byte[]> contentTypes = new Dictionary <string, byte[]>();

            contentTypes.Put("multipart/related; boundary=\"BOUNDARY\"", Sharpen.Runtime.GetBytesForString
                                 (new string("\r\n--BOUNDARY"), utf8));
            contentTypes.Put("multipart/related; boundary=BOUNDARY", Sharpen.Runtime.GetBytesForString
                                 (new string("\r\n--BOUNDARY"), utf8));
            contentTypes.Put("multipart/related;boundary=X", Sharpen.Runtime.GetBytesForString
                                 (new string("\r\n--X"), utf8));
            foreach (string contentType in contentTypes.Keys)
            {
                MultipartReaderDelegate delegate_ = null;
                MultipartReader         reader    = new MultipartReader(contentType, delegate_);
                byte[] expectedBoundary           = (byte[])contentTypes.Get(contentType);
                byte[] boundary = reader.GetBoundary();
                NUnit.Framework.Assert.IsTrue(Arrays.Equals(boundary, expectedBoundary));
            }
            try
            {
                MultipartReaderDelegate delegate_ = null;
                MultipartReader         reader    = new MultipartReader("multipart/related; boundary=\"BOUNDARY"
                                                                        , delegate_);
                NUnit.Framework.Assert.IsTrue("Should not have gotten here, above lines should have thrown exception"
                                              , false);
            }
            catch (Exception)
            {
            }
        }
Beispiel #2
0
 public MultipartReader(string contentType, MultipartReaderDelegate delegate_)
 {
     this.contentType = contentType;
     this.delegate_   = delegate_;
     this.buffer      = new ByteArrayBuffer(1024);
     this.state       = MultipartReader.MultipartReaderState.kAtStart;
     ParseContentType();
 }
		public MultipartReader(string contentType, MultipartReaderDelegate delegate_)
		{
			this.contentType = contentType;
			this.delegate_ = delegate_;
			this.buffer = new ByteArrayBuffer(1024);
			this.state = MultipartReader.MultipartReaderState.kAtStart;
			ParseContentType();
		}