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 org.apache.hc.core5.http.protocol;
29  
30  import org.apache.hc.core5.http.ProtocolVersion;
31  
32  /**
33   * HttpContext represents execution state of an HTTP process. It is a structure
34   * that can be used to map an attribute name to an attribute value.
35   * </p>
36   * <p>
37   * The primary purpose of the HTTP context is to facilitate information sharing
38   * among various  logically related components. HTTP context can be used
39   * to store a processing state for one message or several consecutive messages.
40   * Multiple logically related messages can participate in a logical session
41   * if the same context is reused between consecutive messages.
42   * </p>
43   * <p>
44   * IMPORTANT: Please note HTTP context implementation, even when thread safe,
45   * may not be used concurrently by multiple threads, as the context may contain
46   * thread unsafe attributes.
47   * </p>
48   *
49   * @since 4.0
50   */
51  public interface HttpContext {
52  
53      /** The prefix reserved for use by HTTP components. "http." */
54      public static final String RESERVED_PREFIX  = "http.";
55  
56      /**
57       * Returns protocol version used in this context.
58       *
59       * @since 5.0
60       */
61      ProtocolVersion getProtocolVersion();
62  
63      /**
64       * Sets protocol version used in this context.
65       *
66       * @since 5.0
67       */
68      void setProtocolVersion(ProtocolVersion version);
69  
70      /**
71       * Obtains attribute with the given name.
72       *
73       * @param id the attribute name.
74       * @return attribute value, or {@code null} if not set.
75       */
76      Object getAttribute(String id);
77  
78      /**
79       * Sets value of the attribute with the given name.
80       *
81       * @param id the attribute name.
82       * @param obj the attribute value.
83       */
84      void setAttribute(String id, Object obj);
85  
86      /**
87       * Removes attribute with the given name from the context.
88       *
89       * @param id the attribute name.
90       * @return attribute value, or {@code null} if not set.
91       */
92      Object removeAttribute(String id);
93  
94  }