class HeaderableWrapper extends HttpServletRequestWrapper {

    final HttpHeaders httpHeaders;

    boolean removeParts = false;

    /**
     * Constructs a request object wrapping the given request.
     *
     * @param request The request to wrap
     * @throws IllegalArgumentException if the request is null
     */
    public HeaderableWrapper(HttpServletRequest request) {
        super(request);
        httpHeaders = new HttpHeaders();
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            Enumeration<String> headerValues = request.getHeaders(headerName);
            while (headerValues.hasMoreElements()) {
                String headerValue = headerValues.nextElement();
                httpHeaders.add(headerName, headerValue);
            }
        }
    }

    @Override
    public String getHeader(String name) {
        return httpHeaders.getFirst(name);
    }

    @Override
    public Enumeration<String> getHeaders(String name) {
        List<String> strings = httpHeaders.get(name);
        if (strings == null) {
            return null;
        } else {
            return Collections.enumeration(strings);
        }
    }

    @Override
    public Enumeration<String> getHeaderNames() {
        return Collections.enumeration(httpHeaders.keySet());
    }

    public HttpHeaders getHttpHeaders() {
        return httpHeaders;
    }

    @Override
    public Collection<Part> getParts() throws IOException, ServletException {
        if (removeParts) {
            return new ArrayList<>();
        } else {
            return super.getParts();
        }
    }
}