View Javadoc

1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package org.jboss.netty.handler.codec.spdy;
17  
18  import org.jboss.netty.handler.codec.http.HttpHeaders;
19  import org.jboss.netty.handler.codec.http.HttpMessage;
20  
21  /**
22   * Provides the constants for the header names and the utility methods
23   * used by the {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}.
24   * @apiviz.stereotype static
25   */
26  public final class SpdyHttpHeaders {
27  
28      /**
29       * SPDY HTTP header names
30       * @apiviz.stereotype static
31       */
32      public static final class Names {
33          /**
34           * {@code "X-SPDY-Stream-ID"}
35           */
36          public static final String STREAM_ID = "X-SPDY-Stream-ID";
37          /**
38           * {@code "X-SPDY-Associated-To-Stream-ID"}
39           */
40          public static final String ASSOCIATED_TO_STREAM_ID = "X-SPDY-Associated-To-Stream-ID";
41          /**
42           * {@code "X-SPDY-Priority"}
43           */
44          public static final String PRIORITY = "X-SPDY-Priority";
45          /**
46           * {@code "X-SPDY-URL"}
47           */
48          public static final String URL = "X-SPDY-URL";
49          /**
50           * {@code "X-SPDY-Scheme"}
51           */
52          public static final String SCHEME = "X-SPDY-Scheme";
53  
54          private Names() {
55          }
56      }
57  
58      private SpdyHttpHeaders() {
59      }
60  
61      /**
62       * @deprecated Use {@link #removeStreamId(HttpMessage)} instead.
63       */
64      @Deprecated
65      public static void removeStreamID(HttpMessage message) {
66          removeStreamId(message);
67      }
68  
69      /**
70       * Removes the {@code "X-SPDY-Stream-ID"} header.
71       */
72      public static void removeStreamId(HttpMessage message) {
73          message.removeHeader(Names.STREAM_ID);
74      }
75  
76      /**
77       * @deprecated Use {@link #getStreamId(HttpMessage)} instead.
78       */
79      @Deprecated
80      public static int getStreamID(HttpMessage message) {
81          return getStreamId(message);
82      }
83  
84      /**
85       * Returns the value of the {@code "X-SPDY-Stream-ID"} header.
86       */
87      public static int getStreamId(HttpMessage message) {
88          return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
89      }
90  
91      /**
92       * @deprecated Use {@link #setStreamId(HttpMessage, int)} instead.
93       */
94      @Deprecated
95      public static void setStreamID(HttpMessage message, int streamId) {
96          setStreamId(message, streamId);
97      }
98  
99      /**
100      * Sets the {@code "X-SPDY-Stream-ID"} header.
101      */
102     public static void setStreamId(HttpMessage message, int streamId) {
103         HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamId);
104     }
105 
106     /**
107      * @deprecated Use {@link #removeAssociatedToStreamId(HttpMessage)} instead.
108      */
109     @Deprecated
110     public static void removeAssociatedToStreamID(HttpMessage message) {
111         removeAssociatedToStreamId(message);
112     }
113 
114     /**
115      * Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
116      */
117     public static void removeAssociatedToStreamId(HttpMessage message) {
118         message.removeHeader(Names.ASSOCIATED_TO_STREAM_ID);
119     }
120 
121     /**
122      * @deprecated Use {@link #getAssociatedToStreamId(HttpMessage)} instead.
123      */
124     @Deprecated
125     public static int getAssociatedToStreamID(HttpMessage message) {
126         return getAssociatedToStreamId(message);
127     }
128 
129     /**
130      * Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
131      *
132      * @return the header value or {@code 0} if there is no such header or
133      *         if the header value is not a number
134      */
135     public static int getAssociatedToStreamId(HttpMessage message) {
136         return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
137     }
138 
139     /**
140      * @deprecated Use {@link #setAssociatedToStreamId(HttpMessage, int)} instead.
141      */
142     @Deprecated
143     public static void setAssociatedToStreamID(HttpMessage message, int associatedToStreamId) {
144         setAssociatedToStreamId(message, associatedToStreamId);
145     }
146 
147     /**
148      * Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
149      */
150     public static void setAssociatedToStreamId(HttpMessage message, int associatedToStreamId) {
151         HttpHeaders.setIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
152     }
153 
154     /**
155      * Removes the {@code "X-SPDY-Priority"} header.
156      */
157     public static void removePriority(HttpMessage message) {
158         message.removeHeader(Names.PRIORITY);
159     }
160 
161     /**
162      * Returns the value of the {@code "X-SPDY-Priority"} header.
163      *
164      * @return the header value or {@code 0} if there is no such header or
165      *         if the header value is not a number
166      */
167     public static byte getPriority(HttpMessage message) {
168         return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
169     }
170 
171     /**
172      * Sets the {@code "X-SPDY-Priority"} header.
173      */
174     public static void setPriority(HttpMessage message, byte priority) {
175         HttpHeaders.setIntHeader(message, Names.PRIORITY, priority);
176     }
177 
178     /**
179      * Removes the {@code "X-SPDY-URL"} header.
180      */
181     public static void removeUrl(HttpMessage message) {
182         message.removeHeader(Names.URL);
183     }
184 
185     /**
186      * Returns the value of the {@code "X-SPDY-URL"} header.
187      */
188     public static String getUrl(HttpMessage message) {
189         return message.getHeader(Names.URL);
190     }
191 
192     /**
193      * Sets the {@code "X-SPDY-URL"} header.
194      */
195     public static void setUrl(HttpMessage message, String url) {
196         message.setHeader(Names.URL, url);
197     }
198 
199     /**
200      * Removes the {@code "X-SPDY-Scheme"} header.
201      */
202     public static void removeScheme(HttpMessage message) {
203         message.removeHeader(Names.SCHEME);
204     }
205 
206     /**
207      * Returns the value of the {@code "X-SPDY-Scheme"} header.
208      */
209     public static String getScheme(HttpMessage message) {
210         return message.getHeader(Names.SCHEME);
211     }
212 
213     /**
214      * Sets the {@code "X-SPDY-Scheme"} header.
215      */
216     public static void setScheme(HttpMessage message, String scheme) {
217         message.setHeader(Names.SCHEME, scheme);
218     }
219 }