1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.container.servlet.filters.internal

File SetHTTPHeaderFilter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
6
3
1
71
34
4
0.67
2
3
1.33

Classes

Class Line # Actions
SetHTTPHeaderFilter 38 6 0% 4 1
0.9090909490.9%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.container.servlet.filters.internal;
21   
22    import java.io.IOException;
23   
24    import javax.servlet.Filter;
25    import javax.servlet.FilterChain;
26    import javax.servlet.FilterConfig;
27    import javax.servlet.ServletException;
28    import javax.servlet.ServletRequest;
29    import javax.servlet.ServletResponse;
30    import javax.servlet.http.HttpServletResponse;
31   
32    /**
33    * Filter that set the desired header of the HTTP response to the desired value.
34    *
35    * @version $Id: a306a2b297e1c3653d0a23012f2e0c93794fa19b $
36    * @since 6.3M2
37    */
 
38    public class SetHTTPHeaderFilter implements Filter
39    {
40    private String httpHeaderName;
41   
42    private String httpHeaderValue;
43   
 
44  64 toggle @Override
45    public void init(FilterConfig filterConfig) throws ServletException
46    {
47  64 httpHeaderName = filterConfig.getInitParameter("name");
48  64 httpHeaderValue = filterConfig.getInitParameter("value");
49    }
50   
 
51  14096 toggle @Override
52    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
53    throws IOException, ServletException
54    {
55    // If the response is an HTTP response
56  14094 if (response instanceof HttpServletResponse) {
57  14065 HttpServletResponse httpResponse = (HttpServletResponse) response;
58    // Set the attribute
59  14085 httpResponse.addHeader(httpHeaderName, httpHeaderValue);
60    }
61   
62    // Pass control on to the next filter
63  14105 chain.doFilter(request, response);
64    }
65   
 
66  64 toggle @Override
67    public void destroy()
68    {
69    // Nothing to do
70    }
71    }