001 /*
002 * Copyright (c) 2007 Mozilla Foundation
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a
005 * copy of this software and associated documentation files (the "Software"),
006 * to deal in the Software without restriction, including without limitation
007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
008 * and/or sell copies of the Software, and to permit persons to whom the
009 * Software is furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
017 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
019 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
020 * DEALINGS IN THE SOFTWARE.
021 */
022
023 package nu.validator.servletfilter;
024
025 import java.io.IOException;
026
027 import javax.servlet.Filter;
028 import javax.servlet.FilterChain;
029 import javax.servlet.FilterConfig;
030 import javax.servlet.ServletException;
031 import javax.servlet.ServletInputStream;
032 import javax.servlet.ServletRequest;
033 import javax.servlet.ServletResponse;
034 import javax.servlet.http.HttpServletRequest;
035
036 public class InboundGzipFilter implements Filter {
037
038 public void destroy() {
039 }
040
041 public void doFilter(ServletRequest req, ServletResponse res,
042 FilterChain chain) throws IOException, ServletException {
043 HttpServletRequest request = (HttpServletRequest) req;
044 String method = request.getMethod();
045 if ("POST".equals(method) || "PUT".equals(method)) {
046 String ce = request.getHeader("Content-Encoding");
047 if (ce != null && "gzip".equalsIgnoreCase(ce.trim())) {
048 chain.doFilter(wrap(request), res);
049 } else {
050 // do nothing
051 chain.doFilter(req, res);
052 }
053 } else {
054 // do nothing
055 chain.doFilter(req, res);
056 }
057 }
058
059 private ServletRequest wrap(HttpServletRequest request) {
060 // TODO Auto-generated method stub
061 return null;
062 }
063
064 public void init(FilterConfig config) throws ServletException {
065 }
066
067 private class GzipServletInputStream extends ServletInputStream {
068
069 @Override
070 public int read() throws IOException {
071 // TODO Auto-generated method stub
072 return 0;
073 }
074
075 }
076 }