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              super();
    56          }
    57      }
    58
    59      private SpdyHttpHeaders() {
    60      }
    61
    62      /**
    63       * @deprecated Use {@link #removeStreamId(HttpMessage)} instead.
    64       */
    65      @Deprecated
    66      public static void removeStreamID(HttpMessage message) {
    67          removeStreamId(message);
    68      }
    69
    70      /**
    71       * Removes the {@code "X-SPDY-Stream-ID"} header.
    72       */
    73      public static void removeStreamId(HttpMessage message) {
    74          message.removeHeader(Names.STREAM_ID);
    75      }
    76
    77      /**
    78       * @deprecated Use {@link #getStreamId(HttpMessage)} instead.
    79       */
    80      @Deprecated
    81      public static int getStreamID(HttpMessage message) {
    82          return getStreamId(message);
    83      }
    84
    85      /**
    86       * Returns the value of the {@code "X-SPDY-Stream-ID"} header.
    87       */
    88      public static int getStreamId(HttpMessage message) {
    89          return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
    90      }
    91
    92      /**
    93       * @deprecated Use {@link #setStreamId(HttpMessage, int)} instead.
    94       */
    95      @Deprecated
    96      public static void setStreamID(HttpMessage message, int streamId) {
    97          setStreamId(message, streamId);
    98      }
    99
    100     /**
    101      * Sets the {@code "X-SPDY-Stream-ID"} header.
    102      */
    103     public static void setStreamId(HttpMessage message, int streamId) {
    104         HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamId);
    105     }
    106
    107     /**
    108      * @deprecated Use {@link #removeAssociatedToStreamId(HttpMessage)} instead.
    109      */
    110     @Deprecated
    111     public static void removeAssociatedToStreamID(HttpMessage message) {
    112         removeAssociatedToStreamId(message);
    113     }
    114
    115     /**
    116      * Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
    117      */
    118     public static void removeAssociatedToStreamId(HttpMessage message) {
    119         message.removeHeader(Names.ASSOCIATED_TO_STREAM_ID);
    120     }
    121
    122     /**
    123      * @deprecated Use {@link #getAssociatedToStreamId(HttpMessage)} instead.
    124      */
    125     @Deprecated
    126     public static int getAssociatedToStreamID(HttpMessage message) {
    127         return getAssociatedToStreamId(message);
    128     }
    129
    130     /**
    131      * Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
    132      *
    133      * @return the header value or {@code 0} if there is no such header or
    134      *         if the header value is not a number
    135      */
    136     public static int getAssociatedToStreamId(HttpMessage message) {
    137         return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
    138     }
    139
    140     /**
    141      * @deprecated Use {@link #setAssociatedToStreamId(HttpMessage, int)} instead.
    142      */
    143     @Deprecated
    144     public static void setAssociatedToStreamID(HttpMessage message, int associatedToStreamId) {
    145         setAssociatedToStreamId(message, associatedToStreamId);
    146     }
    147
    148     /**
    149      * Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
    150      */
    151     public static void setAssociatedToStreamId(HttpMessage message, int associatedToStreamId) {
    152         HttpHeaders.setIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
    153     }
    154
    155     /**
    156      * Removes the {@code "X-SPDY-Priority"} header.
    157      */
    158     public static void removePriority(HttpMessage message) {
    159         message.removeHeader(Names.PRIORITY);
    160     }
    161
    162     /**
    163      * Returns the value of the {@code "X-SPDY-Priority"} header.
    164      *
    165      * @return the header value or {@code 0} if there is no such header or
    166      *         if the header value is not a number
    167      */
    168     public static byte getPriority(HttpMessage message) {
    169         return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
    170     }
    171
    172     /**
    173      * Sets the {@code "X-SPDY-Priority"} header.
    174      */
    175     public static void setPriority(HttpMessage message, byte priority) {
    176         HttpHeaders.setIntHeader(message, Names.PRIORITY, priority);
    177     }
    178
    179     /**
    180      * Removes the {@code "X-SPDY-URL"} header.
    181      */
    182     public static void removeUrl(HttpMessage message) {
    183         message.removeHeader(Names.URL);
    184     }
    185
    186     /**
    187      * Returns the value of the {@code "X-SPDY-URL"} header.
    188      */
    189     public static String getUrl(HttpMessage message) {
    190         return message.getHeader(Names.URL);
    191     }
    192
    193     /**
    194      * Sets the {@code "X-SPDY-URL"} header.
    195      */
    196     public static void setUrl(HttpMessage message, String url) {
    197         message.setHeader(Names.URL, url);
    198     }
    199
    200     /**
    201      * Removes the {@code "X-SPDY-Scheme"} header.
    202      */
    203     public static void removeScheme(HttpMessage message) {
    204         message.removeHeader(Names.SCHEME);
    205     }
    206
    207     /**
    208      * Returns the value of the {@code "X-SPDY-Scheme"} header.
    209      */
    210     public static String getScheme(HttpMessage message) {
    211         return message.getHeader(Names.SCHEME);
    212     }
    213
    214     /**
    215      * Sets the {@code "X-SPDY-Scheme"} header.
    216      */
    217     public static void setScheme(HttpMessage message, String scheme) {
    218         message.setHeader(Names.SCHEME, scheme);
    219     }
    220 }