001    package com.khubla.pragmatach.framework.api;
002    
003    import java.util.Enumeration;
004    import java.util.HashMap;
005    import java.util.Map;
006    
007    import javax.servlet.http.HttpServletRequest;
008    import javax.servlet.http.HttpServletResponse;
009    
010    /**
011     * @author tome
012     */
013    public class Headers {
014       /**
015        * HttpServletRequest
016        */
017       private final HttpServletRequest httpServletRequest;
018       /**
019        * HttpServletResponse
020        */
021       private final HttpServletResponse httpServletResponse;
022    
023       /**
024        * ctor
025        */
026       public Headers(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
027          this.httpServletRequest = httpServletRequest;
028          this.httpServletResponse = httpServletResponse;
029       }
030    
031       /**
032        * Accept-Language
033        */
034       public String getAcceptLanguage() {
035          return httpServletRequest.getHeader("Accept-Language");
036       }
037    
038       /**
039        * get content type
040        */
041       String getContentType() {
042          return httpServletRequest.getContentType();
043       }
044    
045       /**
046        * headers
047        */
048       public Map<String, String> getHeaders() {
049          final Map<String, String> ret = new HashMap<String, String>();
050          final Enumeration<String> enumer = httpServletRequest.getHeaderNames();
051          while (enumer.hasMoreElements()) {
052             final String key = enumer.nextElement();
053             ret.put(key, httpServletRequest.getHeader(key));
054          }
055          return ret;
056       }
057    
058       /**
059        * pragma
060        */
061       public String[] getPragma() {
062          final String pragmas = httpServletRequest.getHeader("Pragma");
063          if (null != pragmas) {
064             return pragmas.split(",");
065          }
066          return null;
067       }
068    
069       /**
070        * referer
071        */
072       public String getReferer() {
073          return httpServletRequest.getHeader("referer");
074       }
075    
076       /**
077        * User-Agent
078        */
079       public String getUserAgent() {
080          return httpServletRequest.getHeader("User-Agent");
081       }
082    
083       /**
084        * Via
085        */
086       public String getVia() {
087          return httpServletRequest.getHeader("Via");
088       }
089    
090       /**
091        * set header
092        */
093       public void setHeader(String name, String value) {
094          httpServletResponse.setHeader(name, value);
095       }
096    }