Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] how to get the request header's specified field and add it to the URI?

Hi,
why don't you use a fIlter?
Something like

public class HashFilter implements Filter {

   
     public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain nextFilter)
         throws ServletException, IOException
     {
        
    request.setAttribute("caucho.form.character.encoding","UTF-8");
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        String hash=req.getHeader("Hash");
        if (hash!=null)
            request.getRequestDispatcher("/"+hash+req.getRequestURI()).forward(req, res);
     
         nextFilter.doFilter(request, response);
    }
}


in web.xml

    <filter>
        <filter-name>hashFilter</filter-name>
        <filter-class>com.package.HashFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>hashFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>


bye
Andrea


On 6/08/11 1:14 PM, zhiwei chen wrote:
hi,all.
I give the specified request header to jetty server,how can I get this specified field and add it to the URI?

For example:
Request header:

GET /hello/test.txt HTTP/1.1
User-Agent: curl/7.21.3
Host: localhost
Accept: */*
Hash:234

As you can see,this request header has a specified field "Hash",the URI is "/hello/test.txt".

I want to rewrite this URI to "/234/hello/test.txt"(i.e.: the new URI is : /Hash/oldURI )

Jetty7 hasn't this class,so how should I get the specified request header field and rewrite the request URI?

Is jetty-rewirte.xml can do this? How to add this rule?

Thank you!


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top