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 io.netty.handler.codec.spdy;
17  
18  import io.netty.handler.codec.http.HttpHeaders;
19  import io.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   */
25  public final class SpdyHttpHeaders {
26  
27      /**
28       * SPDY HTTP header names
29       */
30      public static final class Names {
31          /**
32           * {@code "x-spdy-stream-id"}
33           */
34          public static final String STREAM_ID = "x-spdy-stream-id";
35          /**
36           * {@code "x-spdy-associated-to-stream-id"}
37           */
38          public static final String ASSOCIATED_TO_STREAM_ID = "x-spdy-associated-to-stream-id";
39          /**
40           * {@code "x-spdy-priority"}
41           */
42          public static final String PRIORITY = "x-spdy-priority";
43          /**
44           * {@code "x-spdy-scheme"}
45           */
46          public static final String SCHEME = "x-spdy-scheme";
47  
48          private Names() { }
49      }
50  
51      private SpdyHttpHeaders() {
52      }
53  
54      /**
55       * Removes the {@code "X-SPDY-Stream-ID"} header.
56       */
57      public static void removeStreamId(HttpMessage message) {
58          message.headers().remove(Names.STREAM_ID);
59      }
60  
61      /**
62       * Returns the value of the {@code "X-SPDY-Stream-ID"} header.
63       */
64      public static int getStreamId(HttpMessage message) {
65          return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
66      }
67  
68      /**
69       * Sets the {@code "X-SPDY-Stream-ID"} header.
70       */
71      public static void setStreamId(HttpMessage message, int streamId) {
72          HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamId);
73      }
74  
75      /**
76       * Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
77       */
78      public static void removeAssociatedToStreamId(HttpMessage message) {
79          message.headers().remove(Names.ASSOCIATED_TO_STREAM_ID);
80      }
81  
82      /**
83       * Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
84       *
85       * @return the header value or {@code 0} if there is no such header or
86       *         if the header value is not a number
87       */
88      public static int getAssociatedToStreamId(HttpMessage message) {
89          return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
90      }
91  
92      /**
93       * Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
94       */
95      public static void setAssociatedToStreamId(HttpMessage message, int associatedToStreamId) {
96          HttpHeaders.setIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
97      }
98  
99      /**
100      * Removes the {@code "X-SPDY-Priority"} header.
101      */
102     public static void removePriority(HttpMessage message) {
103         message.headers().remove(Names.PRIORITY);
104     }
105 
106     /**
107      * Returns the value of the {@code "X-SPDY-Priority"} header.
108      *
109      * @return the header value or {@code 0} if there is no such header or
110      *         if the header value is not a number
111      */
112     public static byte getPriority(HttpMessage message) {
113         return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
114     }
115 
116     /**
117      * Sets the {@code "X-SPDY-Priority"} header.
118      */
119     public static void setPriority(HttpMessage message, byte priority) {
120         HttpHeaders.setIntHeader(message, Names.PRIORITY, priority);
121     }
122 
123     /**
124      * Removes the {@code "X-SPDY-Scheme"} header.
125      */
126     public static void removeScheme(HttpMessage message) {
127         message.headers().remove(Names.SCHEME);
128     }
129 
130     /**
131      * Returns the value of the {@code "X-SPDY-Scheme"} header.
132      */
133     public static String getScheme(HttpMessage message) {
134         return message.headers().get(Names.SCHEME);
135     }
136 
137     /**
138      * Sets the {@code "X-SPDY-Scheme"} header.
139      */
140     public static void setScheme(HttpMessage message, String scheme) {
141         message.headers().set(Names.SCHEME, scheme);
142     }
143 }