| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_test_util_common.h" | 5 #include "net/spdy/spdy_test_util_common.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 694 |
| 695 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, | 695 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, |
| 696 SpdyHeaderBlock* headers) const { | 696 SpdyHeaderBlock* headers) const { |
| 697 std::string scheme, host, path; | 697 std::string scheme, host, path; |
| 698 ParseUrl(url, &scheme, &host, &path); | 698 ParseUrl(url, &scheme, &host, &path); |
| 699 (*headers)[GetHostKey()] = host; | 699 (*headers)[GetHostKey()] = host; |
| 700 (*headers)[GetSchemeKey()] = scheme; | 700 (*headers)[GetSchemeKey()] = scheme; |
| 701 (*headers)[GetPathKey()] = path; | 701 (*headers)[GetPathKey()] = path; |
| 702 } | 702 } |
| 703 | 703 |
| 704 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( | 704 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock( |
| 705 base::StringPiece url) const { | 705 base::StringPiece url) const { |
| 706 return ConstructHeaderBlock("GET", url, NULL); | 706 return ConstructHeaderBlock("GET", url, NULL); |
| 707 } | 707 } |
| 708 | 708 |
| 709 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( | 709 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlockForProxy( |
| 710 base::StringPiece url) const { | 710 base::StringPiece url) const { |
| 711 std::unique_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); | 711 return ConstructGetHeaderBlock(url); |
| 712 return headers; | |
| 713 } | 712 } |
| 714 | 713 |
| 715 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( | 714 SpdyHeaderBlock SpdyTestUtil::ConstructHeadHeaderBlock( |
| 716 base::StringPiece url, | 715 base::StringPiece url, |
| 717 int64_t content_length) const { | 716 int64_t content_length) const { |
| 718 return ConstructHeaderBlock("HEAD", url, nullptr); | 717 return ConstructHeaderBlock("HEAD", url, nullptr); |
| 719 } | 718 } |
| 720 | 719 |
| 721 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( | 720 SpdyHeaderBlock SpdyTestUtil::ConstructPostHeaderBlock( |
| 722 base::StringPiece url, | 721 base::StringPiece url, |
| 723 int64_t content_length) const { | 722 int64_t content_length) const { |
| 724 return ConstructHeaderBlock("POST", url, &content_length); | 723 return ConstructHeaderBlock("POST", url, &content_length); |
| 725 } | 724 } |
| 726 | 725 |
| 727 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPutHeaderBlock( | 726 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( |
| 728 base::StringPiece url, | 727 base::StringPiece url, |
| 729 int64_t content_length) const { | 728 int64_t content_length) const { |
| 730 return ConstructHeaderBlock("PUT", url, &content_length); | 729 return ConstructHeaderBlock("PUT", url, &content_length); |
| 731 } | 730 } |
| 732 | 731 |
| 733 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( | 732 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( |
| 734 const SpdyHeaderInfo& header_info, | 733 const SpdyHeaderInfo& header_info, |
| 735 std::unique_ptr<SpdyHeaderBlock> headers) const { | 734 SpdyHeaderBlock headers) const { |
| 736 BufferedSpdyFramer framer(spdy_version_); | 735 BufferedSpdyFramer framer(spdy_version_); |
| 737 SpdySerializedFrame* frame = NULL; | 736 SpdySerializedFrame* frame = NULL; |
| 738 switch (header_info.kind) { | 737 switch (header_info.kind) { |
| 739 case DATA: | 738 case DATA: |
| 740 frame = framer.CreateDataFrame(header_info.id, header_info.data, | 739 frame = framer.CreateDataFrame(header_info.id, header_info.data, |
| 741 header_info.data_length, | 740 header_info.data_length, |
| 742 header_info.data_flags); | 741 header_info.data_flags); |
| 743 break; | 742 break; |
| 744 case SYN_STREAM: | 743 case SYN_STREAM: |
| 745 { | 744 frame = framer.CreateSynStream( |
| 746 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, | 745 header_info.id, header_info.assoc_id, header_info.priority, |
| 747 header_info.priority, | 746 header_info.control_flags, std::move(headers)); |
| 748 header_info.control_flags, | |
| 749 headers.get()); | |
| 750 } | |
| 751 break; | 747 break; |
| 752 case SYN_REPLY: | 748 case SYN_REPLY: |
| 753 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, | 749 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, |
| 754 headers.get()); | 750 std::move(headers)); |
| 755 break; | 751 break; |
| 756 case RST_STREAM: | 752 case RST_STREAM: |
| 757 frame = framer.CreateRstStream(header_info.id, header_info.status); | 753 frame = framer.CreateRstStream(header_info.id, header_info.status); |
| 758 break; | 754 break; |
| 759 case HEADERS: | 755 case HEADERS: |
| 760 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, | 756 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, |
| 761 header_info.weight, headers.get()); | 757 header_info.weight, std::move(headers)); |
| 762 break; | 758 break; |
| 763 default: | 759 default: |
| 764 ADD_FAILURE(); | 760 ADD_FAILURE(); |
| 765 break; | 761 break; |
| 766 } | 762 } |
| 767 return frame; | 763 return frame; |
| 768 } | 764 } |
| 769 | 765 |
| 770 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( | 766 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( |
| 771 const SpdyHeaderInfo& header_info, | 767 const SpdyHeaderInfo& header_info, |
| 772 const char* const extra_headers[], | 768 const char* const extra_headers[], |
| 773 int extra_header_count, | 769 int extra_header_count, |
| 774 const char* const tail_headers[], | 770 const char* const tail_headers[], |
| 775 int tail_header_count) const { | 771 int tail_header_count) const { |
| 776 std::unique_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 772 SpdyHeaderBlock headers; |
| 777 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 773 AppendToHeaderBlock(extra_headers, extra_header_count, &headers); |
| 778 if (tail_headers && tail_header_count) | 774 if (tail_headers && tail_header_count) |
| 779 AppendToHeaderBlock(tail_headers, tail_header_count, headers.get()); | 775 AppendToHeaderBlock(tail_headers, tail_header_count, &headers); |
| 780 return ConstructSpdyFrame(header_info, std::move(headers)); | 776 return ConstructSpdyFrame(header_info, std::move(headers)); |
| 781 } | 777 } |
| 782 | 778 |
| 783 std::string SpdyTestUtil::ConstructSpdyReplyString( | 779 std::string SpdyTestUtil::ConstructSpdyReplyString( |
| 784 const SpdyHeaderBlock& headers) const { | 780 const SpdyHeaderBlock& headers) const { |
| 785 std::string reply_string; | 781 std::string reply_string; |
| 786 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 782 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
| 787 it != headers.end(); ++it) { | 783 it != headers.end(); ++it) { |
| 788 std::string key = it->first.as_string(); | 784 std::string key = it->first.as_string(); |
| 789 // Remove leading colon from "special" headers (for SPDY3 and | 785 // Remove leading colon from "special" headers (for SPDY3 and |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 SpdyRstStreamStatus status) { | 867 SpdyRstStreamStatus status) { |
| 872 SpdyRstStreamIR rst_ir(stream_id, status); | 868 SpdyRstStreamIR rst_ir(stream_id, status); |
| 873 return new SpdySerializedFrame( | 869 return new SpdySerializedFrame( |
| 874 headerless_spdy_framer_.SerializeRstStream(rst_ir)); | 870 headerless_spdy_framer_.SerializeRstStream(rst_ir)); |
| 875 } | 871 } |
| 876 | 872 |
| 877 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( | 873 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( |
| 878 const char* const url, | 874 const char* const url, |
| 879 SpdyStreamId stream_id, | 875 SpdyStreamId stream_id, |
| 880 RequestPriority request_priority) { | 876 RequestPriority request_priority) { |
| 881 std::unique_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url)); | 877 SpdyHeaderBlock block(ConstructGetHeaderBlock(url)); |
| 882 return ConstructSpdySyn(stream_id, *block, request_priority, true); | 878 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); |
| 883 } | 879 } |
| 884 | 880 |
| 885 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( | 881 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( |
| 886 const char* const extra_headers[], | 882 const char* const extra_headers[], |
| 887 int extra_header_count, | 883 int extra_header_count, |
| 888 int stream_id, | 884 int stream_id, |
| 889 RequestPriority request_priority, | 885 RequestPriority request_priority, |
| 890 bool direct) { | 886 bool direct) { |
| 891 SpdyHeaderBlock block; | 887 SpdyHeaderBlock block; |
| 892 MaybeAddVersionHeader(&block); | 888 MaybeAddVersionHeader(&block); |
| 893 block[GetMethodKey()] = "GET"; | 889 block[GetMethodKey()] = "GET"; |
| 894 AddUrlToHeaderBlock(default_url_.spec(), &block); | 890 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 895 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 891 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 896 return ConstructSpdySyn(stream_id, block, request_priority, true); | 892 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); |
| 897 } | 893 } |
| 898 | 894 |
| 899 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect( | 895 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect( |
| 900 const char* const extra_headers[], | 896 const char* const extra_headers[], |
| 901 int extra_header_count, | 897 int extra_header_count, |
| 902 int stream_id, | 898 int stream_id, |
| 903 RequestPriority priority, | 899 RequestPriority priority, |
| 904 const HostPortPair& host_port_pair) { | 900 const HostPortPair& host_port_pair) { |
| 905 SpdyHeaderBlock block; | 901 SpdyHeaderBlock block; |
| 906 MaybeAddVersionHeader(&block); | 902 MaybeAddVersionHeader(&block); |
| 907 block[GetMethodKey()] = "CONNECT"; | 903 block[GetMethodKey()] = "CONNECT"; |
| 908 if (spdy_version() < HTTP2) { | 904 if (spdy_version() < HTTP2) { |
| 909 block[GetHostKey()] = (host_port_pair.port() == 443) | 905 block[GetHostKey()] = (host_port_pair.port() == 443) |
| 910 ? host_port_pair.host() | 906 ? host_port_pair.host() |
| 911 : host_port_pair.ToString(); | 907 : host_port_pair.ToString(); |
| 912 block[GetPathKey()] = host_port_pair.ToString(); | 908 block[GetPathKey()] = host_port_pair.ToString(); |
| 913 } else { | 909 } else { |
| 914 block[GetHostKey()] = host_port_pair.ToString(); | 910 block[GetHostKey()] = host_port_pair.ToString(); |
| 915 } | 911 } |
| 916 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 912 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 917 return ConstructSpdySyn(stream_id, block, priority, false); | 913 return ConstructSpdySyn(stream_id, std::move(block), priority, false); |
| 918 } | 914 } |
| 919 | 915 |
| 920 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( | 916 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( |
| 921 const char* const extra_headers[], | 917 const char* const extra_headers[], |
| 922 int extra_header_count, | 918 int extra_header_count, |
| 923 int stream_id, | 919 int stream_id, |
| 924 int associated_stream_id, | 920 int associated_stream_id, |
| 925 const char* url) { | 921 const char* url) { |
| 926 if (spdy_version() < HTTP2) { | 922 if (spdy_version() < HTTP2) { |
| 927 SpdySynStreamIR syn_stream(stream_id); | 923 SpdySynStreamIR syn_stream(stream_id); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 &push_promise_frame, &headers_frame, | 997 &push_promise_frame, &headers_frame, |
| 1002 }; | 998 }; |
| 1003 int combined_size = | 999 int combined_size = |
| 1004 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); | 1000 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 1005 DCHECK_EQ(combined_size, joint_data_size); | 1001 DCHECK_EQ(combined_size, joint_data_size); |
| 1006 return new SpdySerializedFrame(data.release(), joint_data_size, true); | 1002 return new SpdySerializedFrame(data.release(), joint_data_size, true); |
| 1007 } | 1003 } |
| 1008 } | 1004 } |
| 1009 | 1005 |
| 1010 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( | 1006 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( |
| 1011 std::unique_ptr<SpdyHeaderBlock> headers, | 1007 SpdyHeaderBlock headers, |
| 1012 int stream_id, | 1008 int stream_id, |
| 1013 int associated_stream_id) { | 1009 int associated_stream_id) { |
| 1014 if (spdy_version() < HTTP2) { | 1010 if (spdy_version() < HTTP2) { |
| 1015 SpdySynStreamIR syn_stream(stream_id); | 1011 SpdySynStreamIR syn_stream(stream_id, std::move(headers)); |
| 1016 syn_stream.set_associated_to_stream_id(associated_stream_id); | 1012 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 1017 SetPriority(LOWEST, &syn_stream); | 1013 SetPriority(LOWEST, &syn_stream); |
| 1018 syn_stream.set_header_block(*headers); | |
| 1019 return new SpdySerializedFrame( | 1014 return new SpdySerializedFrame( |
| 1020 response_spdy_framer_.SerializeFrame(syn_stream)); | 1015 response_spdy_framer_.SerializeFrame(syn_stream)); |
| 1021 } else { | 1016 } else { |
| 1022 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 1017 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id, |
| 1023 push_promise.set_header_block(*headers); | 1018 std::move(headers)); |
| 1024 return new SpdySerializedFrame( | 1019 return new SpdySerializedFrame( |
| 1025 response_spdy_framer_.SerializeFrame(push_promise)); | 1020 response_spdy_framer_.SerializeFrame(push_promise)); |
| 1026 } | 1021 } |
| 1027 } | 1022 } |
| 1028 | 1023 |
| 1029 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( | 1024 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( |
| 1030 int stream_id, | 1025 int stream_id, |
| 1031 const char* const extra_headers[], | 1026 const char* const extra_headers[], |
| 1032 int extra_header_count) { | 1027 int extra_header_count) { |
| 1033 SpdyHeadersIR headers(stream_id); | 1028 SpdyHeaderBlock header_block; |
| 1034 headers.SetHeader(GetStatusKey(), "200"); | 1029 MaybeAddVersionHeader(&header_block); |
| 1035 MaybeAddVersionHeader(&headers); | 1030 header_block[GetStatusKey()] = "200"; |
| 1036 AppendToHeaderBlock(extra_headers, extra_header_count, | 1031 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block); |
| 1037 headers.mutable_header_block()); | 1032 SpdyHeadersIR headers(stream_id, std::move(header_block)); |
| 1038 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); | 1033 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); |
| 1039 } | 1034 } |
| 1040 | 1035 |
| 1041 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( | 1036 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( |
| 1042 int stream_id, | 1037 int stream_id, |
| 1043 const SpdyHeaderBlock& headers, | 1038 SpdyHeaderBlock headers, |
| 1044 bool fin) { | 1039 bool fin) { |
| 1045 SpdyHeadersIR spdy_headers(stream_id); | 1040 SpdyHeadersIR spdy_headers(stream_id, std::move(headers)); |
| 1046 spdy_headers.set_header_block(headers); | |
| 1047 spdy_headers.set_fin(fin); | 1041 spdy_headers.set_fin(fin); |
| 1048 return new SpdySerializedFrame( | 1042 return new SpdySerializedFrame( |
| 1049 response_spdy_framer_.SerializeFrame(spdy_headers)); | 1043 response_spdy_framer_.SerializeFrame(spdy_headers)); |
| 1050 } | 1044 } |
| 1051 | 1045 |
| 1052 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn( | 1046 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, |
| 1053 int stream_id, | 1047 SpdyHeaderBlock block, |
| 1054 const SpdyHeaderBlock& block, | 1048 RequestPriority priority, |
| 1055 RequestPriority priority, | 1049 bool fin) { |
| 1056 bool fin) { | |
| 1057 // Get the stream id of the next highest priority request | 1050 // Get the stream id of the next highest priority request |
| 1058 // (most recent request of the same priority, or last request of | 1051 // (most recent request of the same priority, or last request of |
| 1059 // an earlier priority). | 1052 // an earlier priority). |
| 1060 // Note that this is a duplicate of the logic in Http2PriorityDependencies | 1053 // Note that this is a duplicate of the logic in Http2PriorityDependencies |
| 1061 // (slightly transformed as this is based on RequestPriority and that logic | 1054 // (slightly transformed as this is based on RequestPriority and that logic |
| 1062 // on SpdyPriority, but only slightly transformed) and hence tests using | 1055 // on SpdyPriority, but only slightly transformed) and hence tests using |
| 1063 // this function do not effectively test that logic. | 1056 // this function do not effectively test that logic. |
| 1064 // That logic is tested by the Http2PriorityDependencies unit tests. | 1057 // That logic is tested by the Http2PriorityDependencies unit tests. |
| 1065 int parent_stream_id = 0; | 1058 int parent_stream_id = 0; |
| 1066 for (int q = priority; q <= HIGHEST; ++q) { | 1059 for (int q = priority; q <= HIGHEST; ++q) { |
| 1067 if (!priority_to_stream_id_list_[q].empty()) { | 1060 if (!priority_to_stream_id_list_[q].empty()) { |
| 1068 parent_stream_id = priority_to_stream_id_list_[q].back(); | 1061 parent_stream_id = priority_to_stream_id_list_[q].back(); |
| 1069 break; | 1062 break; |
| 1070 } | 1063 } |
| 1071 } | 1064 } |
| 1072 | 1065 |
| 1073 priority_to_stream_id_list_[priority].push_back(stream_id); | 1066 priority_to_stream_id_list_[priority].push_back(stream_id); |
| 1074 | 1067 |
| 1075 if (protocol_ < kProtoHTTP2) { | 1068 if (protocol_ < kProtoHTTP2) { |
| 1076 SpdySynStreamIR syn_stream(stream_id); | 1069 SpdySynStreamIR syn_stream(stream_id, std::move(block)); |
| 1077 syn_stream.set_header_block(block); | |
| 1078 syn_stream.set_priority( | 1070 syn_stream.set_priority( |
| 1079 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1071 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1080 syn_stream.set_fin(fin); | 1072 syn_stream.set_fin(fin); |
| 1081 return new SpdySerializedFrame( | 1073 return new SpdySerializedFrame( |
| 1082 request_spdy_framer_.SerializeFrame(syn_stream)); | 1074 request_spdy_framer_.SerializeFrame(syn_stream)); |
| 1083 } else { | 1075 } else { |
| 1084 SpdyHeadersIR headers(stream_id); | 1076 SpdyHeadersIR headers(stream_id, std::move(block)); |
| 1085 headers.set_header_block(block); | |
| 1086 headers.set_has_priority(true); | 1077 headers.set_has_priority(true); |
| 1087 headers.set_weight(Spdy3PriorityToHttp2Weight( | 1078 headers.set_weight(Spdy3PriorityToHttp2Weight( |
| 1088 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()))); | 1079 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()))); |
| 1089 if (dependency_priorities_) { | 1080 if (dependency_priorities_) { |
| 1090 headers.set_parent_stream_id(parent_stream_id); | 1081 headers.set_parent_stream_id(parent_stream_id); |
| 1091 headers.set_exclusive(true); | 1082 headers.set_exclusive(true); |
| 1092 } | 1083 } |
| 1093 headers.set_fin(fin); | 1084 headers.set_fin(fin); |
| 1094 return new SpdySerializedFrame( | 1085 return new SpdySerializedFrame( |
| 1095 request_spdy_framer_.SerializeFrame(headers)); | 1086 request_spdy_framer_.SerializeFrame(headers)); |
| 1096 } | 1087 } |
| 1097 } | 1088 } |
| 1098 | 1089 |
| 1099 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply( | 1090 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, |
| 1100 int stream_id, | 1091 SpdyHeaderBlock headers) { |
| 1101 const SpdyHeaderBlock& headers) { | |
| 1102 if (protocol_ < kProtoHTTP2) { | 1092 if (protocol_ < kProtoHTTP2) { |
| 1103 SpdySynReplyIR syn_reply(stream_id); | 1093 SpdySynReplyIR syn_reply(stream_id, std::move(headers)); |
| 1104 syn_reply.set_header_block(headers); | |
| 1105 return new SpdySerializedFrame( | 1094 return new SpdySerializedFrame( |
| 1106 response_spdy_framer_.SerializeFrame(syn_reply)); | 1095 response_spdy_framer_.SerializeFrame(syn_reply)); |
| 1107 } else { | 1096 } else { |
| 1108 SpdyHeadersIR reply(stream_id); | 1097 SpdyHeadersIR reply(stream_id, std::move(headers)); |
| 1109 reply.set_header_block(headers); | |
| 1110 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); | 1098 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); |
| 1111 } | 1099 } |
| 1112 } | 1100 } |
| 1113 | 1101 |
| 1114 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( | 1102 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( |
| 1115 const char* const status, | 1103 const char* const status, |
| 1116 const char* const* const extra_headers, | 1104 const char* const* const extra_headers, |
| 1117 int extra_header_count, | 1105 int extra_header_count, |
| 1118 int stream_id) { | 1106 int stream_id) { |
| 1119 SpdyHeaderBlock block; | 1107 SpdyHeaderBlock block; |
| 1120 block[GetStatusKey()] = status; | 1108 block[GetStatusKey()] = status; |
| 1121 MaybeAddVersionHeader(&block); | 1109 MaybeAddVersionHeader(&block); |
| 1122 block["hello"] = "bye"; | 1110 block["hello"] = "bye"; |
| 1123 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1111 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1124 | 1112 |
| 1125 return ConstructSpdyReply(stream_id, block); | 1113 return ConstructSpdyReply(stream_id, std::move(block)); |
| 1126 } | 1114 } |
| 1127 | 1115 |
| 1128 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( | 1116 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( |
| 1129 int stream_id) { | 1117 int stream_id) { |
| 1130 static const char* const kExtraHeaders[] = { | 1118 static const char* const kExtraHeaders[] = { |
| 1131 "location", "http://www.foo.com/index.php", | 1119 "location", "http://www.foo.com/index.php", |
| 1132 }; | 1120 }; |
| 1133 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 1121 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, |
| 1134 arraysize(kExtraHeaders)/2, stream_id); | 1122 arraysize(kExtraHeaders)/2, stream_id); |
| 1135 } | 1123 } |
| 1136 | 1124 |
| 1137 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { | 1125 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { |
| 1138 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 1126 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
| 1139 } | 1127 } |
| 1140 | 1128 |
| 1141 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( | 1129 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( |
| 1142 const char* const extra_headers[], | 1130 const char* const extra_headers[], |
| 1143 int extra_header_count, | 1131 int extra_header_count, |
| 1144 int stream_id) { | 1132 int stream_id) { |
| 1145 SpdyHeaderBlock block; | 1133 SpdyHeaderBlock block; |
| 1146 block[GetStatusKey()] = "200"; | 1134 block[GetStatusKey()] = "200"; |
| 1147 MaybeAddVersionHeader(&block); | 1135 MaybeAddVersionHeader(&block); |
| 1148 block["hello"] = "bye"; | 1136 block["hello"] = "bye"; |
| 1149 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1137 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1150 | 1138 |
| 1151 return ConstructSpdyReply(stream_id, block); | 1139 return ConstructSpdyReply(stream_id, std::move(block)); |
| 1152 } | 1140 } |
| 1153 | 1141 |
| 1154 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( | 1142 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( |
| 1155 const char* url, | 1143 const char* url, |
| 1156 SpdyStreamId stream_id, | 1144 SpdyStreamId stream_id, |
| 1157 int64_t content_length, | 1145 int64_t content_length, |
| 1158 RequestPriority priority, | 1146 RequestPriority priority, |
| 1159 const char* const extra_headers[], | 1147 const char* const extra_headers[], |
| 1160 int extra_header_count) { | 1148 int extra_header_count) { |
| 1161 std::unique_ptr<SpdyHeaderBlock> block( | 1149 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length)); |
| 1162 ConstructPostHeaderBlock(url, content_length)); | 1150 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1163 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); | 1151 return ConstructSpdySyn(stream_id, std::move(block), priority, false); |
| 1164 return ConstructSpdySyn(stream_id, *block, priority, false); | |
| 1165 } | 1152 } |
| 1166 | 1153 |
| 1167 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( | 1154 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( |
| 1168 const char* const extra_headers[], | 1155 const char* const extra_headers[], |
| 1169 int extra_header_count) { | 1156 int extra_header_count) { |
| 1170 SpdyHeaderBlock block; | 1157 SpdyHeaderBlock block; |
| 1171 MaybeAddVersionHeader(&block); | 1158 MaybeAddVersionHeader(&block); |
| 1172 block[GetMethodKey()] = "POST"; | 1159 block[GetMethodKey()] = "POST"; |
| 1173 AddUrlToHeaderBlock(default_url_.spec(), &block); | 1160 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 1174 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1161 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1175 return ConstructSpdySyn(1, block, LOWEST, false); | 1162 return ConstructSpdySyn(1, std::move(block), LOWEST, false); |
| 1176 } | 1163 } |
| 1177 | 1164 |
| 1178 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( | 1165 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( |
| 1179 const char* const extra_headers[], | 1166 const char* const extra_headers[], |
| 1180 int extra_header_count) { | 1167 int extra_header_count) { |
| 1181 // TODO(jgraettinger): Remove this method. | 1168 // TODO(jgraettinger): Remove this method. |
| 1182 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); | 1169 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); |
| 1183 } | 1170 } |
| 1184 | 1171 |
| 1185 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1172 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 } | 1245 } |
| 1259 | 1246 |
| 1260 const char* SpdyTestUtil::GetVersionKey() const { | 1247 const char* SpdyTestUtil::GetVersionKey() const { |
| 1261 return ":version"; | 1248 return ":version"; |
| 1262 } | 1249 } |
| 1263 | 1250 |
| 1264 const char* SpdyTestUtil::GetPathKey() const { | 1251 const char* SpdyTestUtil::GetPathKey() const { |
| 1265 return ":path"; | 1252 return ":path"; |
| 1266 } | 1253 } |
| 1267 | 1254 |
| 1268 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( | 1255 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock( |
| 1269 base::StringPiece method, | 1256 base::StringPiece method, |
| 1270 base::StringPiece url, | 1257 base::StringPiece url, |
| 1271 int64_t* content_length) const { | 1258 int64_t* content_length) const { |
| 1272 std::string scheme, host, path; | 1259 std::string scheme, host, path; |
| 1273 ParseUrl(url.data(), &scheme, &host, &path); | 1260 ParseUrl(url.data(), &scheme, &host, &path); |
| 1274 std::unique_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 1261 SpdyHeaderBlock headers; |
| 1275 if (include_version_header()) { | 1262 if (include_version_header()) { |
| 1276 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1263 headers[GetVersionKey()] = "HTTP/1.1"; |
| 1277 } | 1264 } |
| 1278 (*headers)[GetMethodKey()] = method.as_string(); | 1265 headers[GetMethodKey()] = method.as_string(); |
| 1279 (*headers)[GetHostKey()] = host.c_str(); | 1266 headers[GetHostKey()] = host.c_str(); |
| 1280 (*headers)[GetSchemeKey()] = scheme.c_str(); | 1267 headers[GetSchemeKey()] = scheme.c_str(); |
| 1281 (*headers)[GetPathKey()] = path.c_str(); | 1268 headers[GetPathKey()] = path.c_str(); |
| 1282 if (content_length) { | 1269 if (content_length) { |
| 1283 std::string length_str = base::Int64ToString(*content_length); | 1270 std::string length_str = base::Int64ToString(*content_length); |
| 1284 (*headers)["content-length"] = length_str; | 1271 headers["content-length"] = length_str; |
| 1285 } | 1272 } |
| 1286 return headers; | 1273 return headers; |
| 1287 } | 1274 } |
| 1288 | 1275 |
| 1289 void SpdyTestUtil::MaybeAddVersionHeader( | |
| 1290 SpdyFrameWithHeaderBlockIR* frame_ir) const { | |
| 1291 if (include_version_header()) { | |
| 1292 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); | |
| 1293 } | |
| 1294 } | |
| 1295 | |
| 1296 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { | 1276 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { |
| 1297 if (include_version_header()) { | 1277 if (include_version_header()) { |
| 1298 (*block)[GetVersionKey()] = "HTTP/1.1"; | 1278 (*block)[GetVersionKey()] = "HTTP/1.1"; |
| 1299 } | 1279 } |
| 1300 } | 1280 } |
| 1301 | 1281 |
| 1302 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1282 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1303 SpdySynStreamIR* ir) const { | 1283 SpdySynStreamIR* ir) const { |
| 1304 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1284 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1305 priority, spdy_version())); | 1285 priority, spdy_version())); |
| 1306 } | 1286 } |
| 1307 | 1287 |
| 1308 } // namespace net | 1288 } // namespace net |
| OLD | NEW |