View Javadoc

1   /*
2    * Copyright 2013 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       * Removes the {@code "X-SPDY-Stream-ID"} header.
63       */
64      public static void removeStreamId(HttpMessage message) {
65          message.headers().remove(Names.STREAM_ID);
66      }
67  
68      /**
69       * Returns the value of the {@code "X-SPDY-Stream-ID"} header.
70       */
71      public static int getStreamId(HttpMessage message) {
72          return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
73      }
74  
75      /**
76       * Sets the {@code "X-SPDY-Stream-ID"} header.
77       */
78      public static void setStreamId(HttpMessage message, int streamId) {
79          HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamId);
80      }
81  
82      /**
83       * Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
84       */
85      public static void removeAssociatedToStreamId(HttpMessage message) {
86          message.headers().remove(Names.ASSOCIATED_TO_STREAM_ID);
87      }
88  
89      /**
90       * Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
91       *
92       * @return the header value or {@code 0} if there is no such header or
93       *         if the header value is not a number
94       */
95      public static int getAssociatedToStreamId(HttpMessage message) {
96          return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
97      }
98  
99      /**
100      * Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
101      */
102     public static void setAssociatedToStreamId(HttpMessage message, int associatedToStreamId) {
103         HttpHeaders.setIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
104     }
105 
106     /**
107      * Removes the {@code "X-SPDY-Priority"} header.
108      */
109     public static void removePriority(HttpMessage message) {
110         message.headers().remove(Names.PRIORITY);
111     }
112 
113     /**
114      * Returns the value of the {@code "X-SPDY-Priority"} header.
115      *
116      * @return the header value or {@code 0} if there is no such header or
117      *         if the header value is not a number
118      */
119     public static byte getPriority(HttpMessage message) {
120         return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
121     }
122 
123     /**
124      * Sets the {@code "X-SPDY-Priority"} header.
125      */
126     public static void setPriority(HttpMessage message, byte priority) {
127         HttpHeaders.setIntHeader(message, Names.PRIORITY, priority);
128     }
129 
130     /**
131      * Removes the {@code "X-SPDY-URL"} header.
132      */
133     public static void removeUrl(HttpMessage message) {
134         message.headers().remove(Names.URL);
135     }
136 
137     /**
138      * Returns the value of the {@code "X-SPDY-URL"} header.
139      */
140     public static String getUrl(HttpMessage message) {
141         return message.headers().get(Names.URL);
142     }
143 
144     /**
145      * Sets the {@code "X-SPDY-URL"} header.
146      */
147     public static void setUrl(HttpMessage message, String url) {
148         message.headers().set(Names.URL, url);
149     }
150 
151     /**
152      * Removes the {@code "X-SPDY-Scheme"} header.
153      */
154     public static void removeScheme(HttpMessage message) {
155         message.headers().remove(Names.SCHEME);
156     }
157 
158     /**
159      * Returns the value of the {@code "X-SPDY-Scheme"} header.
160      */
161     public static String getScheme(HttpMessage message) {
162         return message.headers().get(Names.SCHEME);
163     }
164 
165     /**
166      * Sets the {@code "X-SPDY-Scheme"} header.
167      */
168     public static void setScheme(HttpMessage message, String scheme) {
169         message.headers().set(Names.SCHEME, scheme);
170     }
171 }