| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // If |wire_setting_id| is the on-the-wire representation of a defined SETTINGS | 224 // If |wire_setting_id| is the on-the-wire representation of a defined SETTINGS |
| 247 // parameter, parse it to |*setting_id| and return true. | 225 // parameter, parse it to |*setting_id| and return true. |
| 248 NET_EXPORT_PRIVATE bool ParseSettingsId(int wire_setting_id, | 226 NET_EXPORT_PRIVATE bool ParseSettingsId(int wire_setting_id, |
| 249 SpdySettingsIds* setting_id); | 227 SpdySettingsIds* setting_id); |
| 250 | 228 |
| 251 // Return if |id| corresponds to a defined setting; | 229 // Return if |id| corresponds to a defined setting; |
| 252 // stringify |id| to |*settings_id_string| regardless. | 230 // stringify |id| to |*settings_id_string| regardless. |
| 253 NET_EXPORT_PRIVATE bool SettingsIdToString(SpdySettingsIds id, | 231 NET_EXPORT_PRIVATE bool SettingsIdToString(SpdySettingsIds id, |
| 254 const char** settings_id_string); | 232 const char** settings_id_string); |
| 255 | 233 |
| 256 // Parses a RST_STREAM error code from an on-the-wire enumeration. | 234 // Parse |wire_error_code| to a SpdyErrorCode. |
| 257 // Treat unrecognized error codes as INTERNAL_ERROR | 235 // Treat unrecognized error codes as INTERNAL_ERROR |
| 258 // as recommended by the HTTP/2 specification. | 236 // as recommended by the HTTP/2 specification. |
| 259 NET_EXPORT_PRIVATE SpdyRstStreamStatus | 237 NET_EXPORT_PRIVATE SpdyErrorCode ParseErrorCode(uint32_t wire_error_code); |
| 260 ParseRstStreamStatus(int rst_stream_status_field); | |
| 261 | |
| 262 // Parses a GOAWAY error code from an on-the-wire enumeration. | |
| 263 // Treat unrecognized error codes as INTERNAL_ERROR | |
| 264 // as recommended by the HTTP/2 specification. | |
| 265 NET_EXPORT_PRIVATE SpdyGoAwayStatus ParseGoAwayStatus(int goaway_status_field); | |
| 266 | 238 |
| 267 // Serialize RST_STREAM or GOAWAY frame error code to string | 239 // Serialize RST_STREAM or GOAWAY frame error code to string |
| 268 // for logging/debugging. | 240 // for logging/debugging. |
| 269 const char* ErrorCodeToString(uint32_t error_code); | 241 const char* ErrorCodeToString(uint32_t error_code); |
| 270 | 242 |
| 271 // Frame type for non-control (i.e. data) frames. | 243 // Frame type for non-control (i.e. data) frames. |
| 272 const int kDataFrameType = 0; | 244 const int kDataFrameType = 0; |
| 273 // Number of octets in the frame header. | 245 // Number of octets in the frame header. |
| 274 const size_t kFrameHeaderSize = 9; | 246 const size_t kFrameHeaderSize = 9; |
| 275 // Size, in bytes, of the data frame header. | 247 // Size, in bytes, of the data frame header. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 502 |
| 531 bool padded_; | 503 bool padded_; |
| 532 // padding_payload_len_ = desired padding length - len(padding length field). | 504 // padding_payload_len_ = desired padding length - len(padding length field). |
| 533 int padding_payload_len_; | 505 int padding_payload_len_; |
| 534 | 506 |
| 535 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); | 507 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); |
| 536 }; | 508 }; |
| 537 | 509 |
| 538 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR { | 510 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR { |
| 539 public: | 511 public: |
| 540 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status); | 512 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyErrorCode error_code); |
| 541 | 513 |
| 542 ~SpdyRstStreamIR() override; | 514 ~SpdyRstStreamIR() override; |
| 543 | 515 |
| 544 SpdyRstStreamStatus status() const { | 516 SpdyErrorCode error_code() const { return error_code_; } |
| 545 return status_; | 517 void set_error_code(SpdyErrorCode error_code) { error_code_ = error_code; } |
| 546 } | |
| 547 void set_status(SpdyRstStreamStatus status) { | |
| 548 status_ = status; | |
| 549 } | |
| 550 | 518 |
| 551 void Visit(SpdyFrameVisitor* visitor) const override; | 519 void Visit(SpdyFrameVisitor* visitor) const override; |
| 552 | 520 |
| 553 private: | 521 private: |
| 554 SpdyRstStreamStatus status_; | 522 SpdyErrorCode error_code_; |
| 555 | 523 |
| 556 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR); | 524 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR); |
| 557 }; | 525 }; |
| 558 | 526 |
| 559 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { | 527 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { |
| 560 public: | 528 public: |
| 561 SpdySettingsIR(); | 529 SpdySettingsIR(); |
| 562 ~SpdySettingsIR() override; | 530 ~SpdySettingsIR() override; |
| 563 | 531 |
| 564 // Overwrites as appropriate. | 532 // Overwrites as appropriate. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 594 bool is_ack_; | 562 bool is_ack_; |
| 595 | 563 |
| 596 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR); | 564 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR); |
| 597 }; | 565 }; |
| 598 | 566 |
| 599 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR { | 567 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR { |
| 600 public: | 568 public: |
| 601 // References description, doesn't copy it, so description must outlast | 569 // References description, doesn't copy it, so description must outlast |
| 602 // this SpdyGoAwayIR. | 570 // this SpdyGoAwayIR. |
| 603 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 571 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 604 SpdyGoAwayStatus status, | 572 SpdyErrorCode error_code, |
| 605 base::StringPiece description); | 573 base::StringPiece description); |
| 606 | 574 |
| 607 // References description, doesn't copy it, so description must outlast | 575 // References description, doesn't copy it, so description must outlast |
| 608 // this SpdyGoAwayIR. | 576 // this SpdyGoAwayIR. |
| 609 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 577 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 610 SpdyGoAwayStatus status, | 578 SpdyErrorCode error_code, |
| 611 const char* description); | 579 const char* description); |
| 612 | 580 |
| 613 // Moves description into description_store_, so caller doesn't need to | 581 // Moves description into description_store_, so caller doesn't need to |
| 614 // keep description live after constructing this SpdyGoAwayIR. | 582 // keep description live after constructing this SpdyGoAwayIR. |
| 615 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 583 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
| 616 SpdyGoAwayStatus status, | 584 SpdyErrorCode error_code, |
| 617 std::string description); | 585 std::string description); |
| 618 | 586 |
| 619 ~SpdyGoAwayIR() override; | 587 ~SpdyGoAwayIR() override; |
| 620 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } | 588 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; } |
| 621 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { | 589 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) { |
| 622 DCHECK_LE(0u, last_good_stream_id); | 590 DCHECK_LE(0u, last_good_stream_id); |
| 623 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); | 591 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask); |
| 624 last_good_stream_id_ = last_good_stream_id; | 592 last_good_stream_id_ = last_good_stream_id; |
| 625 } | 593 } |
| 626 SpdyGoAwayStatus status() const { return status_; } | 594 SpdyErrorCode error_code() const { return error_code_; } |
| 627 void set_status(SpdyGoAwayStatus status) { | 595 void set_error_code(SpdyErrorCode error_code) { |
| 628 // TODO(hkhalil): Check valid ranges of status? | 596 // TODO(hkhalil): Check valid ranges of error_code? |
| 629 status_ = status; | 597 error_code_ = error_code; |
| 630 } | 598 } |
| 631 | 599 |
| 632 const base::StringPiece& description() const { return description_; } | 600 const base::StringPiece& description() const { return description_; } |
| 633 | 601 |
| 634 void Visit(SpdyFrameVisitor* visitor) const override; | 602 void Visit(SpdyFrameVisitor* visitor) const override; |
| 635 | 603 |
| 636 private: | 604 private: |
| 637 SpdyStreamId last_good_stream_id_; | 605 SpdyStreamId last_good_stream_id_; |
| 638 SpdyGoAwayStatus status_; | 606 SpdyErrorCode error_code_; |
| 639 const std::string description_store_; | 607 const std::string description_store_; |
| 640 const base::StringPiece description_; | 608 const base::StringPiece description_; |
| 641 | 609 |
| 642 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); | 610 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR); |
| 643 }; | 611 }; |
| 644 | 612 |
| 645 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { | 613 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { |
| 646 public: | 614 public: |
| 647 explicit SpdyHeadersIR(SpdyStreamId stream_id) | 615 explicit SpdyHeadersIR(SpdyStreamId stream_id) |
| 648 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} | 616 : SpdyHeadersIR(stream_id, SpdyHeaderBlock()) {} |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 SpdyFrameVisitor() {} | 890 SpdyFrameVisitor() {} |
| 923 virtual ~SpdyFrameVisitor() {} | 891 virtual ~SpdyFrameVisitor() {} |
| 924 | 892 |
| 925 private: | 893 private: |
| 926 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 894 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
| 927 }; | 895 }; |
| 928 | 896 |
| 929 } // namespace net | 897 } // namespace net |
| 930 | 898 |
| 931 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 899 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |