protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            httpResponse.KeepAlive = false;

            if (m_NeighbourService == null)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
                return;
            }

            switch (httpRequest.HttpMethod)
            {
            case "POST":
            {
                OSDMap args = RestHandlerUtils.DeserializeOSMap(httpRequest);
                if (args == null)
                {
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                    httpResponse.RawBuffer  = Util.UTF8.GetBytes("false");
                    return;
                }

                if (RestHandlerUtils.GetParams(httpRequest.UriPath, out UUID regionID, out ulong regionHandle, out string action) ||
                    regionID == UUID.Zero)
                {
                    m_log.InfoFormat("[RegionPostHandler]: Invalid parameters for neighbour message {0}", httpRequest.UriPath);
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                    return;
                }
                ProcessPostRequest(args, httpRequest, httpResponse, regionID);
                break;
            }

            case "GET":
            case "PUT":
            case "DELETE":
                httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
                return;

            default:
            {
                httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
                return;
            }
            }
        }
        public override byte[] Handle(string path, Stream request,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            byte[] result = new byte[0];

            UUID   regionID;
            string action;
            ulong  regionHandle;

            if (RestHandlerUtils.GetParams(path, out regionID, out regionHandle, out action))
            {
                m_log.InfoFormat("[RegionPostHandler]: Invalid parameters for neighbour message {0}", path);
                httpResponse.StatusCode        = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Invalid parameters for neighbour message " + path;

                return(result);
            }

            if (m_AuthenticationService != null)
            {
                // Authentication
                string authority = string.Empty;
                string authToken = string.Empty;
                if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken))
                {
                    m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path);
                    httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return(result);
                }
                // TODO: Rethink this
                //if (!m_AuthenticationService.VerifyKey(regionID, authToken))
                //{
                //    m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path);
                //    httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
                //    return result;
                //}
                m_log.DebugFormat("[RegionPostHandler]: Authentication succeeded for {0}", regionID);
            }

            OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength);

            if (args == null)
            {
                httpResponse.StatusCode        = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Unable to retrieve data";
                m_log.DebugFormat("[RegionPostHandler]: Unable to retrieve data for post {0}", path);
                return(result);
            }

            // retrieve the regionhandle
            ulong regionhandle = 0;

            if (args["destination_handle"] != null)
            {
                UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
            }

            RegionInfo aRegion = new RegionInfo();

            try
            {
                aRegion.UnpackRegionInfoData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[RegionPostHandler]: exception on unpacking region info {0}", ex.Message);
                httpResponse.StatusCode        = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Problems with data deserialization";
                return(result);
            }

            // Finally!
            GridRegion thisRegion = m_NeighbourService.HelloNeighbour(regionhandle, aRegion);

            OSDMap resp = new OSDMap(1);

            if (thisRegion != null)
            {
                resp["success"] = OSD.FromBoolean(true);
            }
            else
            {
                resp["success"] = OSD.FromBoolean(false);
            }

            httpResponse.StatusCode = (int)HttpStatusCode.OK;

            return(Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)));
        }
        // TODO: unused: private bool m_AllowForeignGuests;
        protected void ProcessPostRequest(OSDMap args, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID regionID)
        {
            byte[] result = new byte[0];

            if (m_AuthenticationService != null)
            {
                // Authentication
                string authority = string.Empty;
                string authToken = string.Empty;
                if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken))
                {
                    m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message");
                    httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return;
                }
                // TODO: Rethink this
                //if (!m_AuthenticationService.VerifyKey(regionID, authToken))
                //{
                //    m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path);
                //    httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
                //    return result;
                //}
                m_log.DebugFormat("[RegionPostHandler]: Authentication succeeded for {0}", regionID);
            }

            // retrieve the regionhandle
            ulong regionhandle = 0;

            if (args["destination_handle"] != null)
            {
                UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
            }

            RegionInfo aRegion = new RegionInfo();

            try
            {
                aRegion.UnpackRegionInfoData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[RegionPostHandler]: exception on unpacking region info {0}", ex.Message);
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            // Finally!
            GridRegion thisRegion = m_NeighbourService.HelloNeighbour(regionhandle, aRegion);

            OSDMap resp = new OSDMap(1);

            if (thisRegion != null)
            {
                resp["success"] = OSD.FromBoolean(true);
            }
            else
            {
                resp["success"] = OSD.FromBoolean(false);
            }

            httpResponse.RawBuffer  = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp));
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }