| 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 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 host->append(":"); | 51 host->append(":"); |
| 52 host->append(gurl.port()); | 52 host->append(gurl.port()); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 // Chop a frame into an array of MockWrites. | 58 // Chop a frame into an array of MockWrites. |
| 59 // |frame| is the frame to chop. | 59 // |frame| is the frame to chop. |
| 60 // |num_chunks| is the number of chunks to create. | 60 // |num_chunks| is the number of chunks to create. |
| 61 MockWrite* ChopWriteFrame(const SpdyFrame& frame, int num_chunks) { | 61 MockWrite* ChopWriteFrame(const SpdySerializedFrame& frame, int num_chunks) { |
| 62 MockWrite* chunks = new MockWrite[num_chunks]; | 62 MockWrite* chunks = new MockWrite[num_chunks]; |
| 63 int chunk_size = frame.size() / num_chunks; | 63 int chunk_size = frame.size() / num_chunks; |
| 64 for (int index = 0; index < num_chunks; index++) { | 64 for (int index = 0; index < num_chunks; index++) { |
| 65 const char* ptr = frame.data() + (index * chunk_size); | 65 const char* ptr = frame.data() + (index * chunk_size); |
| 66 if (index == num_chunks - 1) | 66 if (index == num_chunks - 1) |
| 67 chunk_size += | 67 chunk_size += |
| 68 frame.size() % chunk_size; // The last chunk takes the remainder. | 68 frame.size() % chunk_size; // The last chunk takes the remainder. |
| 69 chunks[index] = MockWrite(ASYNC, ptr, chunk_size); | 69 chunks[index] = MockWrite(ASYNC, ptr, chunk_size); |
| 70 } | 70 } |
| 71 return chunks; | 71 return chunks; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Append the new value. | 111 // Append the new value. |
| 112 new_value += this_value; | 112 new_value += this_value; |
| 113 } else { | 113 } else { |
| 114 // Not a duplicate, just write the value. | 114 // Not a duplicate, just write the value. |
| 115 new_value = this_value; | 115 new_value = this_value; |
| 116 } | 116 } |
| 117 (*headers)[this_header] = new_value; | 117 (*headers)[this_header] = new_value; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Create a MockWrite from the given SpdyFrame. | 121 // Create a MockWrite from the given SpdySerializedFrame. |
| 122 MockWrite CreateMockWrite(const SpdyFrame& req) { | 122 MockWrite CreateMockWrite(const SpdySerializedFrame& req) { |
| 123 return MockWrite(ASYNC, req.data(), req.size()); | 123 return MockWrite(ASYNC, req.data(), req.size()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Create a MockWrite from the given SpdyFrame and sequence number. | 126 // Create a MockWrite from the given SpdySerializedFrame and sequence number. |
| 127 MockWrite CreateMockWrite(const SpdyFrame& req, int seq) { | 127 MockWrite CreateMockWrite(const SpdySerializedFrame& req, int seq) { |
| 128 return CreateMockWrite(req, seq, ASYNC); | 128 return CreateMockWrite(req, seq, ASYNC); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Create a MockWrite from the given SpdyFrame and sequence number. | 131 // Create a MockWrite from the given SpdySerializedFrame and sequence number. |
| 132 MockWrite CreateMockWrite(const SpdyFrame& req, int seq, IoMode mode) { | 132 MockWrite CreateMockWrite(const SpdySerializedFrame& req, |
| 133 int seq, |
| 134 IoMode mode) { |
| 133 return MockWrite(mode, req.data(), req.size(), seq); | 135 return MockWrite(mode, req.data(), req.size(), seq); |
| 134 } | 136 } |
| 135 | 137 |
| 136 // Create a MockRead from the given SpdyFrame. | 138 // Create a MockRead from the given SpdySerializedFrame. |
| 137 MockRead CreateMockRead(const SpdyFrame& resp) { | 139 MockRead CreateMockRead(const SpdySerializedFrame& resp) { |
| 138 return MockRead(ASYNC, resp.data(), resp.size()); | 140 return MockRead(ASYNC, resp.data(), resp.size()); |
| 139 } | 141 } |
| 140 | 142 |
| 141 // Create a MockRead from the given SpdyFrame and sequence number. | 143 // Create a MockRead from the given SpdySerializedFrame and sequence number. |
| 142 MockRead CreateMockRead(const SpdyFrame& resp, int seq) { | 144 MockRead CreateMockRead(const SpdySerializedFrame& resp, int seq) { |
| 143 return CreateMockRead(resp, seq, ASYNC); | 145 return CreateMockRead(resp, seq, ASYNC); |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Create a MockRead from the given SpdyFrame and sequence number. | 148 // Create a MockRead from the given SpdySerializedFrame and sequence number. |
| 147 MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode) { | 149 MockRead CreateMockRead(const SpdySerializedFrame& resp, int seq, IoMode mode) { |
| 148 return MockRead(mode, resp.data(), resp.size(), seq); | 150 return MockRead(mode, resp.data(), resp.size(), seq); |
| 149 } | 151 } |
| 150 | 152 |
| 151 // Combines the given SpdyFrames into the given char array and returns | 153 // Combines the given SpdyFrames into the given char array and returns |
| 152 // the total length. | 154 // the total length. |
| 153 int CombineFrames(const SpdyFrame** frames, | 155 int CombineFrames(const SpdySerializedFrame** frames, |
| 154 int num_frames, | 156 int num_frames, |
| 155 char* buf, | 157 char* buf, |
| 156 int buf_len) { | 158 int buf_len) { |
| 157 int total_len = 0; | 159 int total_len = 0; |
| 158 for (int i = 0; i < num_frames; ++i) { | 160 for (int i = 0; i < num_frames; ++i) { |
| 159 total_len += frames[i]->size(); | 161 total_len += frames[i]->size(); |
| 160 } | 162 } |
| 161 DCHECK_LE(total_len, buf_len); | 163 DCHECK_LE(total_len, buf_len); |
| 162 char* ptr = buf; | 164 char* ptr = buf; |
| 163 for (int i = 0; i < num_frames; ++i) { | 165 for (int i = 0; i < num_frames; ++i) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return false; | 235 return false; |
| 234 } | 236 } |
| 235 | 237 |
| 236 private: | 238 private: |
| 237 SpdyPriority priority_; | 239 SpdyPriority priority_; |
| 238 }; | 240 }; |
| 239 | 241 |
| 240 } // namespace | 242 } // namespace |
| 241 | 243 |
| 242 bool GetSpdyPriority(SpdyMajorVersion version, | 244 bool GetSpdyPriority(SpdyMajorVersion version, |
| 243 const SpdyFrame& frame, | 245 const SpdySerializedFrame& frame, |
| 244 SpdyPriority* priority) { | 246 SpdyPriority* priority) { |
| 245 BufferedSpdyFramer framer(version); | 247 BufferedSpdyFramer framer(version); |
| 246 PriorityGetter priority_getter; | 248 PriorityGetter priority_getter; |
| 247 framer.set_visitor(&priority_getter); | 249 framer.set_visitor(&priority_getter); |
| 248 size_t frame_size = frame.size(); | 250 size_t frame_size = frame.size(); |
| 249 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { | 251 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { |
| 250 return false; | 252 return false; |
| 251 } | 253 } |
| 252 *priority = priority_getter.priority(); | 254 *priority = priority_getter.priority(); |
| 253 return true; | 255 return true; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 int64_t content_length) const { | 733 int64_t content_length) const { |
| 732 return ConstructHeaderBlock("POST", url, &content_length); | 734 return ConstructHeaderBlock("POST", url, &content_length); |
| 733 } | 735 } |
| 734 | 736 |
| 735 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPutHeaderBlock( | 737 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPutHeaderBlock( |
| 736 base::StringPiece url, | 738 base::StringPiece url, |
| 737 int64_t content_length) const { | 739 int64_t content_length) const { |
| 738 return ConstructHeaderBlock("PUT", url, &content_length); | 740 return ConstructHeaderBlock("PUT", url, &content_length); |
| 739 } | 741 } |
| 740 | 742 |
| 741 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame( | 743 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( |
| 742 const SpdyHeaderInfo& header_info, | 744 const SpdyHeaderInfo& header_info, |
| 743 scoped_ptr<SpdyHeaderBlock> headers) const { | 745 scoped_ptr<SpdyHeaderBlock> headers) const { |
| 744 BufferedSpdyFramer framer(spdy_version_); | 746 BufferedSpdyFramer framer(spdy_version_); |
| 745 SpdyFrame* frame = NULL; | 747 SpdySerializedFrame* frame = NULL; |
| 746 switch (header_info.kind) { | 748 switch (header_info.kind) { |
| 747 case DATA: | 749 case DATA: |
| 748 frame = framer.CreateDataFrame(header_info.id, header_info.data, | 750 frame = framer.CreateDataFrame(header_info.id, header_info.data, |
| 749 header_info.data_length, | 751 header_info.data_length, |
| 750 header_info.data_flags); | 752 header_info.data_flags); |
| 751 break; | 753 break; |
| 752 case SYN_STREAM: | 754 case SYN_STREAM: |
| 753 { | 755 { |
| 754 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, | 756 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, |
| 755 header_info.priority, | 757 header_info.priority, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 769 header_info.priority, | 771 header_info.priority, |
| 770 headers.get()); | 772 headers.get()); |
| 771 break; | 773 break; |
| 772 default: | 774 default: |
| 773 ADD_FAILURE(); | 775 ADD_FAILURE(); |
| 774 break; | 776 break; |
| 775 } | 777 } |
| 776 return frame; | 778 return frame; |
| 777 } | 779 } |
| 778 | 780 |
| 779 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, | 781 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( |
| 780 const char* const extra_headers[], | 782 const SpdyHeaderInfo& header_info, |
| 781 int extra_header_count, | 783 const char* const extra_headers[], |
| 782 const char* const tail_headers[], | 784 int extra_header_count, |
| 783 int tail_header_count) const { | 785 const char* const tail_headers[], |
| 786 int tail_header_count) const { |
| 784 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 787 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 785 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 788 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
| 786 if (tail_headers && tail_header_count) | 789 if (tail_headers && tail_header_count) |
| 787 AppendToHeaderBlock(tail_headers, tail_header_count, headers.get()); | 790 AppendToHeaderBlock(tail_headers, tail_header_count, headers.get()); |
| 788 return ConstructSpdyFrame(header_info, std::move(headers)); | 791 return ConstructSpdyFrame(header_info, std::move(headers)); |
| 789 } | 792 } |
| 790 | 793 |
| 791 std::string SpdyTestUtil::ConstructSpdyReplyString( | 794 std::string SpdyTestUtil::ConstructSpdyReplyString( |
| 792 const SpdyHeaderBlock& headers) const { | 795 const SpdyHeaderBlock& headers) const { |
| 793 std::string reply_string; | 796 std::string reply_string; |
| 794 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 797 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
| 795 it != headers.end(); ++it) { | 798 it != headers.end(); ++it) { |
| 796 std::string key = it->first.as_string(); | 799 std::string key = it->first.as_string(); |
| 797 // Remove leading colon from "special" headers (for SPDY3 and | 800 // Remove leading colon from "special" headers (for SPDY3 and |
| 798 // above). | 801 // above). |
| 799 if (spdy_version() >= SPDY3 && key[0] == ':') | 802 if (spdy_version() >= SPDY3 && key[0] == ':') |
| 800 key = key.substr(1); | 803 key = key.substr(1); |
| 801 for (const std::string& value : | 804 for (const std::string& value : |
| 802 base::SplitString(it->second, base::StringPiece("\0", 1), | 805 base::SplitString(it->second, base::StringPiece("\0", 1), |
| 803 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 806 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 804 reply_string += key + ": " + value + "\n"; | 807 reply_string += key + ": " + value + "\n"; |
| 805 } | 808 } |
| 806 } | 809 } |
| 807 return reply_string; | 810 return reply_string; |
| 808 } | 811 } |
| 809 | 812 |
| 810 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 813 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
| 811 // SpdySettingsIR). | 814 // SpdySettingsIR). |
| 812 SpdyFrame* SpdyTestUtil::ConstructSpdySettings(const SettingsMap& settings) { | 815 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettings( |
| 816 const SettingsMap& settings) { |
| 813 SpdySettingsIR settings_ir; | 817 SpdySettingsIR settings_ir; |
| 814 for (SettingsMap::const_iterator it = settings.begin(); | 818 for (SettingsMap::const_iterator it = settings.begin(); |
| 815 it != settings.end(); | 819 it != settings.end(); |
| 816 ++it) { | 820 ++it) { |
| 817 settings_ir.AddSetting( | 821 settings_ir.AddSetting( |
| 818 it->first, | 822 it->first, |
| 819 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, | 823 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, |
| 820 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, | 824 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, |
| 821 it->second.second); | 825 it->second.second); |
| 822 } | 826 } |
| 823 return headerless_spdy_framer_.SerializeFrame(settings_ir); | 827 return new SpdySerializedFrame( |
| 828 headerless_spdy_framer_.SerializeFrame(settings_ir)); |
| 824 } | 829 } |
| 825 | 830 |
| 826 SpdyFrame* SpdyTestUtil::ConstructSpdySettingsAck() { | 831 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySettingsAck() { |
| 827 char kEmptyWrite[] = ""; | 832 char kEmptyWrite[] = ""; |
| 828 | 833 |
| 829 if (spdy_version() > SPDY3) { | 834 if (spdy_version() > SPDY3) { |
| 830 SpdySettingsIR settings_ir; | 835 SpdySettingsIR settings_ir; |
| 831 settings_ir.set_is_ack(true); | 836 settings_ir.set_is_ack(true); |
| 832 return headerless_spdy_framer_.SerializeFrame(settings_ir); | 837 return new SpdySerializedFrame( |
| 838 headerless_spdy_framer_.SerializeFrame(settings_ir)); |
| 833 } | 839 } |
| 834 // No settings ACK write occurs. Create an empty placeholder write. | 840 // No settings ACK write occurs. Create an empty placeholder write. |
| 835 return new SpdyFrame(kEmptyWrite, 0, false); | 841 return new SpdySerializedFrame(kEmptyWrite, 0, false); |
| 836 } | 842 } |
| 837 | 843 |
| 838 SpdyFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id, bool is_ack) { | 844 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id, |
| 845 bool is_ack) { |
| 839 SpdyPingIR ping_ir(ping_id); | 846 SpdyPingIR ping_ir(ping_id); |
| 840 ping_ir.set_is_ack(is_ack); | 847 ping_ir.set_is_ack(is_ack); |
| 841 return headerless_spdy_framer_.SerializeFrame(ping_ir); | 848 return new SpdySerializedFrame( |
| 849 headerless_spdy_framer_.SerializeFrame(ping_ir)); |
| 842 } | 850 } |
| 843 | 851 |
| 844 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway() { | 852 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway() { |
| 845 return ConstructSpdyGoAway(0); | 853 return ConstructSpdyGoAway(0); |
| 846 } | 854 } |
| 847 | 855 |
| 848 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) { | 856 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway( |
| 857 SpdyStreamId last_good_stream_id) { |
| 849 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); | 858 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); |
| 850 return headerless_spdy_framer_.SerializeFrame(go_ir); | 859 return new SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); |
| 851 } | 860 } |
| 852 | 861 |
| 853 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway(SpdyStreamId last_good_stream_id, | 862 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGoAway( |
| 854 SpdyGoAwayStatus status, | 863 SpdyStreamId last_good_stream_id, |
| 855 const std::string& desc) { | 864 SpdyGoAwayStatus status, |
| 865 const std::string& desc) { |
| 856 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc); | 866 SpdyGoAwayIR go_ir(last_good_stream_id, status, desc); |
| 857 return headerless_spdy_framer_.SerializeFrame(go_ir); | 867 return new SpdySerializedFrame(headerless_spdy_framer_.SerializeFrame(go_ir)); |
| 858 } | 868 } |
| 859 | 869 |
| 860 SpdyFrame* SpdyTestUtil::ConstructSpdyWindowUpdate(const SpdyStreamId stream_id, | 870 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( |
| 861 uint32_t delta_window_size) { | 871 const SpdyStreamId stream_id, |
| 872 uint32_t delta_window_size) { |
| 862 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); | 873 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); |
| 863 return headerless_spdy_framer_.SerializeFrame(update_ir); | 874 return new SpdySerializedFrame( |
| 875 headerless_spdy_framer_.SerializeFrame(update_ir)); |
| 864 } | 876 } |
| 865 | 877 |
| 866 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 878 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
| 867 // SpdyRstStreamIR). | 879 // SpdyRstStreamIR). |
| 868 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream(SpdyStreamId stream_id, | 880 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyRstStream( |
| 869 SpdyRstStreamStatus status) { | 881 SpdyStreamId stream_id, |
| 882 SpdyRstStreamStatus status) { |
| 870 SpdyRstStreamIR rst_ir(stream_id, status); | 883 SpdyRstStreamIR rst_ir(stream_id, status); |
| 871 return headerless_spdy_framer_.SerializeRstStream(rst_ir); | 884 return new SpdySerializedFrame( |
| 885 headerless_spdy_framer_.SerializeRstStream(rst_ir)); |
| 872 } | 886 } |
| 873 | 887 |
| 874 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const url, | 888 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( |
| 875 SpdyStreamId stream_id, | 889 const char* const url, |
| 876 RequestPriority request_priority) { | 890 SpdyStreamId stream_id, |
| 891 RequestPriority request_priority) { |
| 877 scoped_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url)); | 892 scoped_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url)); |
| 878 return ConstructSpdySyn(stream_id, *block, request_priority, true); | 893 return ConstructSpdySyn(stream_id, *block, request_priority, true); |
| 879 } | 894 } |
| 880 | 895 |
| 881 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], | 896 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGet( |
| 882 int extra_header_count, | 897 const char* const extra_headers[], |
| 883 int stream_id, | 898 int extra_header_count, |
| 884 RequestPriority request_priority, | 899 int stream_id, |
| 885 bool direct) { | 900 RequestPriority request_priority, |
| 901 bool direct) { |
| 886 SpdyHeaderBlock block; | 902 SpdyHeaderBlock block; |
| 887 MaybeAddVersionHeader(&block); | 903 MaybeAddVersionHeader(&block); |
| 888 block[GetMethodKey()] = "GET"; | 904 block[GetMethodKey()] = "GET"; |
| 889 AddUrlToHeaderBlock(default_url_.spec(), &block); | 905 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 890 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 906 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 891 return ConstructSpdySyn(stream_id, block, request_priority, true); | 907 return ConstructSpdySyn(stream_id, block, request_priority, true); |
| 892 } | 908 } |
| 893 | 909 |
| 894 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( | 910 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyConnect( |
| 895 const char* const extra_headers[], | 911 const char* const extra_headers[], |
| 896 int extra_header_count, | 912 int extra_header_count, |
| 897 int stream_id, | 913 int stream_id, |
| 898 RequestPriority priority, | 914 RequestPriority priority, |
| 899 const HostPortPair& host_port_pair) { | 915 const HostPortPair& host_port_pair) { |
| 900 SpdyHeaderBlock block; | 916 SpdyHeaderBlock block; |
| 901 MaybeAddVersionHeader(&block); | 917 MaybeAddVersionHeader(&block); |
| 902 block[GetMethodKey()] = "CONNECT"; | 918 block[GetMethodKey()] = "CONNECT"; |
| 903 if (spdy_version() < HTTP2) { | 919 if (spdy_version() < HTTP2) { |
| 904 block[GetHostKey()] = (host_port_pair.port() == 443) | 920 block[GetHostKey()] = (host_port_pair.port() == 443) |
| 905 ? host_port_pair.host() | 921 ? host_port_pair.host() |
| 906 : host_port_pair.ToString(); | 922 : host_port_pair.ToString(); |
| 907 block[GetPathKey()] = host_port_pair.ToString(); | 923 block[GetPathKey()] = host_port_pair.ToString(); |
| 908 } else { | 924 } else { |
| 909 block[GetHostKey()] = host_port_pair.ToString(); | 925 block[GetHostKey()] = host_port_pair.ToString(); |
| 910 } | 926 } |
| 911 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 927 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 912 return ConstructSpdySyn(stream_id, block, priority, false); | 928 return ConstructSpdySyn(stream_id, block, priority, false); |
| 913 } | 929 } |
| 914 | 930 |
| 915 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 931 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( |
| 916 int extra_header_count, | 932 const char* const extra_headers[], |
| 917 int stream_id, | 933 int extra_header_count, |
| 918 int associated_stream_id, | 934 int stream_id, |
| 919 const char* url) { | 935 int associated_stream_id, |
| 936 const char* url) { |
| 920 if (spdy_version() < HTTP2) { | 937 if (spdy_version() < HTTP2) { |
| 921 SpdySynStreamIR syn_stream(stream_id); | 938 SpdySynStreamIR syn_stream(stream_id); |
| 922 syn_stream.set_associated_to_stream_id(associated_stream_id); | 939 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 923 syn_stream.SetHeader("hello", "bye"); | 940 syn_stream.SetHeader("hello", "bye"); |
| 924 syn_stream.SetHeader(GetStatusKey(), "200"); | 941 syn_stream.SetHeader(GetStatusKey(), "200"); |
| 925 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); | 942 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 926 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); | 943 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); |
| 927 AppendToHeaderBlock(extra_headers, extra_header_count, | 944 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 928 syn_stream.mutable_header_block()); | 945 syn_stream.mutable_header_block()); |
| 929 return response_spdy_framer_.SerializeFrame(syn_stream); | 946 return new SpdySerializedFrame( |
| 947 response_spdy_framer_.SerializeFrame(syn_stream)); |
| 930 } else { | 948 } else { |
| 931 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 949 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 932 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); | 950 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); |
| 933 scoped_ptr<SpdyFrame> push_promise_frame( | 951 SpdySerializedFrame push_promise_frame( |
| 934 response_spdy_framer_.SerializeFrame(push_promise)); | 952 response_spdy_framer_.SerializeFrame(push_promise)); |
| 935 | 953 |
| 936 SpdyHeadersIR headers(stream_id); | 954 SpdyHeadersIR headers(stream_id); |
| 937 headers.SetHeader(GetStatusKey(), "200"); | 955 headers.SetHeader(GetStatusKey(), "200"); |
| 938 headers.SetHeader("hello", "bye"); | 956 headers.SetHeader("hello", "bye"); |
| 939 AppendToHeaderBlock(extra_headers, extra_header_count, | 957 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 940 headers.mutable_header_block()); | 958 headers.mutable_header_block()); |
| 941 scoped_ptr<SpdyFrame> headers_frame( | 959 SpdySerializedFrame headers_frame( |
| 942 response_spdy_framer_.SerializeFrame(headers)); | 960 response_spdy_framer_.SerializeFrame(headers)); |
| 943 | 961 |
| 944 int joint_data_size = push_promise_frame->size() + headers_frame->size(); | 962 int joint_data_size = push_promise_frame.size() + headers_frame.size(); |
| 945 scoped_ptr<char[]> data(new char[joint_data_size]); | 963 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 946 const SpdyFrame* frames[2] = { | 964 const SpdySerializedFrame* frames[2] = { |
| 947 push_promise_frame.get(), headers_frame.get(), | 965 &push_promise_frame, &headers_frame, |
| 948 }; | 966 }; |
| 949 int combined_size = | 967 int combined_size = |
| 950 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); | 968 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 951 DCHECK_EQ(combined_size, joint_data_size); | 969 DCHECK_EQ(combined_size, joint_data_size); |
| 952 return new SpdyFrame(data.release(), joint_data_size, true); | 970 return new SpdySerializedFrame(data.release(), joint_data_size, true); |
| 953 } | 971 } |
| 954 } | 972 } |
| 955 | 973 |
| 956 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 974 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPush( |
| 957 int extra_header_count, | 975 const char* const extra_headers[], |
| 958 int stream_id, | 976 int extra_header_count, |
| 959 int associated_stream_id, | 977 int stream_id, |
| 960 const char* url, | 978 int associated_stream_id, |
| 961 const char* status, | 979 const char* url, |
| 962 const char* location) { | 980 const char* status, |
| 981 const char* location) { |
| 963 if (spdy_version() < HTTP2) { | 982 if (spdy_version() < HTTP2) { |
| 964 SpdySynStreamIR syn_stream(stream_id); | 983 SpdySynStreamIR syn_stream(stream_id); |
| 965 syn_stream.set_associated_to_stream_id(associated_stream_id); | 984 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 966 syn_stream.SetHeader("hello", "bye"); | 985 syn_stream.SetHeader("hello", "bye"); |
| 967 syn_stream.SetHeader(GetStatusKey(), status); | 986 syn_stream.SetHeader(GetStatusKey(), status); |
| 968 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); | 987 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 969 syn_stream.SetHeader("location", location); | 988 syn_stream.SetHeader("location", location); |
| 970 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); | 989 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); |
| 971 AppendToHeaderBlock(extra_headers, extra_header_count, | 990 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 972 syn_stream.mutable_header_block()); | 991 syn_stream.mutable_header_block()); |
| 973 return response_spdy_framer_.SerializeFrame(syn_stream); | 992 return new SpdySerializedFrame( |
| 993 response_spdy_framer_.SerializeFrame(syn_stream)); |
| 974 } else { | 994 } else { |
| 975 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 995 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 976 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); | 996 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); |
| 977 scoped_ptr<SpdyFrame> push_promise_frame( | 997 SpdySerializedFrame push_promise_frame( |
| 978 response_spdy_framer_.SerializeFrame(push_promise)); | 998 response_spdy_framer_.SerializeFrame(push_promise)); |
| 979 | 999 |
| 980 SpdyHeadersIR headers(stream_id); | 1000 SpdyHeadersIR headers(stream_id); |
| 981 headers.SetHeader("hello", "bye"); | 1001 headers.SetHeader("hello", "bye"); |
| 982 headers.SetHeader(GetStatusKey(), status); | 1002 headers.SetHeader(GetStatusKey(), status); |
| 983 headers.SetHeader("location", location); | 1003 headers.SetHeader("location", location); |
| 984 AppendToHeaderBlock(extra_headers, extra_header_count, | 1004 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 985 headers.mutable_header_block()); | 1005 headers.mutable_header_block()); |
| 986 scoped_ptr<SpdyFrame> headers_frame( | 1006 SpdySerializedFrame headers_frame( |
| 987 response_spdy_framer_.SerializeFrame(headers)); | 1007 response_spdy_framer_.SerializeFrame(headers)); |
| 988 | 1008 |
| 989 int joint_data_size = push_promise_frame->size() + headers_frame->size(); | 1009 int joint_data_size = push_promise_frame.size() + headers_frame.size(); |
| 990 scoped_ptr<char[]> data(new char[joint_data_size]); | 1010 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 991 const SpdyFrame* frames[2] = { | 1011 const SpdySerializedFrame* frames[2] = { |
| 992 push_promise_frame.get(), headers_frame.get(), | 1012 &push_promise_frame, &headers_frame, |
| 993 }; | 1013 }; |
| 994 int combined_size = | 1014 int combined_size = |
| 995 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); | 1015 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 996 DCHECK_EQ(combined_size, joint_data_size); | 1016 DCHECK_EQ(combined_size, joint_data_size); |
| 997 return new SpdyFrame(data.release(), joint_data_size, true); | 1017 return new SpdySerializedFrame(data.release(), joint_data_size, true); |
| 998 } | 1018 } |
| 999 } | 1019 } |
| 1000 | 1020 |
| 1001 SpdyFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( | 1021 SpdySerializedFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( |
| 1002 scoped_ptr<SpdyHeaderBlock> headers, | 1022 scoped_ptr<SpdyHeaderBlock> headers, |
| 1003 int stream_id, | 1023 int stream_id, |
| 1004 int associated_stream_id) { | 1024 int associated_stream_id) { |
| 1005 if (spdy_version() < HTTP2) { | 1025 if (spdy_version() < HTTP2) { |
| 1006 SpdySynStreamIR syn_stream(stream_id); | 1026 SpdySynStreamIR syn_stream(stream_id); |
| 1007 syn_stream.set_associated_to_stream_id(associated_stream_id); | 1027 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 1008 SetPriority(LOWEST, &syn_stream); | 1028 SetPriority(LOWEST, &syn_stream); |
| 1009 syn_stream.set_header_block(*headers); | 1029 syn_stream.set_header_block(*headers); |
| 1010 return response_spdy_framer_.SerializeFrame(syn_stream); | 1030 return new SpdySerializedFrame( |
| 1031 response_spdy_framer_.SerializeFrame(syn_stream)); |
| 1011 } else { | 1032 } else { |
| 1012 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 1033 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1013 push_promise.set_header_block(*headers); | 1034 push_promise.set_header_block(*headers); |
| 1014 return response_spdy_framer_.SerializeFrame(push_promise); | 1035 return new SpdySerializedFrame( |
| 1036 response_spdy_framer_.SerializeFrame(push_promise)); |
| 1015 } | 1037 } |
| 1016 } | 1038 } |
| 1017 | 1039 |
| 1018 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( | 1040 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPushHeaders( |
| 1019 int stream_id, | 1041 int stream_id, |
| 1020 const char* const extra_headers[], | 1042 const char* const extra_headers[], |
| 1021 int extra_header_count) { | 1043 int extra_header_count) { |
| 1022 SpdyHeadersIR headers(stream_id); | 1044 SpdyHeadersIR headers(stream_id); |
| 1023 headers.SetHeader(GetStatusKey(), "200"); | 1045 headers.SetHeader(GetStatusKey(), "200"); |
| 1024 MaybeAddVersionHeader(&headers); | 1046 MaybeAddVersionHeader(&headers); |
| 1025 AppendToHeaderBlock(extra_headers, extra_header_count, | 1047 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1026 headers.mutable_header_block()); | 1048 headers.mutable_header_block()); |
| 1027 return response_spdy_framer_.SerializeFrame(headers); | 1049 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(headers)); |
| 1028 } | 1050 } |
| 1029 | 1051 |
| 1030 SpdyFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( | 1052 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyResponseHeaders( |
| 1031 int stream_id, | 1053 int stream_id, |
| 1032 const SpdyHeaderBlock& headers, | 1054 const SpdyHeaderBlock& headers, |
| 1033 bool fin) { | 1055 bool fin) { |
| 1034 SpdyHeadersIR spdy_headers(stream_id); | 1056 SpdyHeadersIR spdy_headers(stream_id); |
| 1035 spdy_headers.set_header_block(headers); | 1057 spdy_headers.set_header_block(headers); |
| 1036 spdy_headers.set_fin(fin); | 1058 spdy_headers.set_fin(fin); |
| 1037 return response_spdy_framer_.SerializeFrame(spdy_headers); | 1059 return new SpdySerializedFrame( |
| 1060 response_spdy_framer_.SerializeFrame(spdy_headers)); |
| 1038 } | 1061 } |
| 1039 | 1062 |
| 1040 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, | 1063 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySyn( |
| 1041 const SpdyHeaderBlock& block, | 1064 int stream_id, |
| 1042 RequestPriority priority, | 1065 const SpdyHeaderBlock& block, |
| 1043 bool fin) { | 1066 RequestPriority priority, |
| 1067 bool fin) { |
| 1044 // Get the stream id of the next highest priority request | 1068 // Get the stream id of the next highest priority request |
| 1045 // (most recent request of the same priority, or last request of | 1069 // (most recent request of the same priority, or last request of |
| 1046 // an earlier priority). | 1070 // an earlier priority). |
| 1047 // Note that this is a duplicate of the logic in Http2PriorityDependencies | 1071 // Note that this is a duplicate of the logic in Http2PriorityDependencies |
| 1048 // (slightly transformed as this is based on RequestPriority and that logic | 1072 // (slightly transformed as this is based on RequestPriority and that logic |
| 1049 // on SpdyPriority, but only slightly transformed) and hence tests using | 1073 // on SpdyPriority, but only slightly transformed) and hence tests using |
| 1050 // this function do not effectively test that logic. | 1074 // this function do not effectively test that logic. |
| 1051 // That logic is tested by the Http2PriorityDependencies unit tests. | 1075 // That logic is tested by the Http2PriorityDependencies unit tests. |
| 1052 int parent_stream_id = 0; | 1076 int parent_stream_id = 0; |
| 1053 for (int q = priority; q <= HIGHEST; ++q) { | 1077 for (int q = priority; q <= HIGHEST; ++q) { |
| 1054 if (!priority_to_stream_id_list_[q].empty()) { | 1078 if (!priority_to_stream_id_list_[q].empty()) { |
| 1055 parent_stream_id = priority_to_stream_id_list_[q].back(); | 1079 parent_stream_id = priority_to_stream_id_list_[q].back(); |
| 1056 break; | 1080 break; |
| 1057 } | 1081 } |
| 1058 } | 1082 } |
| 1059 | 1083 |
| 1060 priority_to_stream_id_list_[priority].push_back(stream_id); | 1084 priority_to_stream_id_list_[priority].push_back(stream_id); |
| 1061 | 1085 |
| 1062 if (protocol_ < kProtoHTTP2) { | 1086 if (protocol_ < kProtoHTTP2) { |
| 1063 SpdySynStreamIR syn_stream(stream_id); | 1087 SpdySynStreamIR syn_stream(stream_id); |
| 1064 syn_stream.set_header_block(block); | 1088 syn_stream.set_header_block(block); |
| 1065 syn_stream.set_priority( | 1089 syn_stream.set_priority( |
| 1066 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1090 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1067 syn_stream.set_fin(fin); | 1091 syn_stream.set_fin(fin); |
| 1068 return request_spdy_framer_.SerializeFrame(syn_stream); | 1092 return new SpdySerializedFrame( |
| 1093 request_spdy_framer_.SerializeFrame(syn_stream)); |
| 1069 } else { | 1094 } else { |
| 1070 SpdyHeadersIR headers(stream_id); | 1095 SpdyHeadersIR headers(stream_id); |
| 1071 headers.set_header_block(block); | 1096 headers.set_header_block(block); |
| 1072 headers.set_has_priority(true); | 1097 headers.set_has_priority(true); |
| 1073 headers.set_priority( | 1098 headers.set_priority( |
| 1074 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1099 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1075 if (dependency_priorities_) { | 1100 if (dependency_priorities_) { |
| 1076 headers.set_parent_stream_id(parent_stream_id); | 1101 headers.set_parent_stream_id(parent_stream_id); |
| 1077 headers.set_exclusive(true); | 1102 headers.set_exclusive(true); |
| 1078 } | 1103 } |
| 1079 headers.set_fin(fin); | 1104 headers.set_fin(fin); |
| 1080 return request_spdy_framer_.SerializeFrame(headers); | 1105 return new SpdySerializedFrame( |
| 1106 request_spdy_framer_.SerializeFrame(headers)); |
| 1081 } | 1107 } |
| 1082 } | 1108 } |
| 1083 | 1109 |
| 1084 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, | 1110 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply( |
| 1085 const SpdyHeaderBlock& headers) { | 1111 int stream_id, |
| 1112 const SpdyHeaderBlock& headers) { |
| 1086 if (protocol_ < kProtoHTTP2) { | 1113 if (protocol_ < kProtoHTTP2) { |
| 1087 SpdySynReplyIR syn_reply(stream_id); | 1114 SpdySynReplyIR syn_reply(stream_id); |
| 1088 syn_reply.set_header_block(headers); | 1115 syn_reply.set_header_block(headers); |
| 1089 return response_spdy_framer_.SerializeFrame(syn_reply); | 1116 return new SpdySerializedFrame( |
| 1117 response_spdy_framer_.SerializeFrame(syn_reply)); |
| 1090 } else { | 1118 } else { |
| 1091 SpdyHeadersIR reply(stream_id); | 1119 SpdyHeadersIR reply(stream_id); |
| 1092 reply.set_header_block(headers); | 1120 reply.set_header_block(headers); |
| 1093 return response_spdy_framer_.SerializeFrame(reply); | 1121 return new SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); |
| 1094 } | 1122 } |
| 1095 } | 1123 } |
| 1096 | 1124 |
| 1097 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( | 1125 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError( |
| 1098 const char* const status, | 1126 const char* const status, |
| 1099 const char* const* const extra_headers, | 1127 const char* const* const extra_headers, |
| 1100 int extra_header_count, | 1128 int extra_header_count, |
| 1101 int stream_id) { | 1129 int stream_id) { |
| 1102 SpdyHeaderBlock block; | 1130 SpdyHeaderBlock block; |
| 1103 block[GetStatusKey()] = status; | 1131 block[GetStatusKey()] = status; |
| 1104 MaybeAddVersionHeader(&block); | 1132 MaybeAddVersionHeader(&block); |
| 1105 block["hello"] = "bye"; | 1133 block["hello"] = "bye"; |
| 1106 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1134 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1107 | 1135 |
| 1108 return ConstructSpdyReply(stream_id, block); | 1136 return ConstructSpdyReply(stream_id, block); |
| 1109 } | 1137 } |
| 1110 | 1138 |
| 1111 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(int stream_id) { | 1139 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( |
| 1140 int stream_id) { |
| 1112 static const char* const kExtraHeaders[] = { | 1141 static const char* const kExtraHeaders[] = { |
| 1113 "location", "http://www.foo.com/index.php", | 1142 "location", "http://www.foo.com/index.php", |
| 1114 }; | 1143 }; |
| 1115 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 1144 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, |
| 1116 arraysize(kExtraHeaders)/2, stream_id); | 1145 arraysize(kExtraHeaders)/2, stream_id); |
| 1117 } | 1146 } |
| 1118 | 1147 |
| 1119 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { | 1148 SpdySerializedFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { |
| 1120 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 1149 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
| 1121 } | 1150 } |
| 1122 | 1151 |
| 1123 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReply( | 1152 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyGetSynReply( |
| 1124 const char* const extra_headers[], | 1153 const char* const extra_headers[], |
| 1125 int extra_header_count, | 1154 int extra_header_count, |
| 1126 int stream_id) { | 1155 int stream_id) { |
| 1127 SpdyHeaderBlock block; | 1156 SpdyHeaderBlock block; |
| 1128 block[GetStatusKey()] = "200"; | 1157 block[GetStatusKey()] = "200"; |
| 1129 MaybeAddVersionHeader(&block); | 1158 MaybeAddVersionHeader(&block); |
| 1130 block["hello"] = "bye"; | 1159 block["hello"] = "bye"; |
| 1131 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1160 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1132 | 1161 |
| 1133 return ConstructSpdyReply(stream_id, block); | 1162 return ConstructSpdyReply(stream_id, block); |
| 1134 } | 1163 } |
| 1135 | 1164 |
| 1136 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, | 1165 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPost( |
| 1137 SpdyStreamId stream_id, | 1166 const char* url, |
| 1138 int64_t content_length, | 1167 SpdyStreamId stream_id, |
| 1139 RequestPriority priority, | 1168 int64_t content_length, |
| 1140 const char* const extra_headers[], | 1169 RequestPriority priority, |
| 1141 int extra_header_count) { | 1170 const char* const extra_headers[], |
| 1171 int extra_header_count) { |
| 1142 scoped_ptr<SpdyHeaderBlock> block( | 1172 scoped_ptr<SpdyHeaderBlock> block( |
| 1143 ConstructPostHeaderBlock(url, content_length)); | 1173 ConstructPostHeaderBlock(url, content_length)); |
| 1144 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); | 1174 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); |
| 1145 return ConstructSpdySyn(stream_id, *block, priority, false); | 1175 return ConstructSpdySyn(stream_id, *block, priority, false); |
| 1146 } | 1176 } |
| 1147 | 1177 |
| 1148 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( | 1178 SpdySerializedFrame* SpdyTestUtil::ConstructChunkedSpdyPost( |
| 1149 const char* const extra_headers[], | 1179 const char* const extra_headers[], |
| 1150 int extra_header_count) { | 1180 int extra_header_count) { |
| 1151 SpdyHeaderBlock block; | 1181 SpdyHeaderBlock block; |
| 1152 MaybeAddVersionHeader(&block); | 1182 MaybeAddVersionHeader(&block); |
| 1153 block[GetMethodKey()] = "POST"; | 1183 block[GetMethodKey()] = "POST"; |
| 1154 AddUrlToHeaderBlock(default_url_.spec(), &block); | 1184 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 1155 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1185 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1156 return ConstructSpdySyn(1, block, LOWEST, false); | 1186 return ConstructSpdySyn(1, block, LOWEST, false); |
| 1157 } | 1187 } |
| 1158 | 1188 |
| 1159 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply( | 1189 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyPostSynReply( |
| 1160 const char* const extra_headers[], | 1190 const char* const extra_headers[], |
| 1161 int extra_header_count) { | 1191 int extra_header_count) { |
| 1162 // TODO(jgraettinger): Remove this method. | 1192 // TODO(jgraettinger): Remove this method. |
| 1163 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); | 1193 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); |
| 1164 } | 1194 } |
| 1165 | 1195 |
| 1166 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { | 1196 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
| 1197 bool fin) { |
| 1167 SpdyFramer framer(spdy_version_); | 1198 SpdyFramer framer(spdy_version_); |
| 1168 SpdyDataIR data_ir(stream_id, | 1199 SpdyDataIR data_ir(stream_id, |
| 1169 base::StringPiece(kUploadData, kUploadDataSize)); | 1200 base::StringPiece(kUploadData, kUploadDataSize)); |
| 1170 data_ir.set_fin(fin); | 1201 data_ir.set_fin(fin); |
| 1171 return framer.SerializeData(data_ir); | 1202 return new SpdySerializedFrame(framer.SerializeData(data_ir)); |
| 1172 } | 1203 } |
| 1173 | 1204 |
| 1174 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1205 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
| 1175 const char* data, | 1206 const char* data, |
| 1176 uint32_t len, | 1207 uint32_t len, |
| 1177 bool fin) { | 1208 bool fin) { |
| 1178 SpdyFramer framer(spdy_version_); | 1209 SpdyFramer framer(spdy_version_); |
| 1179 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); | 1210 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); |
| 1180 data_ir.set_fin(fin); | 1211 data_ir.set_fin(fin); |
| 1181 return framer.SerializeData(data_ir); | 1212 return new SpdySerializedFrame(framer.SerializeData(data_ir)); |
| 1182 } | 1213 } |
| 1183 | 1214 |
| 1184 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1215 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
| 1185 const char* data, | 1216 const char* data, |
| 1186 uint32_t len, | 1217 uint32_t len, |
| 1187 bool fin, | 1218 bool fin, |
| 1188 int padding_length) { | 1219 int padding_length) { |
| 1189 SpdyFramer framer(spdy_version_); | 1220 SpdyFramer framer(spdy_version_); |
| 1190 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); | 1221 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); |
| 1191 data_ir.set_fin(fin); | 1222 data_ir.set_fin(fin); |
| 1192 data_ir.set_padding_len(padding_length); | 1223 data_ir.set_padding_len(padding_length); |
| 1193 return framer.SerializeData(data_ir); | 1224 return new SpdySerializedFrame(framer.SerializeData(data_ir)); |
| 1194 } | 1225 } |
| 1195 | 1226 |
| 1196 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( | 1227 SpdySerializedFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( |
| 1197 const scoped_ptr<SpdyFrame>& frame, | 1228 const scoped_ptr<SpdySerializedFrame>& frame, |
| 1198 int stream_id) { | 1229 int stream_id) { |
| 1199 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 1230 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
| 1200 frame->size(), false); | 1231 frame->size(), false); |
| 1201 } | 1232 } |
| 1202 | 1233 |
| 1203 void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) { | 1234 void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) { |
| 1204 for (auto priority_it = priority_to_stream_id_list_.begin(); | 1235 for (auto priority_it = priority_to_stream_id_list_.begin(); |
| 1205 priority_it != priority_to_stream_id_list_.end(); ++priority_it) { | 1236 priority_it != priority_to_stream_id_list_.end(); ++priority_it) { |
| 1206 for (auto stream_it = priority_it->second.begin(); | 1237 for (auto stream_it = priority_it->second.begin(); |
| 1207 stream_it != priority_it->second.end(); ++stream_it) { | 1238 stream_it != priority_it->second.end(); ++stream_it) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 } | 1306 } |
| 1276 } | 1307 } |
| 1277 | 1308 |
| 1278 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1309 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1279 SpdySynStreamIR* ir) const { | 1310 SpdySynStreamIR* ir) const { |
| 1280 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1311 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1281 priority, spdy_version())); | 1312 priority, spdy_version())); |
| 1282 } | 1313 } |
| 1283 | 1314 |
| 1284 } // namespace net | 1315 } // namespace net |
| OLD | NEW |