Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1796)

Side by Side Diff: net/spdy/spdy_protocol.cc

Issue 243613003: Refactor GOAWAY status code handling, also handle SPDY4/HTTP2 status codes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor build fixes. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/spdy/spdy_protocol.h" 5 #include "net/spdy/spdy_protocol.h"
6 6
7 namespace net { 7 namespace net {
8 8
9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR(
10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} 10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {}
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 default: 465 default:
466 LOG(DFATAL) << "Unhandled RST_STREAM status " 466 LOG(DFATAL) << "Unhandled RST_STREAM status "
467 << rst_stream_status; 467 << rst_stream_status;
468 return -1; 468 return -1;
469 } 469 }
470 } 470 }
471 LOG(DFATAL) << "Unhandled SPDY version " << version; 471 LOG(DFATAL) << "Unhandled SPDY version " << version;
472 return -1; 472 return -1;
473 } 473 }
474 474
475 bool SpdyConstants::IsValidGoAwayStatus(SpdyMajorVersion version,
476 int goaway_status_field) {
477 switch (version) {
478 case SPDY2:
479 case SPDY3:
480 // GOAWAY_OK is the first valid status.
481 if (goaway_status_field < SerializeGoAwayStatus(version, GOAWAY_OK)) {
482 return false;
483 }
484
485 // GOAWAY_INTERNAL_ERROR is the last valid status.
486 if (goaway_status_field > SerializeGoAwayStatus(version,
487 GOAWAY_INTERNAL_ERROR)) {
488 return false;
489 }
490
491 return true;
492 case SPDY4:
493 // GOAWAY_NO_ERROR is the first valid status.
494 if (goaway_status_field < SerializeGoAwayStatus(version,
495 GOAWAY_NO_ERROR)) {
496 return false;
497 }
498
499 // GOAWAY_INADEQUATE_SECURITY is the last valid status.
500 if (goaway_status_field >
501 SerializeGoAwayStatus(version, GOAWAY_INADEQUATE_SECURITY)) {
502 return false;
503 }
504
505 return true;
506 }
507 LOG(DFATAL) << "Unknown SpdyMajorVersion " << version;
508 return false;
509 }
510
511 SpdyGoAwayStatus SpdyConstants::ParseGoAwayStatus(SpdyMajorVersion version,
512 int goaway_status_field) {
513 switch (version) {
514 case SPDY2:
515 case SPDY3:
516 switch (goaway_status_field) {
517 case 0:
518 return GOAWAY_OK;
519 case 1:
520 return GOAWAY_PROTOCOL_ERROR;
521 case 2:
522 return GOAWAY_INTERNAL_ERROR;
523 }
524 break;
525 case SPDY4:
526 switch (goaway_status_field) {
527 case 0:
528 return GOAWAY_NO_ERROR;
529 case 1:
530 return GOAWAY_PROTOCOL_ERROR;
531 case 2:
532 return GOAWAY_INTERNAL_ERROR;
533 case 3:
534 return GOAWAY_FLOW_CONTROL_ERROR;
535 case 4:
536 return GOAWAY_SETTINGS_TIMEOUT;
537 case 5:
538 return GOAWAY_STREAM_CLOSED;
539 case 6:
540 return GOAWAY_FRAME_SIZE_ERROR;
541 case 7:
542 return GOAWAY_REFUSED_STREAM;
543 case 8:
544 return GOAWAY_CANCEL;
545 case 9:
546 return GOAWAY_COMPRESSION_ERROR;
547 case 10:
548 return GOAWAY_CONNECT_ERROR;
549 case 11:
550 return GOAWAY_ENHANCE_YOUR_CALM;
551 case 12:
552 return GOAWAY_INADEQUATE_SECURITY;
553 }
554 break;
555 }
556
557 LOG(DFATAL) << "Unhandled GOAWAY status " << goaway_status_field;
558 return GOAWAY_PROTOCOL_ERROR;
559 }
560
561 int SpdyConstants::SerializeGoAwayStatus(SpdyMajorVersion version,
562 SpdyGoAwayStatus status) {
563 switch (version) {
564 case SPDY2:
565 case SPDY3:
566 switch (status) {
567 case GOAWAY_OK:
568 return 0;
569 case GOAWAY_PROTOCOL_ERROR:
570 return 1;
571 case GOAWAY_INTERNAL_ERROR:
572 return 2;
573 default:
574 LOG(DFATAL) << "Serializing unhandled GOAWAY status " << status;
575 return -1;
576 }
577 case SPDY4:
578 switch (status) {
579 case GOAWAY_NO_ERROR:
580 return 0;
581 case GOAWAY_PROTOCOL_ERROR:
582 return 1;
583 case GOAWAY_INTERNAL_ERROR:
584 return 2;
585 case GOAWAY_FLOW_CONTROL_ERROR:
586 return 3;
587 case GOAWAY_SETTINGS_TIMEOUT:
588 return 4;
589 case GOAWAY_STREAM_CLOSED:
590 return 5;
591 case GOAWAY_FRAME_SIZE_ERROR:
592 return 6;
593 case GOAWAY_REFUSED_STREAM:
594 return 7;
595 case GOAWAY_CANCEL:
596 return 8;
597 case GOAWAY_COMPRESSION_ERROR:
598 return 9;
599 case GOAWAY_CONNECT_ERROR:
600 return 10;
601 case GOAWAY_ENHANCE_YOUR_CALM:
602 return 11;
603 case GOAWAY_INADEQUATE_SECURITY:
604 return 12;
605 default:
606 LOG(DFATAL) << "Serializing unhandled GOAWAY status " << status;
607 return -1;
608 }
609 }
610 LOG(DFATAL) << "Unknown SpdyMajorVersion " << version;
611 return -1;
612 }
613
475 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { 614 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const {
476 return visitor->VisitData(*this); 615 return visitor->VisitData(*this);
477 } 616 }
478 617
479 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { 618 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const {
480 return visitor->VisitSynStream(*this); 619 return visitor->VisitSynStream(*this);
481 } 620 }
482 621
483 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { 622 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const {
484 return visitor->VisitSynReply(*this); 623 return visitor->VisitSynReply(*this);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 683
545 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { 684 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const {
546 return visitor->VisitPushPromise(*this); 685 return visitor->VisitPushPromise(*this);
547 } 686 }
548 687
549 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { 688 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const {
550 return visitor->VisitContinuation(*this); 689 return visitor->VisitContinuation(*this);
551 } 690 }
552 691
553 } // namespace net 692 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698