예제 #1
0
파일: Multipart.cs 프로젝트: shz/pointy
 public static MultipartParser Parse(MimeType mime)
 {
     return new MultipartParser(mime);
 }
예제 #2
0
파일: MimeType.cs 프로젝트: shz/pointy
        /// <summary>
        /// Guesses MIME type from file extension
        /// </summary>
        /// <param name="extension">File extension.  May include leading .</param>
        /// <returns></returns>
        public static MimeType ByExtension(string extension)
        {
            // Strip the leading . if it's present
            if (extension.Length > 0 && extension[0] == '.')
                extension = extension.Substring(1);

            MimeType ret = null;
            if (!TypesByExtensions.TryGetValue(extension, out ret))
                ret = new MimeType("application", "octet-stream");
            return ret;
        }
예제 #3
0
파일: Multipart.cs 프로젝트: shz/pointy
        internal MultipartParser(MimeType mime)
        {
            // Make sure the mimetype is valid
            if (mime == null) throw new ArgumentNullException("mime");
            if (!mime.Type.Equals("multipart")) throw new Exception("Can't parse multipart data because the MIME type isn't multipart");
            if (!mime.Parameters.ContainsKey("boundary")) throw new Exception("Can't parse multipart data because the MIME type doesn't contain a boundary");

            // Grab the boundary and strip wrapping quotes if needed
            string boundary = mime.Parameters["boundary"];
            if (boundary[0] == '"' && boundary[boundary.Length - 1] == '"')
                boundary = boundary.Substring(1, boundary.Length - 2);

            // Initialize our static state
            Boundary = Encoding.ASCII.GetBytes("\r\n--" + boundary);
            Bp = 0;
            State = ParseState.Preamble;
        }