Esempio n. 1
0
        IEnumerator CoProcessFilePut(HttpListenerContext context, string path)
        {
            var request = context.Request;

            UnityEngine.Debug.Assert(request.HttpMethod == "PUT");
            // 内容があるが?delete=trueがあれば、それは削除
            var deleteValue = request.QueryString["delete"];

            if (deleteValue == "true")
            {
                DebugServerUtil.DeleteOverride(path);
            }
            else
            {
                var  bodyData = request.InputStream;
                var  buffer   = new byte[1024 * 1024]; // 秒間60MBはありえない数字じゃないのでこれくらい用意しておく
                bool first    = true;
                while (true)
                {
                    var asyncResult = bodyData.BeginRead(buffer, 0, buffer.Length, null, null);
                    while (!asyncResult.IsCompleted)
                    {
                        yield return(null);
                    }
                    var size = bodyData.EndRead(asyncResult);
                    if (size == 0)
                    {
                        break;
                    }
                    if (first)
                    {
                        DebugServerUtil.SaveOverride(path, buffer, size);
                        first = false;
                    }
                    else
                    {
                        DebugServerUtil.AppendOverride(path, buffer, size);
                    }
                }
                bodyData.Close();
            }
            var response = context.Response;

            response.Close();
            OnChanged(path);
        }
        void ProcessFilePut(HttpListenerContext context, string path)
        {
            var request = context.Request;

            Debug.Assert(request.HttpMethod == "PUT");
            // 内容があるが?delete=trueがあれば、それは削除
            var deleteValue = request.QueryString["delete"];

            if (deleteValue == "true")
            {
                DebugServerUtil.DeleteOverride(path);
            }
            else
            {
                var bodyData = request.InputStream;
                DebugServerUtil.SaveOverride(path, bodyData);                 // TODO: 非同期化
                bodyData.Close();
            }
            var response = context.Response;

            response.Close();
            OnChanged(path);
        }