Package rabbit.http

Examples of rabbit.http.HttpHeader


  if (requestVersion.equals ("HTTP/1.1")) {
      String host = header.getHeader ("Host");
      if (host == null) {
    Exception exe =
        new Exception ("No host header set in HTTP/1.1 request");
    HttpHeader ret =
        con.getHttpGenerator ().get400 (exe);
    return ret;
      }
      maychunk = true;   
      String closeit = header.getHeader ("Proxy-Connection");
      if (closeit == null)
    closeit = header.getHeader ("Connection");
      mayKeepAlive = (closeit == null
          || !closeit.equalsIgnoreCase ("close"));
  } else {
      header.setHTTPVersion ("HTTP/1.1");
      maychunk = false;
      // stupid netscape to not follow the standards,
      // only "Connection" should be used...
      String keepalive = header.getHeader ("Proxy-Connection");
      mayKeepAlive = (keepalive != null
          && keepalive.equalsIgnoreCase ("Keep-Alive"));
      if (!mayKeepAlive) {
    keepalive = header.getHeader ("Connection");
    mayKeepAlive = (keepalive != null
        && keepalive.equalsIgnoreCase ("Keep-Alive"));
     
  }
 
  boolean useCached = true;
  boolean cacheAllowed = true;
  // damn how many system that use cookies with id's
  /*
        System.out.println ("auth: " + header.getHeader ("authorization") +
                            ", cookie:" + header.getHeader ("cookie") +
                            ", Pragma: " + header.getHeader ("Pragma") +
                            ", Cache: " + header.getHeader ("Cache-Control"));
  */
  //String cached = header.getHeader ("Pragma");
  List<String> ccs = header.getHeaders ("Cache-Control");
  for (String cached : ccs) {
      cached = cached.trim ();
      if (cached.equals ("no-store")) {
    useCached = false;
    cacheAllowed = false;
      } else if (cached.equals ("no-cache")) {
    useCached = false;
      } else if (cached.equals ("no-transform")) {
    useCached = false;     // cache is transformed.
    cacheAllowed = false// dont store, no point.
    con.setMayFilter (false);
      }
  }

  ccs = header.getHeaders ("Pragma");
  for (String cached : ccs) {
      cached = cached.trim ();
      if (cached.equals ("no-cache")) {
    useCached = false;
      }
  }

 
  String method = header.getMethod ().trim ();
  if (!method.equals ("GET") && !method.equals ("HEAD")) {
      useCached = false;
      cacheAllowed = false;
      //mayKeepAlive = false;
  } else if (method.equals ("HEAD")) {
      maychunk = false;
  }
  con.setChunking (maychunk);

  String mf = header.getHeader ("Max-Forwards");
  if (mf != null) {
      HttpHeader ret = checkMaxForwards (con, header, mf);
      if (ret != null) {
    return ret;
      }
  }

  String auths = header.getHeader ("authorization");
  if (auths != null) {
      useCached = false;     // dont use cached files,
      cacheAllowed = false// and dont cache it.
  } else if (cookieId) {
      String cookie = header.getHeader ("cookie");
      String lccookie = null;
      if (cookie != null &&     // cookie-passwords suck.
    (((lccookie = cookie.toLowerCase ()).indexOf ("password") >= 0)
     || (lccookie.indexOf ("id") >= 0))) {
    useCached = false;     // dont use cached files,
    cacheAllowed = false// and dont cache it.
      }
  }
  con.setMayUseCache (useCached);
  con.setMayCache (cacheAllowed);
  con.setKeepalive (mayKeepAlive);
 
  String requri = header.getRequestURI ();
  if (requri.toLowerCase ().startsWith (NOPROXY))
      requri = handleNoProxyRequest (requri, header, con);      
   
  HttpHeader headerr = handleURLSetup (requri, header, con);
  if (headerr != null)
      return headerr;
 
  removeConnectionTokens (header);
  int rsize = removes.size ();
View Full Code Here


              Connection.RequestHandler rh,
              TaskRunner tr,
              List<Range> ranges, long totalSize)
  throws IOException {
  super (cache, rh.entry, tr);
  HttpHeader oldresp = rh.dataHook;
  contentType = oldresp.getHeader ("Content-Type");
  this.ranges = ranges;
  this.totalSize = totalSize;
  buffer = ByteBuffer.allocateDirect (4096);
    }   
View Full Code Here

    /** Get a new HttpHeader initialized with some data.
     * @param statusLine the statusline of the response.
     * @return a new HttpHeader.
     */
    public HttpHeader getHeader (String statusLine) {
  HttpHeader ret = new HttpHeader ();
  ret.setStatusLine (statusLine);
  ret.setHeader ("Server", con.getProxy ().getServerIdentity ());
  ret.setHeader ("Content-type", "text/html");
  ret.setHeader ("Pragma", "no-cache");
  ret.setHeader ("Date", HttpDateParser.getDateString (new Date ()));
  return ret;   
    }
View Full Code Here

    /** Get a 200 Ok header
     * @return a 200 HttpHeader .
     */
    public HttpHeader get200 () {
  HttpHeader header = getHeader ("HTTP/1.1 200 Ok")
  return header;
    }
View Full Code Here

  if (d != null)
      to.setHeader (type, d)
    }

    public HttpHeader get206 (String ifRange, HttpHeader header) {
  HttpHeader ret = new HttpHeader ();
  ret.setStatusLine ("HTTP/1.1 206 Partial Content");
  boolean tiny = ifRange != null;
  if (tiny) {
      String etag = header.getHeader ("ETag");
      if (etag != null && con.checkStrongEtag (ifRange, etag))
    tiny = false;
View Full Code Here

    /** Get a 304 Not Modified header for the given old header
     * @param oldresp the cached header.
     * @return a 304 HttpHeader .
     */
    public HttpHeader get304 (HttpHeader oldresp) {
  HttpHeader header = getHeader ("HTTP/1.1 304 Not Modified")
  copyHeaderIfExists ("Date", oldresp, header);
  copyHeaderIfExists ("Content-Location", oldresp, header);
  copyHeaderIfExists ("ETag", oldresp, header);
  String etag = header.getHeader ("Etag");
  if (etag != null && !con.isWeak (etag))
      copyHeaderIfExists ("Expires", oldresp, header);
  List<String> ccs = oldresp.getHeaders ("Cache-Control");
  for (int i = 0, s = ccs.size (); i < s; i++)
      header.addHeader ("Cache-Control", ccs.get (i));
  ccs = oldresp.getHeaders ("Vary");
  for (int i = 0, s = ccs.size (); i < s; i++)
      header.addHeader ("Vary", (String)ccs.get (i))
  return header;
    }
View Full Code Here

     * @param exception the Exception handled.
     * @return a HttpHeader for the exception.
     */
    public HttpHeader get400 (Exception exception) {
  // in most cases we should have a header out already, but to be sure...
  HttpHeader header = getHeader ("HTTP/1.1 400 Bad Request ")
  StringBuilder accreq =
      new StringBuilder (HtmlPage.getPageHeader (con, "400 Bad Request") +
             "Unable to handle request:<br><b><XMP>\n" +
             exception +
             "</XMP></b></body></html>\n");
  header.setContent (accreq.toString ());
  return header;
    }
View Full Code Here

    /** Get a 403 Forbidden header.
     * @return a HttpHeader.
     */
    public HttpHeader get403 () {
  // in most cases we should have a header out already, but to be sure...
  HttpHeader header = getHeader ("HTTP/1.1 403 Forbidden")
  StringBuilder accreq =
      new StringBuilder (HtmlPage.getPageHeader (con, "403 Forbidden") +
             "That is forbidden</body></html>");
  header.setContent (accreq.toString ());
  return header;
    }
View Full Code Here

    /** Get a 404 File not found.
     * @return a HttpHeader.
     */
    public HttpHeader get404 (String file) {
  // in most cases we should have a header out already, but to be sure...
  HttpHeader header = getHeader ("HTTP/1.1 404 File not found")
  StringBuilder accreq =
      new StringBuilder (HtmlPage.getPageHeader (con, "404 File not found") +
             "File '" + file + "' not found.</body></html>");
  header.setContent (accreq.toString ());
  return header;
    }
View Full Code Here

     * @param realm the realm that requires auth.
     * @param url the URL of the request made.
     * @return a suitable HttpHeader.
     */
    public HttpHeader get407 (String realm, URL url) {
  HttpHeader header =
      getHeader ("HTTP/1.1 407 Proxy Authentication Required");
  header.setHeader ("Proxy-Authenticate",
        "Basic realm=\"" + realm + "\"");
  String h407 = "407 Proxy Authentication Required";
  StringBuilder accreq =
      new StringBuilder (HtmlPage.getPageHeader (con, h407) +
             "access to: <b>" + url +
             " </b><br>requires some authentication\n" +
             "</body></html>\n");
  header.setContent (accreq.toString ());
  return header;
    }
View Full Code Here

TOP

Related Classes of rabbit.http.HttpHeader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.