| 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 <utility> | 10 #include <utility> |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 SpdyRstStreamIR rst_ir(stream_id, status); | 769 SpdyRstStreamIR rst_ir(stream_id, status); |
| 770 return SpdySerializedFrame( | 770 return SpdySerializedFrame( |
| 771 headerless_spdy_framer_.SerializeRstStream(rst_ir)); | 771 headerless_spdy_framer_.SerializeRstStream(rst_ir)); |
| 772 } | 772 } |
| 773 | 773 |
| 774 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet( | 774 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet( |
| 775 const char* const url, | 775 const char* const url, |
| 776 SpdyStreamId stream_id, | 776 SpdyStreamId stream_id, |
| 777 RequestPriority request_priority) { | 777 RequestPriority request_priority) { |
| 778 SpdyHeaderBlock block(ConstructGetHeaderBlock(url)); | 778 SpdyHeaderBlock block(ConstructGetHeaderBlock(url)); |
| 779 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); | 779 return ConstructSpdyHeaders(stream_id, std::move(block), request_priority, |
| 780 true); |
| 780 } | 781 } |
| 781 | 782 |
| 782 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet( | 783 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet( |
| 783 const char* const extra_headers[], | 784 const char* const extra_headers[], |
| 784 int extra_header_count, | 785 int extra_header_count, |
| 785 int stream_id, | 786 int stream_id, |
| 786 RequestPriority request_priority, | 787 RequestPriority request_priority, |
| 787 bool direct) { | 788 bool direct) { |
| 788 SpdyHeaderBlock block; | 789 SpdyHeaderBlock block; |
| 789 block[GetMethodKey()] = "GET"; | 790 block[GetMethodKey()] = "GET"; |
| 790 AddUrlToHeaderBlock(default_url_.spec(), &block); | 791 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 791 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 792 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 792 return ConstructSpdySyn(stream_id, std::move(block), request_priority, true); | 793 return ConstructSpdyHeaders(stream_id, std::move(block), request_priority, |
| 794 true); |
| 793 } | 795 } |
| 794 | 796 |
| 795 SpdySerializedFrame SpdyTestUtil::ConstructSpdyConnect( | 797 SpdySerializedFrame SpdyTestUtil::ConstructSpdyConnect( |
| 796 const char* const extra_headers[], | 798 const char* const extra_headers[], |
| 797 int extra_header_count, | 799 int extra_header_count, |
| 798 int stream_id, | 800 int stream_id, |
| 799 RequestPriority priority, | 801 RequestPriority priority, |
| 800 const HostPortPair& host_port_pair) { | 802 const HostPortPair& host_port_pair) { |
| 801 SpdyHeaderBlock block; | 803 SpdyHeaderBlock block; |
| 802 block[GetMethodKey()] = "CONNECT"; | 804 block[GetMethodKey()] = "CONNECT"; |
| 803 block[GetHostKey()] = host_port_pair.ToString(); | 805 block[GetHostKey()] = host_port_pair.ToString(); |
| 804 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 806 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 805 return ConstructSpdySyn(stream_id, std::move(block), priority, false); | 807 return ConstructSpdyHeaders(stream_id, std::move(block), priority, false); |
| 806 } | 808 } |
| 807 | 809 |
| 808 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush( | 810 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush( |
| 809 const char* const extra_headers[], | 811 const char* const extra_headers[], |
| 810 int extra_header_count, | 812 int extra_header_count, |
| 811 int stream_id, | 813 int stream_id, |
| 812 int associated_stream_id, | 814 int associated_stream_id, |
| 813 const char* url) { | 815 const char* url) { |
| 814 SpdyHeaderBlock push_promise_header_block; | 816 SpdyHeaderBlock push_promise_header_block; |
| 815 AddUrlToHeaderBlock(url, &push_promise_header_block); | 817 AddUrlToHeaderBlock(url, &push_promise_header_block); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 SpdySerializedFrame SpdyTestUtil::ConstructSpdyResponseHeaders( | 898 SpdySerializedFrame SpdyTestUtil::ConstructSpdyResponseHeaders( |
| 897 int stream_id, | 899 int stream_id, |
| 898 SpdyHeaderBlock headers, | 900 SpdyHeaderBlock headers, |
| 899 bool fin) { | 901 bool fin) { |
| 900 SpdyHeadersIR spdy_headers(stream_id, std::move(headers)); | 902 SpdyHeadersIR spdy_headers(stream_id, std::move(headers)); |
| 901 spdy_headers.set_fin(fin); | 903 spdy_headers.set_fin(fin); |
| 902 return SpdySerializedFrame( | 904 return SpdySerializedFrame( |
| 903 response_spdy_framer_.SerializeFrame(spdy_headers)); | 905 response_spdy_framer_.SerializeFrame(spdy_headers)); |
| 904 } | 906 } |
| 905 | 907 |
| 906 SpdySerializedFrame SpdyTestUtil::ConstructSpdySyn(int stream_id, | 908 SpdySerializedFrame SpdyTestUtil::ConstructSpdyHeaders(int stream_id, |
| 907 SpdyHeaderBlock block, | 909 SpdyHeaderBlock block, |
| 908 RequestPriority priority, | 910 RequestPriority priority, |
| 909 bool fin) { | 911 bool fin) { |
| 910 // Get the stream id of the next highest priority request | 912 // Get the stream id of the next highest priority request |
| 911 // (most recent request of the same priority, or last request of | 913 // (most recent request of the same priority, or last request of |
| 912 // an earlier priority). | 914 // an earlier priority). |
| 913 // Note that this is a duplicate of the logic in Http2PriorityDependencies | 915 // Note that this is a duplicate of the logic in Http2PriorityDependencies |
| 914 // (slightly transformed as this is based on RequestPriority and that logic | 916 // (slightly transformed as this is based on RequestPriority and that logic |
| 915 // on SpdyPriority, but only slightly transformed) and hence tests using | 917 // on SpdyPriority, but only slightly transformed) and hence tests using |
| 916 // this function do not effectively test that logic. | 918 // this function do not effectively test that logic. |
| 917 // That logic is tested by the Http2PriorityDependencies unit tests. | 919 // That logic is tested by the Http2PriorityDependencies unit tests. |
| 918 int parent_stream_id = 0; | 920 int parent_stream_id = 0; |
| 919 for (int q = priority; q <= HIGHEST; ++q) { | 921 for (int q = priority; q <= HIGHEST; ++q) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 934 headers.set_fin(fin); | 936 headers.set_fin(fin); |
| 935 return SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers)); | 937 return SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers)); |
| 936 } | 938 } |
| 937 | 939 |
| 938 SpdySerializedFrame SpdyTestUtil::ConstructSpdyReply(int stream_id, | 940 SpdySerializedFrame SpdyTestUtil::ConstructSpdyReply(int stream_id, |
| 939 SpdyHeaderBlock headers) { | 941 SpdyHeaderBlock headers) { |
| 940 SpdyHeadersIR reply(stream_id, std::move(headers)); | 942 SpdyHeadersIR reply(stream_id, std::move(headers)); |
| 941 return SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); | 943 return SpdySerializedFrame(response_spdy_framer_.SerializeFrame(reply)); |
| 942 } | 944 } |
| 943 | 945 |
| 944 SpdySerializedFrame SpdyTestUtil::ConstructSpdySynReplyError( | 946 SpdySerializedFrame SpdyTestUtil::ConstructSpdyReplyError( |
| 945 const char* const status, | 947 const char* const status, |
| 946 const char* const* const extra_headers, | 948 const char* const* const extra_headers, |
| 947 int extra_header_count, | 949 int extra_header_count, |
| 948 int stream_id) { | 950 int stream_id) { |
| 949 SpdyHeaderBlock block; | 951 SpdyHeaderBlock block; |
| 950 block[GetStatusKey()] = status; | 952 block[GetStatusKey()] = status; |
| 951 block["hello"] = "bye"; | 953 block["hello"] = "bye"; |
| 952 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 954 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 953 | 955 |
| 954 return ConstructSpdyReply(stream_id, std::move(block)); | 956 return ConstructSpdyReply(stream_id, std::move(block)); |
| 955 } | 957 } |
| 956 | 958 |
| 957 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetSynReplyRedirect( | 959 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetReplyRedirect(int stream_id) { |
| 958 int stream_id) { | |
| 959 static const char* const kExtraHeaders[] = { | 960 static const char* const kExtraHeaders[] = { |
| 960 "location", "http://www.foo.com/index.php", | 961 "location", "http://www.foo.com/index.php", |
| 961 }; | 962 }; |
| 962 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 963 return ConstructSpdyReplyError("301 Moved Permanently", kExtraHeaders, |
| 963 arraysize(kExtraHeaders)/2, stream_id); | 964 arraysize(kExtraHeaders) / 2, stream_id); |
| 964 } | 965 } |
| 965 | 966 |
| 966 SpdySerializedFrame SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { | 967 SpdySerializedFrame SpdyTestUtil::ConstructSpdyReplyError(int stream_id) { |
| 967 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 968 return ConstructSpdyReplyError("500 Internal Server Error", NULL, 0, 1); |
| 968 } | 969 } |
| 969 | 970 |
| 970 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetSynReply( | 971 SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetReply( |
| 971 const char* const extra_headers[], | 972 const char* const extra_headers[], |
| 972 int extra_header_count, | 973 int extra_header_count, |
| 973 int stream_id) { | 974 int stream_id) { |
| 974 SpdyHeaderBlock block; | 975 SpdyHeaderBlock block; |
| 975 block[GetStatusKey()] = "200"; | 976 block[GetStatusKey()] = "200"; |
| 976 block["hello"] = "bye"; | 977 block["hello"] = "bye"; |
| 977 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 978 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 978 | 979 |
| 979 return ConstructSpdyReply(stream_id, std::move(block)); | 980 return ConstructSpdyReply(stream_id, std::move(block)); |
| 980 } | 981 } |
| 981 | 982 |
| 982 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPost( | 983 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPost( |
| 983 const char* url, | 984 const char* url, |
| 984 SpdyStreamId stream_id, | 985 SpdyStreamId stream_id, |
| 985 int64_t content_length, | 986 int64_t content_length, |
| 986 RequestPriority priority, | 987 RequestPriority priority, |
| 987 const char* const extra_headers[], | 988 const char* const extra_headers[], |
| 988 int extra_header_count) { | 989 int extra_header_count) { |
| 989 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length)); | 990 SpdyHeaderBlock block(ConstructPostHeaderBlock(url, content_length)); |
| 990 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 991 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 991 return ConstructSpdySyn(stream_id, std::move(block), priority, false); | 992 return ConstructSpdyHeaders(stream_id, std::move(block), priority, false); |
| 992 } | 993 } |
| 993 | 994 |
| 994 SpdySerializedFrame SpdyTestUtil::ConstructChunkedSpdyPost( | 995 SpdySerializedFrame SpdyTestUtil::ConstructChunkedSpdyPost( |
| 995 const char* const extra_headers[], | 996 const char* const extra_headers[], |
| 996 int extra_header_count) { | 997 int extra_header_count) { |
| 997 SpdyHeaderBlock block; | 998 SpdyHeaderBlock block; |
| 998 block[GetMethodKey()] = "POST"; | 999 block[GetMethodKey()] = "POST"; |
| 999 AddUrlToHeaderBlock(default_url_.spec(), &block); | 1000 AddUrlToHeaderBlock(default_url_.spec(), &block); |
| 1000 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 1001 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 1001 return ConstructSpdySyn(1, std::move(block), LOWEST, false); | 1002 return ConstructSpdyHeaders(1, std::move(block), LOWEST, false); |
| 1002 } | 1003 } |
| 1003 | 1004 |
| 1004 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPostSynReply( | 1005 SpdySerializedFrame SpdyTestUtil::ConstructSpdyPostReply( |
| 1005 const char* const extra_headers[], | 1006 const char* const extra_headers[], |
| 1006 int extra_header_count) { | 1007 int extra_header_count) { |
| 1007 // TODO(jgraettinger): Remove this method. | 1008 // TODO(jgraettinger): Remove this method. |
| 1008 return ConstructSpdyGetSynReply(extra_headers, extra_header_count, 1); | 1009 return ConstructSpdyGetReply(extra_headers, extra_header_count, 1); |
| 1009 } | 1010 } |
| 1010 | 1011 |
| 1011 SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id, | 1012 SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id, |
| 1012 bool fin) { | 1013 bool fin) { |
| 1013 SpdyFramer framer(HTTP2); | 1014 SpdyFramer framer(HTTP2); |
| 1014 SpdyDataIR data_ir(stream_id, | 1015 SpdyDataIR data_ir(stream_id, |
| 1015 base::StringPiece(kUploadData, kUploadDataSize)); | 1016 base::StringPiece(kUploadData, kUploadDataSize)); |
| 1016 data_ir.set_fin(fin); | 1017 data_ir.set_fin(fin); |
| 1017 return SpdySerializedFrame(framer.SerializeData(data_ir)); | 1018 return SpdySerializedFrame(framer.SerializeData(data_ir)); |
| 1018 } | 1019 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 headers[GetHostKey()] = host.c_str(); | 1095 headers[GetHostKey()] = host.c_str(); |
| 1095 headers[GetSchemeKey()] = scheme.c_str(); | 1096 headers[GetSchemeKey()] = scheme.c_str(); |
| 1096 headers[GetPathKey()] = path.c_str(); | 1097 headers[GetPathKey()] = path.c_str(); |
| 1097 if (content_length) { | 1098 if (content_length) { |
| 1098 std::string length_str = base::Int64ToString(*content_length); | 1099 std::string length_str = base::Int64ToString(*content_length); |
| 1099 headers["content-length"] = length_str; | 1100 headers["content-length"] = length_str; |
| 1100 } | 1101 } |
| 1101 return headers; | 1102 return headers; |
| 1102 } | 1103 } |
| 1103 | 1104 |
| 1104 void SpdyTestUtil::SetPriority(RequestPriority priority, | |
| 1105 SpdySynStreamIR* ir) const { | |
| 1106 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority)); | |
| 1107 } | |
| 1108 | |
| 1109 } // namespace net | 1105 } // namespace net |
| OLD | NEW |