001/*
002 * This file is part of the JDrupes non-blocking HTTP Codec
003 * Copyright (C) 2016, 2017  Michael N. Lipp
004 *
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Lesser General Public License as published
007 * by the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
013 * License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.httpcodec.protocols.http;
020
021import java.util.regex.Pattern;
022
023/**
024 * Common HTTP constants.
025 */
026public interface HttpConstants {
027
028    public static enum HttpProtocol { 
029        HTTP_1_0("HTTP/1.0"), HTTP_1_1("HTTP/1.1");
030        
031        private String repr;
032        
033        HttpProtocol(String repr) {
034                this.repr = repr;
035        }
036
037        @Override
038                public String toString() {
039                        return repr;
040                }
041    }
042
043    public static enum HttpStatus {
044        CONTINUE(100, "Continue"),
045        SWITCHING_PROTOCOLS(101, "Switching Protocols"),
046        OK(200, "OK"),
047        CREATED(201, "Created"),
048        ACCEPTED(202, "Accepted"),
049        NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
050        NO_CONTENT(204, "No Content"),
051        RESET_CONTENT(205, "Reset Content"),
052        PARTIAL_CONTENT(206, "Partial Content"),
053        MULTIPLE_CHOICES(300, "Multiple Choices"),
054        MOVED_PERMANENTLY(301, "Moved Permanently"),
055        FOUND(302, "Found"),
056        SEE_OTHER(303, "See Other"),
057        NOT_MODIFIED(304, "Not Modified"),
058        USE_PROXY(305, "Use Proxy"),
059        TEMPORARY_REDIRECT(307, "Temporary Redirect"),
060        BAD_REQUEST(400, "Bad Request"),
061        UNAUTHORIZED(401, "Unauthorized"),
062        PAYMENT_REQUIRED(402, "Payment Required"),
063        FORBIDDEN(403, "Forbidden"),
064        NOT_FOUND(404, "Not Found"),
065        METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
066        NOT_ACCEPTABLE(406, "Not Acceptable"),
067        PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
068        REQUEST_TIME_OUT(408, "Request Time-out"),
069        CONFLICT(409, "Conflict"),
070        GONE(410, "Gone"),
071        LENGTH_REQUIRED(411, "Length Required"),
072        PRECONDITION_FAILED(412, "Precondition Failed"),
073        REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
074        REQUEST_URI_TOO_LARGE(414, "Request-URI Too Large"),
075        UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
076        REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
077        EXPECTATION_FAILED(417, "Expectation Failed"),
078        INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
079        NOT_IMPLEMENTED(501, "Not Implemented"),
080        BAD_GATEWAY(502, "Bad Gateway"),
081        SERVICE_UNAVAILABLE(503, "Service Unavailable"),
082        GATEWAY_TIME_OUT(504, "Gateway Time-out"),
083        HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported");
084        
085        private int statusCode;
086        private String reasonPhrase;
087        
088        HttpStatus(int statusCode, String reasonPhrase) {
089                this.statusCode = statusCode;
090                this.reasonPhrase = reasonPhrase;
091        }
092        
093                /**
094                 * @return the status code
095                 */
096                public int statusCode() {
097                        return statusCode;
098                }
099
100                /**
101                 * @return the reason phrase
102                 */
103                public String reasonPhrase() {
104                        return reasonPhrase;
105                }
106    }
107    
108    public enum TransferCoding { CHUNKED("chunked"), COMPRESS("compress"),
109        DEFLATE("deflate"), GZIP("gzip");
110        
111        private String repr;
112        
113        TransferCoding(String repr) {
114                this.repr = repr;
115        }
116
117        @Override
118                public String toString() {
119                        return repr;
120                }
121    }
122
123        public static final String TOKEN_CHARS 
124                = "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
125                        + "^`abcdefghijklmnopqrstuvwxyz|~";
126
127        public static final String TOKEN68_CHARS 
128                = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
129                        + "abcdefghijklmnopqrstuvwxyz-._~+/=";
130
131        public static final String TOKEN_REGEXP 
132                = "[" + Pattern.quote(TOKEN_CHARS) + "]+";
133
134        public static final String TOKEN68_REGEXP 
135                = "[" + Pattern.quote(TOKEN68_CHARS) + "]+";
136}