// Path: commons/src/main/java/org/nesty/commons/constant/http/HttpConstants.java
// public class HttpConstants {
// 
//     public static final String HEADER_X_FORWARDED_FOR = "X-Forwarded-For";
//     public static final String HEADER_CONTENT_LENGTH = "Content-Length";
//     public static final String HEADER_CONTENT_TYPE = "Content-Type";
//     public static final String HEADER_CONNECTION = "Connection";
// 
//     public static final String HEADER_SERVER = "Server";
//     public static final String HEADER_REQUEST_ID = "Request-Id";
//     public static final String HEADER_CONNECTION_KEEPALIVE = "keep-alive";
//     public static final String HEADER_CONNECTION_CLOSE = "close";
//     public static final String HEADER_CONTENT_TYPE_TEXT = "application/text";
//     public static final String HEADER_CONTENT_TYPE_JSON = "application/json";
// }
// 
// Path: commons/src/main/java/org/nesty/commons/constant/http/RequestMethod.java
// public enum RequestMethod {
//     GET, POST, PUT, DELETE, UNKOWN
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/request/HttpRequestVisitor.java
// public interface HttpRequestVisitor {
//     String visitRemoteAddress();
// 
//     String visitURI();
// 
//     String[] visitTerms();
// 
//     RequestMethod visitHttpMethod();
// 
//     String visitHttpBody();
// 
//     Map<String, String> visitHttpParams();
// 
//     Map<String, String> visitHttpHeaders();
// 
//     HttpVersion visitHttpVersion();
// }


import io.netty.handler.codec.http.HttpVersion;
import org.nesty.commons.constant.http.HttpConstants;
import org.nesty.commons.constant.http.RequestMethod;
import org.nesty.core.server.rest.request.HttpRequestVisitor;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
package org.nesty.core.server.rest;



/**
 * http context. include all http request and response information
 *
 * Author Michael on 03/03/2016.
 */
public class HttpContext extends HttpSession {
    private static String NestyUID = UUID.randomUUID().toString();
    private static AtomicLong SequenceId = new AtomicLong(0);

    // raw body
    protected String httpBody;
    // params include query string and body param
    protected Map<String, String> httpParams;
    // attribute map values
    protected Map<String, Object> httpAttributes;
    // header values
    protected Map<String, String> httpHeaders;
    // client request with unique id, fetch it from http header(Request-Id)
    // if exsit. or generate by UUID
    private String requestId = String.format("%s-%d", NestyUID, SequenceId.incrementAndGet());
    // ip address from origin client, fetch it from getRemoteAddr()
    // or header X-FORWARDED-FOR
    private String remoteAddress;
    //  raw uri exclude query string
    private String uri;
    // http uri terms split by "/"
    private String[] terms;
    // Http request method. NOT null
// Path: commons/src/main/java/org/nesty/commons/constant/http/HttpConstants.java
// public class HttpConstants {
// 
//     public static final String HEADER_X_FORWARDED_FOR = "X-Forwarded-For";
//     public static final String HEADER_CONTENT_LENGTH = "Content-Length";
//     public static final String HEADER_CONTENT_TYPE = "Content-Type";
//     public static final String HEADER_CONNECTION = "Connection";
// 
//     public static final String HEADER_SERVER = "Server";
//     public static final String HEADER_REQUEST_ID = "Request-Id";
//     public static final String HEADER_CONNECTION_KEEPALIVE = "keep-alive";
//     public static final String HEADER_CONNECTION_CLOSE = "close";
//     public static final String HEADER_CONTENT_TYPE_TEXT = "application/text";
//     public static final String HEADER_CONTENT_TYPE_JSON = "application/json";
// }
// 
// Path: commons/src/main/java/org/nesty/commons/constant/http/RequestMethod.java
// public enum RequestMethod {
//     GET, POST, PUT, DELETE, UNKOWN
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/request/HttpRequestVisitor.java
// public interface HttpRequestVisitor {
//     String visitRemoteAddress();
// 
//     String visitURI();
// 
//     String[] visitTerms();
// 
//     RequestMethod visitHttpMethod();
// 
//     String visitHttpBody();
// 
//     Map<String, String> visitHttpParams();
// 
//     Map<String, String> visitHttpHeaders();
// 
//     HttpVersion visitHttpVersion();
// }


// Path: core/src/main/java/org/nesty/core/server/rest/HttpContext.java
import io.netty.handler.codec.http.HttpVersion;
import org.nesty.commons.constant.http.HttpConstants;
import org.nesty.commons.constant.http.RequestMethod;
import org.nesty.core.server.rest.request.HttpRequestVisitor;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

package org.nesty.core.server.rest;



/**
 * http context. include all http request and response information
 *
 * Author Michael on 03/03/2016.
 */
public class HttpContext extends HttpSession {
    private static String NestyUID = UUID.randomUUID().toString();
    private static AtomicLong SequenceId = new AtomicLong(0);

    // raw body
    protected String httpBody;
    // params include query string and body param
    protected Map<String, String> httpParams;
    // attribute map values
    protected Map<String, Object> httpAttributes;
    // header values
    protected Map<String, String> httpHeaders;
    // client request with unique id, fetch it from http header(Request-Id)
    // if exsit. or generate by UUID
    private String requestId = String.format("%s-%d", NestyUID, SequenceId.incrementAndGet());
    // ip address from origin client, fetch it from getRemoteAddr()
    // or header X-FORWARDED-FOR
    private String remoteAddress;
    //  raw uri exclude query string
    private String uri;
    // http uri terms split by "/"
    private String[] terms;
    // Http request method. NOT null
    private RequestMethod requestMethod;