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

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

Issue 243643002: Refactor RST_STREAM status code handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return 4; 294 return 4;
295 default: 295 default:
296 LOG(DFATAL) << "Serializing unhandled setting id " << id; 296 LOG(DFATAL) << "Serializing unhandled setting id " << id;
297 return -1; 297 return -1;
298 } 298 }
299 } 299 }
300 LOG(DFATAL) << "Unhandled SPDY version " << version; 300 LOG(DFATAL) << "Unhandled SPDY version " << version;
301 return -1; 301 return -1;
302 } 302 }
303 303
304 bool SpdyConstants::IsValidRstStreamStatus(SpdyMajorVersion version,
305 int rst_stream_status_field) {
306 switch (version) {
307 case SPDY2:
308 case SPDY3:
309 // PROTOCOL_ERROR is the valid first status code.
310 if (rst_stream_status_field <
311 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) {
312 return false;
313 }
314
315 // FRAME_TOO_LARGE is the valid last status code.
316 if (rst_stream_status_field >
317 SerializeRstStreamStatus(version, RST_STREAM_FRAME_TOO_LARGE)) {
318 return false;
319 }
320
321 return true;
322 case SPDY4:
323 // NO_ERROR is the first valid status code.
324 if (rst_stream_status_field <
325 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) {
326 return false;
327 }
328
329 // TODO(hkhalil): Omit COMPRESSION_ERROR and SETTINGS_TIMEOUT
330 /*
331 // This works because GOAWAY and RST_STREAM share a namespace.
332 if (rst_stream_status_field ==
333 SerializeGoAwayStatus(version, GOAWAY_COMPRESSION_ERROR) ||
334 rst_stream_status_field ==
335 SerializeGoAwayStatus(version, GOAWAY_SETTINGS_TIMEOUT)) {
336 return false;
337 }
338 */
339
340 // ENHANCE_YOUR_CALM is the last valid status code.
341 if (rst_stream_status_field >
342 SerializeRstStreamStatus(version, RST_STREAM_ENHANCE_YOUR_CALM)) {
343 return false;
344 }
345
346 return true;
347 }
348 }
349
350 SpdyRstStreamStatus SpdyConstants::ParseRstStreamStatus(
351 SpdyMajorVersion version,
352 int rst_stream_status_field) {
353 switch (version) {
354 case SPDY2:
355 case SPDY3:
356 switch (rst_stream_status_field) {
357 case 1:
358 return RST_STREAM_PROTOCOL_ERROR;
359 case 2:
360 return RST_STREAM_INVALID_STREAM;
361 case 3:
362 return RST_STREAM_REFUSED_STREAM;
363 case 4:
364 return RST_STREAM_UNSUPPORTED_VERSION;
365 case 5:
366 return RST_STREAM_CANCEL;
367 case 6:
368 return RST_STREAM_INTERNAL_ERROR;
369 case 7:
370 return RST_STREAM_FLOW_CONTROL_ERROR;
371 case 8:
372 return RST_STREAM_STREAM_IN_USE;
373 case 9:
374 return RST_STREAM_STREAM_ALREADY_CLOSED;
375 case 10:
376 return RST_STREAM_INVALID_CREDENTIALS;
377 case 11:
378 return RST_STREAM_FRAME_TOO_LARGE;
379 }
380 break;
381 case SPDY4:
382 switch (rst_stream_status_field) {
383 case 1:
384 return RST_STREAM_PROTOCOL_ERROR;
385 case 2:
386 return RST_STREAM_INTERNAL_ERROR;
387 case 3:
388 return RST_STREAM_FLOW_CONTROL_ERROR;
389 case 5:
390 return RST_STREAM_STREAM_CLOSED;
391 case 6:
392 return RST_STREAM_FRAME_SIZE_ERROR;
393 case 7:
394 return RST_STREAM_REFUSED_STREAM;
395 case 8:
396 return RST_STREAM_CANCEL;
397 case 10:
398 return RST_STREAM_CONNECT_ERROR;
399 case 11:
400 return RST_STREAM_ENHANCE_YOUR_CALM;
401 }
402 break;
403 }
404
405 LOG(DFATAL) << "Invalid RST_STREAM status " << rst_stream_status_field;
406 return RST_STREAM_PROTOCOL_ERROR;
407 }
408
409 int SpdyConstants::SerializeRstStreamStatus(
410 SpdyMajorVersion version,
411 SpdyRstStreamStatus rst_stream_status) {
412 switch (version) {
413 case SPDY2:
414 case SPDY3:
415 switch (rst_stream_status) {
416 case RST_STREAM_PROTOCOL_ERROR:
417 return 1;
418 case RST_STREAM_INVALID_STREAM:
419 return 2;
420 case RST_STREAM_REFUSED_STREAM:
421 return 3;
422 case RST_STREAM_UNSUPPORTED_VERSION:
423 return 4;
424 case RST_STREAM_CANCEL:
425 return 5;
426 case RST_STREAM_INTERNAL_ERROR:
427 return 6;
428 case RST_STREAM_FLOW_CONTROL_ERROR:
429 return 7;
430 case RST_STREAM_STREAM_IN_USE:
431 return 8;
432 case RST_STREAM_STREAM_ALREADY_CLOSED:
433 return 9;
434 case RST_STREAM_INVALID_CREDENTIALS:
435 return 10;
436 case RST_STREAM_FRAME_TOO_LARGE:
437 return 11;
438 default:
439 LOG(DFATAL) << "Unhandled RST_STREAM status "
440 << rst_stream_status;
441 return -1;
442 }
443 case SPDY4:
444 switch (rst_stream_status) {
445 case RST_STREAM_PROTOCOL_ERROR:
446 return 1;
447 case RST_STREAM_INTERNAL_ERROR:
448 return 2;
449 case RST_STREAM_FLOW_CONTROL_ERROR:
450 return 3;
451 case RST_STREAM_STREAM_CLOSED:
452 return 5;
453 case RST_STREAM_FRAME_SIZE_ERROR:
454 return 6;
455 case RST_STREAM_REFUSED_STREAM:
456 return 7;
457 case RST_STREAM_CANCEL:
458 return 8;
459 case RST_STREAM_CONNECT_ERROR:
460 return 10;
461 case RST_STREAM_ENHANCE_YOUR_CALM:
462 return 11;
463 default:
464 LOG(DFATAL) << "Unhandled RST_STREAM status "
465 << rst_stream_status;
466 return -1;
467 }
468 }
469 }
470
304 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { 471 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const {
305 return visitor->VisitData(*this); 472 return visitor->VisitData(*this);
306 } 473 }
307 474
308 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { 475 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const {
309 return visitor->VisitSynStream(*this); 476 return visitor->VisitSynStream(*this);
310 } 477 }
311 478
312 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { 479 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const {
313 return visitor->VisitSynReply(*this); 480 return visitor->VisitSynReply(*this);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 540
374 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { 541 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const {
375 return visitor->VisitPushPromise(*this); 542 return visitor->VisitPushPromise(*this);
376 } 543 }
377 544
378 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { 545 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const {
379 return visitor->VisitContinuation(*this); 546 return visitor->VisitContinuation(*this);
380 } 547 }
381 548
382 } // namespace net 549 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698