Ejemplo n.º 1
0
        /// <summary>
        /// Handle redirects with a status code that can in future support verbs other
        /// than GET, thus supporting full REST functionality.
        /// </summary>
        /// <remarks>
        /// Handle redirects with a status code that can in future support verbs other
        /// than GET, thus supporting full REST functionality.
        /// <p>
        /// The target URL is included in the redirect text returned
        /// <p>
        /// At the end of this method, the output stream is closed.
        /// </remarks>
        /// <param name="request">
        /// request (hence: the verb and any other information
        /// relevant to a redirect)
        /// </param>
        /// <param name="response">the response</param>
        /// <param name="target">the target URL -unencoded</param>
        /// <exception cref="System.IO.IOException"/>
        public static void SendRedirect(HttpServletRequest request, HttpServletResponse response
                                        , string target)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Redirecting {} {} to {}", request.GetMethod(), request.GetRequestURI()
                          , target);
            }
            string location = response.EncodeRedirectURL(target);

            response.SetStatus(HttpServletResponse.ScFound);
            response.SetHeader(Location, location);
            response.SetContentType(MimeType.Html);
            PrintWriter writer = response.GetWriter();

            ProxyUtils.Page p = new ProxyUtils.Page(writer);
            p.Html().Head().Title("Moved").().Body().H1("Moved").Div().("Content has moved ")
            .A(location, "here").().().();
            writer.Close();
        }