Inheritance: HproseContext
Esempio n. 1
0
 public void Handle(HttpContext httpContext, HproseHttpMethods methods)
 {
     currentContext = httpContext;
     try {
         HproseHttpContext context = new HproseHttpContext(httpContext);
         SendHeader(context);
         string method  = context.Request.HttpMethod;
         Stream ostream = GetOutputStream(context);
         if (method == "GET")
         {
             if (getEnabled)
             {
                 DoFunctionList(methods, context)
                 .WriteTo(ostream);
             }
             else
             {
                 context.Response.StatusCode = 403;
             }
         }
         else if (method == "POST")
         {
             Handle(GetInputStream(context), methods, context)
             .WriteTo(ostream);
         }
         ostream.Close();
         context.Response.Flush();
     }
     finally {
         currentContext = null;
     }
 }
Esempio n. 2
0
        private void SendHeader(HproseHttpContext context)
        {
            if (OnSendHeader != null)
            {
                OnSendHeader(context);
            }
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            response.ContentType = "text/plain";
            if (p3pEnabled)
            {
                response.AppendHeader("P3P",
                                      "CP=\"CAO DSP COR CUR ADM DEV TAI PSA PSD " +
                                      "IVAi IVDi CONi TELo OTPi OUR DELi SAMi " +
                                      "OTRi UNRi PUBi IND PHY ONL UNI PUR FIN " +
                                      "COM NAV INT DEM CNT STA POL HEA PRE GOV\"");
            }
            if (crossDomainEnabled)
            {
                string origin = request.Headers["Origin"];
                if (origin != null && origin != "" && origin != "null")
                {
                    if (origins.Count == 0 || origins.ContainsKey(origin))
                    {
                        response.AppendHeader("Access-Control-Allow-Origin", origin);
                        response.AppendHeader("Access-Control-Allow-Credentials", "true");
                    }
                }
                else
                {
                    response.AppendHeader("Access-Control-Allow-Origin", "*");
                }
            }
            if (compressionEnabled)
            {
                string acceptEncoding = request.Headers["Accept-Encoding"];
                if (acceptEncoding != null)
                {
                    acceptEncoding = acceptEncoding.ToLower();
                    if (acceptEncoding.IndexOf("deflate") > -1)
                    {
                        response.AppendHeader("Content-Encoding", "deflate");
                    }
                    else if (acceptEncoding.IndexOf("gzip") > -1)
                    {
                        response.AppendHeader("Content-Encoding", "gzip");
                    }
                }
            }
        }
Esempio n. 3
0
        private MemoryStream GetInputStream(HproseHttpContext context)
        {
            Stream istream = context.Request.InputStream;
            int    len     = (int)istream.Length;
            int    off     = 0;

            byte[] data = new byte[len];
            while (len > 0)
            {
                int size = istream.Read(data, off, len);
                off += size;
                len -= size;
            }
            istream.Close();
            return(new MemoryStream(data));
        }
Esempio n. 4
0
        protected override object[] FixArguments(Type[] argumentTypes, object[] arguments, int count, HproseContext context)
        {
            HproseHttpContext currentContext = (HproseHttpContext)context;

            if (argumentTypes.Length != count)
            {
                object[] args = new object[argumentTypes.Length];
                System.Array.Copy(arguments, 0, args, 0, count);
                Type argType = argumentTypes[count];
                if (argType == typeof(HproseContext) ||
                    argType == typeof(HproseHttpContext))
                {
                    args[count] = currentContext;
                }
                else if (argType == typeof(HttpContext))
                {
                    args[count] = currentContext.Context;
                }
                else if (argType == typeof(HttpRequest))
                {
                    args[count] = currentContext.Request;
                }
                else if (argType == typeof(HttpResponse))
                {
                    args[count] = currentContext.Response;
                }
                else if (argType == typeof(HttpServerUtility))
                {
                    args[count] = currentContext.Server;
                }
                else if (argType == typeof(HttpApplicationState))
                {
                    args[count] = currentContext.Application;
                }
                else if (argType == typeof(HttpSessionState))
                {
                    args[count] = currentContext.Session;
                }
                return(args);
            }
            return(arguments);
        }
Esempio n. 5
0
        private Stream GetOutputStream(HproseHttpContext context)
        {
            Stream ostream = new BufferedStream(context.Response.OutputStream);

            if (compressionEnabled)
            {
                string acceptEncoding = context.Request.Headers["Accept-Encoding"];
                if (acceptEncoding != null)
                {
                    acceptEncoding = acceptEncoding.ToLower();
                    if (acceptEncoding.IndexOf("deflate") > -1)
                    {
                        ostream = new DeflateStream(ostream, CompressionMode.Compress);
                    }
                    else if (acceptEncoding.IndexOf("gzip") > -1)
                    {
                        ostream = new GZipStream(ostream, CompressionMode.Compress);
                    }
                }
            }
            return(ostream);
        }