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

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

Issue 2096713002: Reduce SpdyHeaderBlock copies with move semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clear() does not work after all. Created 4 years, 5 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
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/tools/flip_server/spdy_interface.cc » ('j') | 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) 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
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
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 SpdyHeaderBlock header_block; 923 SpdyHeaderBlock header_block;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 &push_promise_frame, &headers_frame, 1003 &push_promise_frame, &headers_frame,
1008 }; 1004 };
1009 int combined_size = 1005 int combined_size =
1010 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); 1006 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
1011 DCHECK_EQ(combined_size, joint_data_size); 1007 DCHECK_EQ(combined_size, joint_data_size);
1012 return new SpdySerializedFrame(data.release(), joint_data_size, true); 1008 return new SpdySerializedFrame(data.release(), joint_data_size, true);
1013 } 1009 }
1014 } 1010 }
1015 1011
1016 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( 1012 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame(
1017 std::unique_ptr<SpdyHeaderBlock> headers, 1013 SpdyHeaderBlock headers,
1018 int stream_id, 1014 int stream_id,
1019 int associated_stream_id) { 1015 int associated_stream_id) {
1020 if (spdy_version() < HTTP2) { 1016 if (spdy_version() < HTTP2) {
1021 SpdySynStreamIR syn_stream(stream_id); 1017 SpdySynStreamIR syn_stream(stream_id, std::move(headers));
1022 syn_stream.set_associated_to_stream_id(associated_stream_id); 1018 syn_stream.set_associated_to_stream_id(associated_stream_id);
1023 SetPriority(LOWEST, &syn_stream); 1019 SetPriority(LOWEST, &syn_stream);
1024 syn_stream.set_header_block(*headers);
1025 return new SpdySerializedFrame( 1020 return new SpdySerializedFrame(
1026 response_spdy_framer_.SerializeFrame(syn_stream)); 1021 response_spdy_framer_.SerializeFrame(syn_stream));
1027 } else { 1022 } else {
1028 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); 1023 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id,
1029 push_promise.set_header_block(*headers); 1024 std::move(headers));
1030 return new SpdySerializedFrame( 1025 return new SpdySerializedFrame(
1031 response_spdy_framer_.SerializeFrame(push_promise)); 1026 response_spdy_framer_.SerializeFrame(push_promise));
1032 } 1027 }
1033 } 1028 }
1034 1029
1035 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( 1030 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders(
1036 int stream_id, 1031 int stream_id,
1037 const char* const extra_headers[], 1032 const char* const extra_headers[],
1038 int extra_header_count) { 1033 int extra_header_count) {
1039 SpdyHeaderBlock header_block; 1034 SpdyHeaderBlock header_block;
1040 header_block[GetStatusKey()] = "200"; 1035 header_block[GetStatusKey()] = "200";
1041 MaybeAddVersionHeader(&header_block); 1036 MaybeAddVersionHeader(&header_block);
1042 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block); 1037 AppendToHeaderBlock(extra_headers, extra_header_count, &header_block);
1043 SpdyHeadersIR headers(stream_id, std::move(header_block)); 1038 SpdyHeadersIR headers(stream_id, std::move(header_block));
1044 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); 1039 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers));
1045 } 1040 }
1046 1041
1047 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( 1042 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders(
1048 int stream_id, 1043 int stream_id,
1049 const SpdyHeaderBlock& headers, 1044 SpdyHeaderBlock headers,
1050 bool fin) { 1045 bool fin) {
1051 SpdyHeadersIR spdy_headers(stream_id); 1046 SpdyHeadersIR spdy_headers(stream_id, std::move(headers));
1052 spdy_headers.set_header_block(headers);
1053 spdy_headers.set_fin(fin); 1047 spdy_headers.set_fin(fin);
1054 return new SpdySerializedFrame( 1048 return new SpdySerializedFrame(
1055 response_spdy_framer_.SerializeFrame(spdy_headers)); 1049 response_spdy_framer_.SerializeFrame(spdy_headers));
1056 } 1050 }
1057 1051
1058 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn( 1052 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id,
1059 int stream_id, 1053 SpdyHeaderBlock block,
1060 const SpdyHeaderBlock& block, 1054 RequestPriority priority,
1061 RequestPriority priority, 1055 bool fin) {
1062 bool fin) {
1063 // Get the stream id of the next highest priority request 1056 // Get the stream id of the next highest priority request
1064 // (most recent request of the same priority, or last request of 1057 // (most recent request of the same priority, or last request of
1065 // an earlier priority). 1058 // an earlier priority).
1066 // Note that this is a duplicate of the logic in Http2PriorityDependencies 1059 // Note that this is a duplicate of the logic in Http2PriorityDependencies
1067 // (slightly transformed as this is based on RequestPriority and that logic 1060 // (slightly transformed as this is based on RequestPriority and that logic
1068 // on SpdyPriority, but only slightly transformed) and hence tests using 1061 // on SpdyPriority, but only slightly transformed) and hence tests using
1069 // this function do not effectively test that logic. 1062 // this function do not effectively test that logic.
1070 // That logic is tested by the Http2PriorityDependencies unit tests. 1063 // That logic is tested by the Http2PriorityDependencies unit tests.
1071 int parent_stream_id = 0; 1064 int parent_stream_id = 0;
1072 for (int q = priority; q <= HIGHEST; ++q) { 1065 for (int q = priority; q <= HIGHEST; ++q) {
1073 if (!priority_to_stream_id_list_[q].empty()) { 1066 if (!priority_to_stream_id_list_[q].empty()) {
1074 parent_stream_id = priority_to_stream_id_list_[q].back(); 1067 parent_stream_id = priority_to_stream_id_list_[q].back();
1075 break; 1068 break;
1076 } 1069 }
1077 } 1070 }
1078 1071
1079 priority_to_stream_id_list_[priority].push_back(stream_id); 1072 priority_to_stream_id_list_[priority].push_back(stream_id);
1080 1073
1081 if (protocol_ < kProtoHTTP2) { 1074 if (protocol_ < kProtoHTTP2) {
1082 SpdySynStreamIR syn_stream(stream_id); 1075 SpdySynStreamIR syn_stream(stream_id, std::move(block));
1083 syn_stream.set_header_block(block);
1084 syn_stream.set_priority( 1076 syn_stream.set_priority(
1085 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); 1077 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()));
1086 syn_stream.set_fin(fin); 1078 syn_stream.set_fin(fin);
1087 return new SpdySerializedFrame( 1079 return new SpdySerializedFrame(
1088 request_spdy_framer_.SerializeFrame(syn_stream)); 1080 request_spdy_framer_.SerializeFrame(syn_stream));
1089 } else { 1081 } else {
1090 SpdyHeadersIR headers(stream_id); 1082 SpdyHeadersIR headers(stream_id, std::move(block));
1091 headers.set_header_block(block);
1092 headers.set_has_priority(true); 1083 headers.set_has_priority(true);
1093 headers.set_weight(Spdy3PriorityToHttp2Weight( 1084 headers.set_weight(Spdy3PriorityToHttp2Weight(
1094 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()))); 1085 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())));
1095 if (dependency_priorities_) { 1086 if (dependency_priorities_) {
1096 headers.set_parent_stream_id(parent_stream_id); 1087 headers.set_parent_stream_id(parent_stream_id);
1097 headers.set_exclusive(true); 1088 headers.set_exclusive(true);
1098 } 1089 }
1099 headers.set_fin(fin); 1090 headers.set_fin(fin);
1100 return new SpdySerializedFrame( 1091 return new SpdySerializedFrame(
1101 request_spdy_framer_.SerializeFrame(headers)); 1092 request_spdy_framer_.SerializeFrame(headers));
1102 } 1093 }
1103 } 1094 }
1104 1095
1105 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply( 1096 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id,
1106 int stream_id, 1097 SpdyHeaderBlock headers) {
1107 const SpdyHeaderBlock& headers) {
1108 if (protocol_ < kProtoHTTP2) { 1098 if (protocol_ < kProtoHTTP2) {
1109 SpdySynReplyIR syn_reply(stream_id); 1099 SpdySynReplyIR syn_reply(stream_id, std::move(headers));
1110 syn_reply.set_header_block(headers);
1111 return new SpdySerializedFrame( 1100 return new SpdySerializedFrame(
1112 response_spdy_framer_.SerializeFrame(syn_reply)); 1101 response_spdy_framer_.SerializeFrame(syn_reply));
1113 } else { 1102 } else {
1114 SpdyHeadersIR reply(stream_id); 1103 SpdyHeadersIR reply(stream_id, std::move(headers));
1115 reply.set_header_block(headers);
1116 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); 1104 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply));
1117 } 1105 }
1118 } 1106 }
1119 1107
1120 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( 1108 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(
1121 const char* const status, 1109 const char* const status,
1122 const char* const* const extra_headers, 1110 const char* const* const extra_headers,
1123 int extra_header_count, 1111 int extra_header_count,
1124 int stream_id) { 1112 int stream_id) {
1125 SpdyHeaderBlock block; 1113 SpdyHeaderBlock block;
1126 block[GetStatusKey()] = status; 1114 block[GetStatusKey()] = status;
1127 MaybeAddVersionHeader(&block); 1115 MaybeAddVersionHeader(&block);
1128 block["hello"] = "bye"; 1116 block["hello"] = "bye";
1129 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1117 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1130 1118
1131 return ConstructSpdyReply(stream_id, block); 1119 return ConstructSpdyReply(stream_id, std::move(block));
1132 } 1120 }
1133 1121
1134 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( 1122 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(
1135 int stream_id) { 1123 int stream_id) {
1136 static const char* const kExtraHeaders[] = { 1124 static const char* const kExtraHeaders[] = {
1137 "location", "http://www.foo.com/index.php", 1125 "location", "http://www.foo.com/index.php",
1138 }; 1126 };
1139 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 1127 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
1140 arraysize(kExtraHeaders)/2, stream_id); 1128 arraysize(kExtraHeaders)/2, stream_id);
1141 } 1129 }
1142 1130
1143 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { 1131 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) {
1144 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 1132 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
1145 } 1133 }
1146 1134
1147 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( 1135 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply(
1148 const char* const extra_headers[], 1136 const char* const extra_headers[],
1149 int extra_header_count, 1137 int extra_header_count,
1150 int stream_id) { 1138 int stream_id) {
1151 SpdyHeaderBlock block; 1139 SpdyHeaderBlock block;
1152 block[GetStatusKey()] = "200"; 1140 block[GetStatusKey()] = "200";
1153 MaybeAddVersionHeader(&block); 1141 MaybeAddVersionHeader(&block);
1154 block["hello"] = "bye"; 1142 block["hello"] = "bye";
1155 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1143 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1156 1144
1157 return ConstructSpdyReply(stream_id, block); 1145 return ConstructSpdyReply(stream_id, std::move(block));
1158 } 1146 }
1159 1147
1160 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( 1148 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost(
1161 const char* url, 1149 const char* url,
1162 SpdyStreamId stream_id, 1150 SpdyStreamId stream_id,
1163 int64_t content_length, 1151 int64_t content_length,
1164 RequestPriority priority, 1152 RequestPriority priority,
1165 const char* const extra_headers[], 1153 const char* const extra_headers[],
1166 int extra_header_count) { 1154 int extra_header_count) {
1167 std::unique_ptr<SpdyHeaderBlock> block( 1155 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length));
1168 ConstructPostHeaderBlock(url, content_length)); 1156 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1169 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); 1157 return ConstructSpdySyn(stream_id, std::move(block), priority, false);
1170 return ConstructSpdySyn(stream_id, *block, priority, false);
1171 } 1158 }
1172 1159
1173 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( 1160 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost(
1174 const char* const extra_headers[], 1161 const char* const extra_headers[],
1175 int extra_header_count) { 1162 int extra_header_count) {
1176 SpdyHeaderBlock block; 1163 SpdyHeaderBlock block;
1177 MaybeAddVersionHeader(&block); 1164 MaybeAddVersionHeader(&block);
1178 block[GetMethodKey()] = "POST"; 1165 block[GetMethodKey()] = "POST";
1179 AddUrlToHeaderBlock(default_url_.spec(), &block); 1166 AddUrlToHeaderBlock(default_url_.spec(), &block);
1180 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1167 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1181 return ConstructSpdySyn(1, block, LOWEST, false); 1168 return ConstructSpdySyn(1, std::move(block), LOWEST, false);
1182 } 1169 }
1183 1170
1184 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( 1171 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply(
1185 const char* const extra_headers[], 1172 const char* const extra_headers[],
1186 int extra_header_count) { 1173 int extra_header_count) {
1187 // TODO(jgraettinger): Remove this method. 1174 // TODO(jgraettinger): Remove this method.
1188 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); 1175 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1);
1189 } 1176 }
1190 1177
1191 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, 1178 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 } 1251 }
1265 1252
1266 const char* SpdyTestUtil::GetVersionKey() const { 1253 const char* SpdyTestUtil::GetVersionKey() const {
1267 return ":version"; 1254 return ":version";
1268 } 1255 }
1269 1256
1270 const char* SpdyTestUtil::GetPathKey() const { 1257 const char* SpdyTestUtil::GetPathKey() const {
1271 return ":path"; 1258 return ":path";
1272 } 1259 }
1273 1260
1274 std::unique_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( 1261 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock(
1275 base::StringPiece method, 1262 base::StringPiece method,
1276 base::StringPiece url, 1263 base::StringPiece url,
1277 int64_t* content_length) const { 1264 int64_t* content_length) const {
1278 std::string scheme, host, path; 1265 std::string scheme, host, path;
1279 ParseUrl(url.data(), &scheme, &host, &path); 1266 ParseUrl(url.data(), &scheme, &host, &path);
1280 std::unique_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); 1267 SpdyHeaderBlock headers;
1281 if (include_version_header()) { 1268 if (include_version_header()) {
1282 (*headers)[GetVersionKey()] = "HTTP/1.1"; 1269 headers[GetVersionKey()] = "HTTP/1.1";
1283 } 1270 }
1284 (*headers)[GetMethodKey()] = method.as_string(); 1271 headers[GetMethodKey()] = method.as_string();
1285 (*headers)[GetHostKey()] = host.c_str(); 1272 headers[GetHostKey()] = host.c_str();
1286 (*headers)[GetSchemeKey()] = scheme.c_str(); 1273 headers[GetSchemeKey()] = scheme.c_str();
1287 (*headers)[GetPathKey()] = path.c_str(); 1274 headers[GetPathKey()] = path.c_str();
1288 if (content_length) { 1275 if (content_length) {
1289 std::string length_str = base::Int64ToString(*content_length); 1276 std::string length_str = base::Int64ToString(*content_length);
1290 (*headers)["content-length"] = length_str; 1277 headers["content-length"] = length_str;
1291 } 1278 }
1292 return headers; 1279 return headers;
1293 } 1280 }
1294 1281
1295 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { 1282 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const {
1296 if (include_version_header()) { 1283 if (include_version_header()) {
1297 (*block)[GetVersionKey()] = "HTTP/1.1"; 1284 (*block)[GetVersionKey()] = "HTTP/1.1";
1298 } 1285 }
1299 } 1286 }
1300 1287
1301 void SpdyTestUtil::SetPriority(RequestPriority priority, 1288 void SpdyTestUtil::SetPriority(RequestPriority priority,
1302 SpdySynStreamIR* ir) const { 1289 SpdySynStreamIR* ir) const {
1303 ir->set_priority(ConvertRequestPriorityToSpdyPriority( 1290 ir->set_priority(ConvertRequestPriorityToSpdyPriority(
1304 priority, spdy_version())); 1291 priority, spdy_version()));
1305 } 1292 }
1306 1293
1307 } // namespace net 1294 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/tools/flip_server/spdy_interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698