package fitnesse.http;

import fitnesse.http.MockRequest;
import fitnesse.http.Request;

public class MockRequestBuilder {
  protected String specification;
  private boolean noChunk = false;

  public MockRequestBuilder(String specification) {
    this.specification = specification;
    validate();
  }

  public Request build() {
    MockRequest request = new MockRequest();
    request.parseRequestUri(getCommand());
    if (hasCredentials()) {
      request.setCredentials(getUsername(), getPassword());
    }
    if (noChunk) {
      request.addInput("noChunk", true);
    }
    return request;
  }

  private String getCommand() {
    String actualCommand = null;

    if (hasCredentials())
      actualCommand = commandParts()[2];
    else
      actualCommand = specification;


    if (actualCommand.startsWith("/"))
      return actualCommand;
    else
      return "/" + actualCommand;
  }

  private boolean hasCredentials() {
    return (commandParts().length == 3);
  }

  private boolean hasNoCredentials() {
    return (commandParts().length == 1);
  }

  private void validate() {
    if (!hasCredentials() && !hasNoCredentials())
      throw new IllegalArgumentException("Command specification [" + specification + "] invalid. Format shold be /cmd or user:pass:/cmd");
  }

  private String[] commandParts() {
    return specification.split(":");
  }

  private String getUsername() {
    return commandParts()[0];
  }

  private String getPassword() {
    return commandParts()[1];
  }

  public MockRequestBuilder noChunk() {
    this.noChunk = true;
    return this;
  }
}

package fitnesse.http;

public class MockRequestBuilder {
  protected String specification;
  private boolean noChunk = false;

  public MockRequestBuilder(String specification) {
    this.specification = specification;
    validate();
  }

  public Request build() {
    MockRequest request = new MockRequest();
    request.parseRequestUri(getCommand());
    if (hasCredentials()) {
      request.setCredentials(getUsername(), getPassword());
    }
    if (noChunk) {
      request.addInput("nochunk", true);
    }
    return request;
  }

  private String getCommand() {
    String actualCommand = null;

    if (hasCredentials())
      actualCommand = commandParts()[2];
    else
      actualCommand = specification;


    if (actualCommand.startsWith("/"))
      return actualCommand;
    else
      return "/" + actualCommand;
  }

  private boolean hasCredentials() {
    return (commandParts().length == 3);
  }

  private boolean hasNoCredentials() {
    return (commandParts().length == 1);
  }

  private void validate() {
    if (!hasCredentials() && !hasNoCredentials())
      throw new IllegalArgumentException("Command specification [" + specification + "] invalid. Format shold be /cmd or user:pass:/cmd");
  }

  private String[] commandParts() {
    return specification.split(":");
  }

  private String getUsername() {
    return commandParts()[0];
  }

  private String getPassword() {
    return commandParts()[1];
  }

  public MockRequestBuilder noChunk() {
    this.noChunk = true;
    return this;
  }
}

Fix issue with chunked reponse from command line execution.
Fix issue with chunked reponse from command line execution.
