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