View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package com.foxinmy.weixin4j.http;
29  
30  import java.nio.charset.Charset;
31  
32  import org.apache.http.Consts;
33  
34  /**
35   * Constants and static helpers related to the HTTP protocol.
36   *
37   * @since 4.0
38   */
39  public final class HTTP {
40  
41      public static final int CR = 13; // <US-ASCII CR, carriage return (13)>
42      public static final int LF = 10; // <US-ASCII LF, linefeed (10)>
43      public static final int SP = 32; // <US-ASCII SP, space (32)>
44      public static final int HT = 9;  // <US-ASCII HT, horizontal-tab (9)>
45  
46      /** HTTP header definitions */
47      public static final String TRANSFER_ENCODING = "Transfer-Encoding";
48      public static final String CONTENT_LEN  = "Content-Length";
49      public static final String CONTENT_TYPE = "Content-Type";
50      public static final String CONTENT_ENCODING = "Content-Encoding";
51      public static final String EXPECT_DIRECTIVE = "Expect";
52      public static final String CONN_DIRECTIVE = "Connection";
53      public static final String TARGET_HOST = "Host";
54      public static final String USER_AGENT = "User-Agent";
55      public static final String DATE_HEADER = "Date";
56      public static final String SERVER_HEADER = "Server";
57  
58      /** HTTP expectations */
59      public static final String EXPECT_CONTINUE = "100-continue";
60  
61      /** HTTP connection control */
62      public static final String CONN_CLOSE = "Close";
63      public static final String CONN_KEEP_ALIVE = "Keep-Alive";
64  
65      /** Transfer encoding definitions */
66      public static final String CHUNK_CODING = "chunked";
67      public static final String IDENTITY_CODING = "identity";
68  
69      public static final Charset DEF_CONTENT_CHARSET = Consts.ISO_8859_1;
70      public static final Charset DEF_PROTOCOL_CHARSET = Consts.ASCII;
71  
72      /**
73       */
74      public static final String UTF_8 = "UTF-8";
75  
76      /**
77       */
78      public static final String UTF_16 = "UTF-16";
79  
80      /**
81       */
82      public static final String US_ASCII = "US-ASCII";
83  
84      /**
85       */
86      public static final String ASCII = "ASCII";
87      /**
88       */
89      public static final String DEFAULT_CONTENT_CHARSET = UTF_8;
90  
91      /**
92       */
93      public static final String DEFAULT_PROTOCOL_CHARSET = US_ASCII;
94  
95      /**
96       */
97      public final static String OCTET_STREAM_TYPE = "application/octet-stream";
98  
99      /**
100      */
101     public final static String PLAIN_TEXT_TYPE = "text/plain";
102 
103     /**
104      */
105     public final static String CHARSET_PARAM = "; charset=";
106 
107     /**
108      */
109     public final static String DEFAULT_CONTENT_TYPE = OCTET_STREAM_TYPE;
110 
111     public static boolean isWhitespace(final char ch) {
112         return ch == SP || ch == HT || ch == CR || ch == LF;
113     }
114 
115     private HTTP() {
116     }
117 }