// Path: core/src/main/java/com/squareup/rack/RackApplication.java
// public interface RackApplication {
//   /**
//    * Processes a single HTTP request.
//    *
//    * @param environment the HTTP request environment.
//    * @return the HTTP response.
//    */
//   RackResponse call(RackEnvironment environment);
// }
// 
// Path: core/src/main/java/com/squareup/rack/RackEnvironment.java
// public class RackEnvironment extends ForwardingMap<String, Object> {
//   public static final String REQUEST_METHOD = "REQUEST_METHOD";
//   public static final String SCRIPT_NAME = "SCRIPT_NAME";
//   public static final String PATH_INFO = "PATH_INFO";
//   public static final String QUERY_STRING = "QUERY_STRING";
//   public static final String SERVER_NAME = "SERVER_NAME";
//   public static final String SERVER_PORT = "SERVER_PORT";
//   public static final String CONTENT_LENGTH = "CONTENT_LENGTH";
//   public static final String CONTENT_TYPE = "CONTENT_TYPE";
//   public static final String HTTP_HEADER_PREFIX = "HTTP_";
//   public static final String RACK_VERSION = "rack.version";
//   public static final String RACK_URL_SCHEME = "rack.url_scheme";
//   public static final String RACK_INPUT = "rack.input";
//   public static final String RACK_ERRORS = "rack.errors";
//   public static final String RACK_LOGGER = "rack.logger";
//   public static final String RACK_MULTITHREAD = "rack.multithread";
//   public static final String RACK_MULTIPROCESS = "rack.multiprocess";
//   public static final String RACK_RUN_ONCE = "rack.run_once";
//   public static final String RACK_HIJACK = "rack.hijack?";
//   public static final String MINECART_HTTP_SERVLET_REQUEST = "minecart.http_servlet_request";
// 
//   private final Map<String, Object> contents;
// 
//   /**
//    * Creates a {@link RackEnvironment} with the given contents.
//    *
//    * @see com.squareup.rack.servlet.RackEnvironmentBuilder
//    * @param contents
//    */
//   public RackEnvironment(Map<String, Object> contents) {
//     this.contents = contents;
//   }
// 
//   /**
//    * Closes the rack.input stream.
//    *
//    * @throws IOException
//    */
//   public void closeRackInput() throws IOException {
//     ((Closeable) contents.get(RACK_INPUT)).close();
//   }
// 
//   @Override protected Map<String, Object> delegate() {
//     return contents;
//   }
// }
// 
// Path: core/src/main/java/com/squareup/rack/RackResponse.java
// public class RackResponse {
//   private final int status;
//   private final Map<String, String> headers;
//   private final Iterator<byte[]> body;
// 
//   /**
//    * Creates a {@link RackResponse} with the given contents.
//    *
//    * @param status the HTTP status code.
//    * @param headers the HTTP response headers.
//    * @param body the HTTP response body.
//    */
//   public RackResponse(int status, Map<String, String> headers, Iterator<byte[]> body) {
//     this.status = status;
//     this.headers = headers;
//     this.body = body;
//   }
// 
//   /**
//    * @return the HTTP status code.
//    */
//   public int getStatus() {
//     return status;
//   }
// 
//   /**
//    * @return the HTTP response headers.
//    */
//   public Map<String, String> getHeaders() {
//     return headers;
//   }
// 
//   /**
//    * @return the HTTP response body.
//    */
//   public Iterator<byte[]> getBody() {
//     return body;
//   }
// }


import com.squareup.rack.RackApplication;
import com.squareup.rack.RackEnvironment;
import com.squareup.rack.RackResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
 * Copyright (C) 2013 Square, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.squareup.rack.servlet;


/**
 * <p>Hosts a {@link RackApplication}.</p>
 *
 * <p>Since RackServlet lacks a zero-argument constructor, you'll need to manually instantiate and
 * install it in your container, rather than declaring it in a {@code web.xml} file. See our
 * examples for concrete code.</p>
 */
public class RackServlet extends HttpServlet {
  private final RackEnvironmentBuilder rackEnvironmentBuilder;
  private final RackApplication rackApplication;
  private final RackResponsePropagator rackResponsePropagator;

  /**
   * Creates a servlet hosting the given {@link RackApplication}.
   *
   * @param rackApplication the application to host.
   */
  public RackServlet(RackApplication rackApplication) {
    this(new RackEnvironmentBuilder(), rackApplication, new RackResponsePropagator());
  }

  /**
   * Creates a servlet hosting the given {@link RackApplication} and that uses the given
   * collaborators to translate between the Servlet and Rack environments.
   *
   * @param rackEnvironmentBuilder turns {@link HttpServletRequest}s into {@link RackEnvironment}s.
   * @param rackApplication the application to host.
   * @param rackResponsePropagator writes {@link RackResponse}s onto {@link HttpServletResponse}s.
   */
  public RackServlet(RackEnvironmentBuilder rackEnvironmentBuilder,
// Path: core/src/main/java/com/squareup/rack/RackApplication.java
// public interface RackApplication {
//   /**
//    * Processes a single HTTP request.
//    *
//    * @param environment the HTTP request environment.
//    * @return the HTTP response.
//    */
//   RackResponse call(RackEnvironment environment);
// }
// 
// Path: core/src/main/java/com/squareup/rack/RackEnvironment.java
// public class RackEnvironment extends ForwardingMap<String, Object> {
//   public static final String REQUEST_METHOD = "REQUEST_METHOD";
//   public static final String SCRIPT_NAME = "SCRIPT_NAME";
//   public static final String PATH_INFO = "PATH_INFO";
//   public static final String QUERY_STRING = "QUERY_STRING";
//   public static final String SERVER_NAME = "SERVER_NAME";
//   public static final String SERVER_PORT = "SERVER_PORT";
//   public static final String CONTENT_LENGTH = "CONTENT_LENGTH";
//   public static final String CONTENT_TYPE = "CONTENT_TYPE";
//   public static final String HTTP_HEADER_PREFIX = "HTTP_";
//   public static final String RACK_VERSION = "rack.version";
//   public static final String RACK_URL_SCHEME = "rack.url_scheme";
//   public static final String RACK_INPUT = "rack.input";
//   public static final String RACK_ERRORS = "rack.errors";
//   public static final String RACK_LOGGER = "rack.logger";
//   public static final String RACK_MULTITHREAD = "rack.multithread";
//   public static final String RACK_MULTIPROCESS = "rack.multiprocess";
//   public static final String RACK_RUN_ONCE = "rack.run_once";
//   public static final String RACK_HIJACK = "rack.hijack?";
//   public static final String MINECART_HTTP_SERVLET_REQUEST = "minecart.http_servlet_request";
// 
//   private final Map<String, Object> contents;
// 
//   /**
//    * Creates a {@link RackEnvironment} with the given contents.
//    *
//    * @see com.squareup.rack.servlet.RackEnvironmentBuilder
//    * @param contents
//    */
//   public RackEnvironment(Map<String, Object> contents) {
//     this.contents = contents;
//   }
// 
//   /**
//    * Closes the rack.input stream.
//    *
//    * @throws IOException
//    */
//   public void closeRackInput() throws IOException {
//     ((Closeable) contents.get(RACK_INPUT)).close();
//   }
// 
//   @Override protected Map<String, Object> delegate() {
//     return contents;
//   }
// }
// 
// Path: core/src/main/java/com/squareup/rack/RackResponse.java
// public class RackResponse {
//   private final int status;
//   private final Map<String, String> headers;
//   private final Iterator<byte[]> body;
// 
//   /**
//    * Creates a {@link RackResponse} with the given contents.
//    *
//    * @param status the HTTP status code.
//    * @param headers the HTTP response headers.
//    * @param body the HTTP response body.
//    */
//   public RackResponse(int status, Map<String, String> headers, Iterator<byte[]> body) {
//     this.status = status;
//     this.headers = headers;
//     this.body = body;
//   }
// 
//   /**
//    * @return the HTTP status code.
//    */
//   public int getStatus() {
//     return status;
//   }
// 
//   /**
//    * @return the HTTP response headers.
//    */
//   public Map<String, String> getHeaders() {
//     return headers;
//   }
// 
//   /**
//    * @return the HTTP response body.
//    */
//   public Iterator<byte[]> getBody() {
//     return body;
//   }
// }


// Path: core/src/main/java/com/squareup/rack/servlet/RackServlet.java
import com.squareup.rack.RackApplication;
import com.squareup.rack.RackEnvironment;
import com.squareup.rack.RackResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * Copyright (C) 2013 Square, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.squareup.rack.servlet;


/**
 * <p>Hosts a {@link RackApplication}.</p>
 *
 * <p>Since RackServlet lacks a zero-argument constructor, you'll need to manually instantiate and
 * install it in your container, rather than declaring it in a {@code web.xml} file. See our
 * examples for concrete code.</p>
 */
public class RackServlet extends HttpServlet {
  private final RackEnvironmentBuilder rackEnvironmentBuilder;
  private final RackApplication rackApplication;
  private final RackResponsePropagator rackResponsePropagator;

  /**
   * Creates a servlet hosting the given {@link RackApplication}.
   *
   * @param rackApplication the application to host.
   */
  public RackServlet(RackApplication rackApplication) {
    this(new RackEnvironmentBuilder(), rackApplication, new RackResponsePropagator());
  }

  /**
   * Creates a servlet hosting the given {@link RackApplication} and that uses the given
   * collaborators to translate between the Servlet and Rack environments.
   *
   * @param rackEnvironmentBuilder turns {@link HttpServletRequest}s into {@link RackEnvironment}s.
   * @param rackApplication the application to host.
   * @param rackResponsePropagator writes {@link RackResponse}s onto {@link HttpServletResponse}s.
   */
  public RackServlet(RackEnvironmentBuilder rackEnvironmentBuilder,
      RackApplication rackApplication,