| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 | 5 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 |
| 6 // The SPDY 3 spec can be found at: | 6 // The SPDY 3 spec can be found at: |
| 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 | 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 |
| 8 | 8 |
| 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
| 10 #define NET_SPDY_SPDY_PROTOCOL_H_ | 10 #define NET_SPDY_SPDY_PROTOCOL_H_ |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 SETTINGS_INITIAL_WINDOW_SIZE = 0x4, | 137 SETTINGS_INITIAL_WINDOW_SIZE = 0x4, |
| 138 // The size of the largest frame payload that a receiver is willing to accept. | 138 // The size of the largest frame payload that a receiver is willing to accept. |
| 139 SETTINGS_MAX_FRAME_SIZE = 0x5, | 139 SETTINGS_MAX_FRAME_SIZE = 0x5, |
| 140 // The maximum size of header list that the sender is prepared to accept. | 140 // The maximum size of header list that the sender is prepared to accept. |
| 141 SETTINGS_MAX_HEADER_LIST_SIZE = 0x6, | 141 SETTINGS_MAX_HEADER_LIST_SIZE = 0x6, |
| 142 SETTINGS_MAX = SETTINGS_MAX_HEADER_LIST_SIZE | 142 SETTINGS_MAX = SETTINGS_MAX_HEADER_LIST_SIZE |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 using SettingsMap = std::map<SpdySettingsIds, uint32_t>; | 145 using SettingsMap = std::map<SpdySettingsIds, uint32_t>; |
| 146 | 146 |
| 147 // Status codes for RST_STREAM frames. | 147 // HTTP/2 error codes, RFC 7540 Section 7. |
| 148 enum SpdyRstStreamStatus { | 148 enum SpdyErrorCode : uint32_t { |
| 149 RST_STREAM_NO_ERROR = 0, | 149 ERROR_CODE_NO_ERROR = 0x0, |
| 150 RST_STREAM_MIN = RST_STREAM_NO_ERROR, | 150 ERROR_CODE_PROTOCOL_ERROR = 0x1, |
| 151 RST_STREAM_PROTOCOL_ERROR = 1, | 151 ERROR_CODE_INTERNAL_ERROR = 0x2, |
| 152 RST_STREAM_INTERNAL_ERROR = 2, | 152 ERROR_CODE_FLOW_CONTROL_ERROR = 0x3, |
| 153 RST_STREAM_FLOW_CONTROL_ERROR = 3, | 153 ERROR_CODE_SETTINGS_TIMEOUT = 0x4, |
| 154 RST_STREAM_SETTINGS_TIMEOUT = 4, | 154 ERROR_CODE_STREAM_CLOSED = 0x5, |
| 155 RST_STREAM_STREAM_CLOSED = 5, | 155 ERROR_CODE_FRAME_SIZE_ERROR = 0x6, |
| 156 RST_STREAM_FRAME_SIZE_ERROR = 6, | 156 ERROR_CODE_REFUSED_STREAM = 0x7, |
| 157 RST_STREAM_REFUSED_STREAM = 7, | 157 ERROR_CODE_CANCEL = 0x8, |
| 158 RST_STREAM_CANCEL = 8, | 158 ERROR_CODE_COMPRESSION_ERROR = 0x9, |
| 159 RST_STREAM_COMPRESSION_ERROR = 9, | 159 ERROR_CODE_CONNECT_ERROR = 0xa, |
| 160 RST_STREAM_CONNECT_ERROR = 10, | 160 ERROR_CODE_ENHANCE_YOUR_CALM = 0xb, |
| 161 RST_STREAM_ENHANCE_YOUR_CALM = 11, | 161 ERROR_CODE_INADEQUATE_SECURITY = 0xc, |
| 162 RST_STREAM_INADEQUATE_SECURITY = 12, | 162 ERROR_CODE_HTTP_1_1_REQUIRED = 0xd, |
| 163 RST_STREAM_HTTP_1_1_REQUIRED = 13, | 163 ERROR_CODE_MAX = ERROR_CODE_HTTP_1_1_REQUIRED |
| 164 RST_STREAM_MAX = RST_STREAM_HTTP_1_1_REQUIRED, | |
| 165 RST_STREAM_NUM_STATUS_CODES = 14 | |
| 166 }; | |
| 167 | |
| 168 // Status codes for GOAWAY frames. | |
| 169 enum SpdyGoAwayStatus { | |
| 170 GOAWAY_NO_ERROR = 0, | |
| 171 GOAWAY_MIN = GOAWAY_NO_ERROR, | |
| 172 GOAWAY_PROTOCOL_ERROR = 1, | |
| 173 GOAWAY_INTERNAL_ERROR = 2, | |
| 174 GOAWAY_FLOW_CONTROL_ERROR = 3, | |
| 175 GOAWAY_SETTINGS_TIMEOUT = 4, | |
| 176 GOAWAY_STREAM_CLOSED = 5, | |
| 177 GOAWAY_FRAME_SIZE_ERROR = 6, | |
| 178 GOAWAY_REFUSED_STREAM = 7, | |
| 179 GOAWAY_CANCEL = 8, | |
| 180 GOAWAY_COMPRESSION_ERROR = 9, | |
| 181 GOAWAY_CONNECT_ERROR = 10, | |
| 182 GOAWAY_ENHANCE_YOUR_CALM = 11, | |
| 183 GOAWAY_INADEQUATE_SECURITY = 12, | |
| 184 GOAWAY_HTTP_1_1_REQUIRED = 13, | |
| 185 GOAWAY_MAX = GOAWAY_HTTP_1_1_REQUIRED | |
| 186 }; | 164 }; |
| 187 | 165 |
| 188 // A SPDY priority is a number between 0 and 7 (inclusive). | 166 // A SPDY priority is a number between 0 and 7 (inclusive). |
| 189 typedef uint8_t SpdyPriority; | 167 typedef uint8_t SpdyPriority; |
| 190 | 168 |
| 191 // Lowest and Highest here refer to SPDY priorities as described in | 169 // Lowest and Highest here refer to SPDY priorities as described in |
| 192 | 170 |
| 193 // https://www.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3-1#TOC-2.3.3-
Stream-priority | 171 // https://www.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3-1#TOC-2.3.3-
Stream-priority |
| 194 const SpdyPriority kV3HighestPriority = 0; | 172 const SpdyPriority kV3HighestPriority = 0; |
| 195 const SpdyPriority kV3LowestPriority = 7; | 173 const SpdyPriority kV3LowestPriority = 7; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // If |wire_setting_id| is the on-the-wire representation of a defined SETTINGS | 221 // If |wire_setting_id| is the on-the-wire representation of a defined SETTINGS |
| 244 // parameter, parse it to |*setting_id| and return true. | 222 // parameter, parse it to |*setting_id| and return true. |
| 245 NET_EXPORT_PRIVATE bool ParseSettingsId(int wire_setting_id, | 223 NET_EXPORT_PRIVATE bool ParseSettingsId(int wire_setting_id, |
| 246 SpdySettingsIds* setting_id); | 224 SpdySettingsIds* setting_id); |
| 247 | 225 |
| 248 // Return if |id| corresponds to a defined setting; | 226 // Return if |id| corresponds to a defined setting; |
| 249 // stringify |id| to |*settings_id_string| regardless. | 227 // stringify |id| to |*settings_id_string| regardless. |
| 250 NET_EXPORT_PRIVATE bool SettingsIdToString(SpdySettingsIds id, | 228 NET_EXPORT_PRIVATE bool SettingsIdToString(SpdySettingsIds id, |
| 251 const char** settings_id_string); | 229 const char** settings_id_string); |
| 252 | 230 |
| 253 // Parses a RST_STREAM error code from an on-the-wire enumeration. | 231 // Parse |wire_error_code| to a SpdyErrorCode. |
| 254 // Treat unrecognized error codes as INTERNAL_ERROR | 232 // Treat unrecognized error codes as INTERNAL_ERROR |
| 255 // as recommended by the HTTP/2 specification. | 233 // as recommended by the HTTP/2 specification. |
| 256 NET_EXPORT_PRIVATE SpdyRstStreamStatus | 234 NET_EXPORT_PRIVATE SpdyErrorCode ParseErrorCode(uint32_t wire_error_code); |
| 257 ParseRstStreamStatus(int rst_stream_status_field); | |
| 258 | |
| 259 // Parses a GOAWAY error code from an on-the-wire enumeration. | |
| 260 // Treat unrecognized error codes as INTERNAL_ERROR | |
| 261 // as recommended by the HTTP/2 specification. | |
| 262 NET_EXPORT_PRIVATE SpdyGoAwayStatus ParseGoAwayStatus(int goaway_status_field); | |
| 263 | 235 |
| 264 // Frame type for non-control (i.e. data) frames. | 236 // Frame type for non-control (i.e. data) frames. |
| 265 const int kDataFrameType = 0; | 237 const int kDataFrameType = 0; |
| 266 // Number of octets in the frame header. | 238 // Number of octets in the frame header. |
| 267 const size_t kFrameHeaderSize = 9; | 239 const size_t kFrameHeaderSize = 9; |
| 268 // Size, in bytes, of the data frame header. | 240 // Size, in bytes, of the data frame header. |
| 269 const size_t kDataFrameMinimumSize = kFrameHeaderSize; | 241 const size_t kDataFrameMinimumSize = kFrameHeaderSize; |
| 270 // Maximum possible configurable size of a frame in octets. | 242 // Maximum possible configurable size of a frame in octets. |
| 271 const size_t kMaxFrameSizeLimit = kSpdyMaxFrameSizeLimit + kFrameHeaderSize; | 243 const size_t kMaxFrameSizeLimit = kSpdyMaxFrameSizeLimit + kFrameHeaderSize; |
| 272 // Size of a header block size field. Valid only for SPDY 3. | 244 // Size of a header block size field. Valid only for SPDY 3. |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 495 |
| 524 bool padded_; | 496 bool padded_; |
| 525 // padding_payload_len_ = desired padding length - len(padding length field). | 497 // padding_payload_len_ = desired padding length - len(padding length field). |
| 526 int padding_payload_len_; | 498 int padding_payload_len_; |
| 527 | 499 |
| 528 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); | 500 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); |
| 529 }; | 501 }; |
| 530 | 502 |
| 531 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR { | 503 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR { |
| 532 public: | 504 public: |
| 533 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status); | 505 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyErrorCode error_code); |
| 534 | 506 |
| 535 ~SpdyRstStreamIR() override; | 507 ~SpdyRstStreamIR() override; |
| 536 | 508 |
| 537 SpdyRstStreamStatus status() const { | 509 SpdyErrorCode error_code() const { return error_code_; } |
| 538 return status_; | 510 void set_error_code(SpdyErrorCode error_code) { error_code_ = error_code; } |
| 539 } | |
| 540 void set_status(SpdyRstStreamStatus status) { | |
| 541 status_ = status; | |
| 542 } | |
| 543 | 511 |
| 544 void Visit(SpdyFrameVisitor* visitor) const override; | 512 void Visit(SpdyFrameVisitor* visitor) const override; |
| 545 | 513 |
| 546 private: | 514 private: |
| 547 SpdyRstStreamStatus status_; | 515 SpdyErrorCode error_code_; |
| 548 | 516 |
| 549 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR); | 517 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR); |
| 550 }; | 518 }; |
| 551 | 519 |
| 552 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { | 520 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { |
| 553 public: | 521 public: |
| 554 SpdySettingsIR(); | 522 SpdySettingsIR(); |
| 555 ~SpdySettingsIR() override; | 523 ~SpdySettingsIR() override; |
| 556 | 524 |
| 557 // Overwrites as appropriate. | 525 // Overwrites as appropriate. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 587 bool is_ack_; | 555 bool is_ack_; |
| 588 | 556 |
| 589 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR); | 557 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR); |
| 590 }; | 558 }; |
| 591 | 559 |
| 592 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR { | 560 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR { |
| 593 public: | 561 public: |
| 594 // References description, doesn't copy it, so description must outlast | 562 // References description, doesn't copy it, so description must outlast |
| 595 // this SpdyGoAwayIR. | 563 // this SpdyGoAwayIR. |
| 596 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 564 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 597 SpdyGoAwayStatus status, | 565 SpdyErrorCode error_code, |
| 598 base::StringPiece description); | 566 base::StringPiece description); |
| 599 | 567 |
| 600 // References description, doesn't copy it, so description must outlast | 568 // References description, doesn't copy it, so description must outlast |
| 601 // this SpdyGoAwayIR. | 569 // this SpdyGoAwayIR. |
| 602 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 570 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 603 SpdyGoAwayStatus status, | 571 SpdyErrorCode error_code, |
| 604 const char* description); | 572 const char* description); |
| 605 | 573 |
| 606 // Moves description into description_store_, so caller doesn't need to | 574 // Moves description into description_store_, so caller doesn't need to |
| 607 // keep description live after constructing this SpdyGoAwayIR. | 575 // keep description live after constructing this SpdyGoAwayIR. |
| 608 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 576 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 609 SpdyGoAwayStatus status, | 577 SpdyErrorCode error_code, |
| 610 std::string description); | 578 std::string description); |
| 611 | 579 |
| 612 ~SpdyGoAwayIR() override; | 580 ~SpdyGoAwayIR() override; |
| 613 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } | 581 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } |
| 614 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { | 582 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { |
| 615 DCHECK_LE(0u, last_good_stream_id); | 583 DCHECK_LE(0u, last_good_stream_id); |
| 616 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); | 584 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); |
| 617 last_good_stream_id_ = last_good_stream_id; | 585 last_good_stream_id_ = last_good_stream_id; |
| 618 } | 586 } |
| 619 SpdyGoAwayStatus status() const { return status_; } | 587 SpdyErrorCode error_code() const { return error_code_; } |
| 620 void set_status(SpdyGoAwayStatus status) { | 588 void set_error_code(SpdyErrorCode error_code) { |
| 621 // TODO(hkhalil): Check valid ranges of status? | 589 // TODO(hkhalil): Check valid ranges of error_code? |
| 622 status_ = status; | 590 error_code_ = error_code; |
| 623 } | 591 } |
| 624 | 592 |
| 625 const base::StringPiece& description() const { return description_; } | 593 const base::StringPiece& description() const { return description_; } |
| 626 | 594 |
| 627 void Visit(SpdyFrameVisitor* visitor) const override; | 595 void Visit(SpdyFrameVisitor* visitor) const override; |
| 628 | 596 |
| 629 private: | 597 private: |
| 630 SpdyStreamId last_good_stream_id_; | 598 SpdyStreamId last_good_stream_id_; |
| 631 SpdyGoAwayStatus status_; | 599 SpdyErrorCode error_code_; |
| 632 const std::string description_store_; | 600 const std::string description_store_; |
| 633 const base::StringPiece description_; | 601 const base::StringPiece description_; |
| 634 | 602 |
| 635 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); | 603 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); |
| 636 }; | 604 }; |
| 637 | 605 |
| 638 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { | 606 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { |
| 639 public: | 607 public: |
| 640 explicit SpdyHeadersIR(SpdyStreamId stream_id) | 608 explicit SpdyHeadersIR(SpdyStreamId stream_id) |
| 641 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} | 609 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 SpdyFrameVisitor() {} | 883 SpdyFrameVisitor() {} |
| 916 virtual ~SpdyFrameVisitor() {} | 884 virtual ~SpdyFrameVisitor() {} |
| 917 | 885 |
| 918 private: | 886 private: |
| 919 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 887 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
| 920 }; | 888 }; |
| 921 | 889 |
| 922 } // namespace net | 890 } // namespace net |
| 923 | 891 |
| 924 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 892 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |