jdk/src/java.httpclient/share/classes/java/net/http/Http2Frame.java
author michaelm
Sat, 30 Apr 2016 00:30:31 +0100
changeset 37720 45cd7cc65382
child 39730 196f4e25d9f5
permissions -rw-r--r--
8087124: HTTP/2 implementation Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     1
/*
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     4
 *
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    10
 *
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    15
 * accompanied this code).
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    16
 *
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    20
 *
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    23
 */
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    24
package java.net.http;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    25
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    26
import java.io.IOException;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    27
import java.nio.ByteBuffer;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    28
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    29
/**
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    30
 * When sending a frame, the length field must be set in sub-class
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    31
 * by calling computeLength()
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    32
 */
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    33
abstract class Http2Frame {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    34
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    35
    int length = -1;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    36
    int type;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    37
    int streamid;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    38
    int flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    39
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    40
    // called when reading in only
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    41
    void initCommon(int length, int type, int streamid, int flags) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    42
        this.length = length;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    43
        this.type = type;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    44
        this.streamid = streamid;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    45
        this.flags = flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    46
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    47
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    48
    public int length() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    49
        return length;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    50
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    51
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    52
    public int type() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    53
        return type;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    54
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    55
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    56
    public int streamid() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    57
        return streamid;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    58
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    59
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    60
    public void setFlag(int flag) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    61
        flags |= flag;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    62
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    63
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    64
    public void setFlags(int flags) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    65
        this.flags = flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    66
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    67
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    68
    public int getFlags() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    69
        return flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    70
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    71
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    72
    public boolean getFlag(int flag) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    73
        return (flags & flag) != 0;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    74
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    75
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    76
    public void clearFlag(int flag) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    77
        flags &= 0xffffffff ^ flag;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    78
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    79
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    80
    public void streamid(int streamid) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    81
        this.streamid = streamid;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    82
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    83
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    84
    abstract void readIncomingImpl(ByteBufferConsumer bc) throws IOException;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    85
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    86
    /**
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    87
     * assume given array contains at least one complete frame.
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    88
     */
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    89
    static Http2Frame readIncoming(ByteBufferConsumer bc) throws IOException {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    90
        int x = bc.getInt();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    91
        int length = x >> 8;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    92
        int type = x & 0xff;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    93
        int flags = bc.getByte();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    94
        int streamid = bc.getInt();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    95
        Http2Frame f = null;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    96
        switch (type) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    97
          case DataFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    98
            f = new DataFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
    99
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   100
          case HeadersFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   101
            f = new HeadersFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   102
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   103
          case ContinuationFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   104
            f = new ContinuationFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   105
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   106
          case ResetFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   107
            f = new ResetFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   108
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   109
          case PriorityFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   110
            f = new PriorityFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   111
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   112
          case SettingsFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   113
            f = new SettingsFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   114
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   115
          case GoAwayFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   116
            f = new GoAwayFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   117
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   118
          case PingFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   119
            f = new PingFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   120
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   121
          case PushPromiseFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   122
            f = new PushPromiseFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   123
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   124
          case WindowUpdateFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   125
            f = new WindowUpdateFrame();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   126
            break;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   127
          default:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   128
            String msg = Integer.toString(type);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   129
            throw new IOException("unknown frame type " + msg);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   130
        }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   131
        f.initCommon(length, type, streamid, flags);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   132
        f.readIncomingImpl(bc);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   133
        return f;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   134
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   135
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   136
    public String typeAsString() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   137
        return asString(this.type);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   138
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   139
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   140
    public static String asString(int type) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   141
        switch (type) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   142
          case DataFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   143
            return "DATA";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   144
          case HeadersFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   145
            return "HEADERS";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   146
          case ContinuationFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   147
            return "CONTINUATION";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   148
          case ResetFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   149
            return "RESET";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   150
          case PriorityFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   151
            return "PRIORITY";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   152
          case SettingsFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   153
            return "SETTINGS";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   154
          case GoAwayFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   155
            return "GOAWAY";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   156
          case PingFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   157
            return "PING";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   158
          case PushPromiseFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   159
            return "PUSH_PROMISE";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   160
          case WindowUpdateFrame.TYPE:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   161
            return "WINDOW_UPDATE";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   162
          default:
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   163
            return "UNKNOWN";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   164
        }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   165
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   166
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   167
    @Override
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   168
    public String toString() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   169
        StringBuilder sb = new StringBuilder();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   170
        sb.append(typeAsString())
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   171
                .append(": length=")
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   172
                .append(Integer.toString(length))
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   173
                .append(", streamid=")
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   174
                .append(streamid)
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   175
                .append(", flags=");
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   176
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   177
        int f = flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   178
        int i = 0;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   179
        if (f == 0) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   180
            sb.append("0 ");
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   181
        } else {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   182
            while (f != 0) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   183
                if ((f & 1) == 1) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   184
                    sb.append(flagAsString(1 << i))
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   185
                      .append(' ');
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   186
                }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   187
                f = f >> 1;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   188
                i++;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   189
            }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   190
        }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   191
        return sb.toString();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   192
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   193
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   194
    // Override
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   195
    String flagAsString(int f) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   196
        return "unknown";
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   197
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   198
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   199
    abstract void computeLength();
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   200
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   201
    void writeOutgoing(ByteBufferGenerator bg) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   202
        if (length == -1) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   203
            throw new InternalError("Length not set on outgoing frame");
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   204
        }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   205
        ByteBuffer buf = bg.getBuffer(9);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   206
        int x = (length << 8) + type;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   207
        buf.putInt(x);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   208
        buf.put((byte)flags);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   209
        buf.putInt(streamid);
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   210
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents:
diff changeset
   211
}