Package tkuri.jxy.server

Source Code of tkuri.jxy.server.OriginResponse

package tkuri.jxy.server;

import tkuri.jxy.Const;
import tkuri.jxy.Util;
import tkuri.jxy.arch.GeneralHeaderInfo;
import tkuri.jxy.arch.HeaderList;
import tkuri.jxy.arch.HeaderReader;
import tkuri.uty.Bs;


/**
*
*/
public class OriginResponse {

  public OriginPeer peer;
  public Bs statusLine = Bs.BLANK;
  public HeaderList headerList = new HeaderList();
  public GeneralHeaderInfo headerInfo = null;

  private HeaderReader headerReader_ = null;
  private boolean isReqHead_ = false; // リクエストメソッドはHEADか?

  private String debugStr_ = "";

  public OriginResponse(OriginPeer aPeer, boolean aIsReqHead, String aDebugStr) {

    peer = aPeer;
    isReqHead_ = aIsReqHead;
    headerReader_ = new HeaderReader(peer.reader);
    debugStr_ = aDebugStr;
  }


  public boolean getReady() {

    if (headerInfo != null) {
      return true;
    }

    statusLine = headerReader_.queryFirstLine();
    if (statusLine == null) {
      return false;
    }

    Util.say("response stat: ", statusLine.trim(), " from ", debugStr_);

    for (Bs line: headerReader_) {
      //Util.say("org res: ", line.trim());
      headerList.addLine(line);
    }

    boolean aDefConnClose = ! statusLine.startsWith("HTTP/1.1");
    headerInfo = new GeneralHeaderInfo(headerList, aDefConnClose);

    if (isReqHead_ || _isStatusCode(Const.S_204, Const.S_205, Const.S_304)) {
      headerInfo.hasMessageBody = false;
    } else {
      headerInfo.hasMessageBody = true;
    }

    return true;
  }


  private boolean _isStatusCode(Bs...aBs) {

    for (Bs b: aBs) {
      if (statusLine.isSeq(9, b)) {
        return true;
      }
    }

    return false;
  }
}
TOP

Related Classes of tkuri.jxy.server.OriginResponse

TOP
Copyright © 2018 www.massapi.com. 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.