Exemple #1
0
        /// <summary>
        /// This method is called only once as it touches the input streams
        /// </summary>
        protected virtual JSONDataMap ParseRequestBodyAsJSONDataMap()
        {
            if (!Request.HasEntityBody)
            {
                return(null);
            }

            JSONDataMap result = null;

            var ctp = Request.ContentType;

            //Multipart
            if (ctp.IndexOf(ContentType.FORM_MULTIPART_ENCODED) >= 0)
            {
                var boundary = Multipart.ParseContentType(ctp);
                var mp       = Multipart.ReadFromStream(Request.InputStream, ref boundary, Request.ContentEncoding);
                result = mp.ToJSONDataMap();
            }
            else //Form URL encoded
            if (ctp.IndexOf(ContentType.FORM_URL_ENCODED) >= 0)
            {
                result = JSONDataMap.FromURLEncodedStream(new NFX.IO.NonClosingStreamWrap(Request.InputStream),
                                                          Request.ContentEncoding);
            }
            else//JSON
            if (ctp.IndexOf(ContentType.JSON) >= 0)
            {
                result = JSONReader.DeserializeDataObject(new NFX.IO.NonClosingStreamWrap(Request.InputStream),
                                                          Request.ContentEncoding) as JSONDataMap;
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Converts request into JSONDataMap
        /// </summary>
        protected JSONDataMap GetRequestAsJSONDataMap(WorkContext work)
        {
            if (!work.Request.HasEntityBody)
            {
                return(work.MatchedVars);
            }

            JSONDataMap result = null;

            var ctp = work.Request.ContentType;

            //Multipart
            if (ctp.IndexOf(ContentType.FORM_MULTIPART_ENCODED) >= 0)
            {
                result = MultiPartContent.ToJSONDataMap(work.Request.InputStream, ctp, work.Request.ContentEncoding);
            }
            else //Form URL encoded
            if (ctp.IndexOf(ContentType.FORM_URL_ENCODED) >= 0)
            {
                result = JSONDataMap.FromURLEncodedStream(new NFX.IO.NonClosingStreamWrap(work.Request.InputStream),
                                                          work.Request.ContentEncoding);
            }
            else//JSON
            if (ctp.IndexOf(ContentType.JSON) >= 0)
            {
                result = JSONReader.DeserializeDataObject(new NFX.IO.NonClosingStreamWrap(work.Request.InputStream),
                                                          work.Request.ContentEncoding) as JSONDataMap;
            }

            return(result == null ? work.MatchedVars : result.Append(work.MatchedVars));
        }