| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/spdy_balsa_utils.h" | 5 #include "net/tools/quic/spdy_balsa_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "net/base/linked_hash_map.h" | 14 #include "net/base/linked_hash_map.h" |
| 14 #include "net/quic/quic_flags.h" | 15 #include "net/quic/quic_flags.h" |
| 15 #include "net/quic/spdy_utils.h" | 16 #include "net/quic/spdy_utils.h" |
| 16 #include "net/spdy/spdy_frame_builder.h" | 17 #include "net/spdy/spdy_frame_builder.h" |
| 17 #include "net/spdy/spdy_framer.h" | 18 #include "net/spdy/spdy_framer.h" |
| 18 #include "net/spdy/spdy_protocol.h" | 19 #include "net/spdy/spdy_protocol.h" |
| 19 #include "net/tools/balsa/balsa_headers.h" | 20 #include "net/tools/balsa/balsa_headers.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 (*block)[kV3Version] = headers.response_version(); | 112 (*block)[kV3Version] = headers.response_version(); |
| 112 } else { | 113 } else { |
| 113 (*block)[kV3Status] = headers.response_code(); | 114 (*block)[kV3Status] = headers.response_code(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 PopulateSpdyHeaderBlock(headers, block, true); | 117 PopulateSpdyHeaderBlock(headers, block, true); |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool IsSpecialSpdyHeader(SpdyHeaderBlock::const_iterator header, | 120 bool IsSpecialSpdyHeader(SpdyHeaderBlock::const_iterator header, |
| 120 BalsaHeaders* headers) { | 121 BalsaHeaders* headers) { |
| 121 return header->first.empty() || header->second.empty() || | 122 return header->first.empty() || /* header->second.empty() || */ |
| 122 header->first[0] == ':'; | 123 header->first[0] == ':'; |
| 123 } | 124 } |
| 124 | 125 |
| 125 // The reason phrase should match regexp [\d\d\d [^\r\n]+]. If not, we will | 126 // The reason phrase should match regexp [\d\d\d [^\r\n]+]. If not, we will |
| 126 // fail to parse it. | 127 // fail to parse it. |
| 127 bool ParseReasonAndStatus(StringPiece status_and_reason, | 128 bool ParseReasonAndStatus(StringPiece status_and_reason, |
| 128 BalsaHeaders* headers) { | 129 BalsaHeaders* headers) { |
| 129 int status; | 130 int status; |
| 130 if (!base::StringToInt(status_and_reason, &status)) { | 131 if (!base::StringToInt(status_and_reason, &status)) { |
| 131 return false; | 132 return false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 146 if (status_it == end_it) { | 147 if (status_it == end_it) { |
| 147 return; | 148 return; |
| 148 } | 149 } |
| 149 | 150 |
| 150 if (!ParseReasonAndStatus(status_it->second, request_headers)) { | 151 if (!ParseReasonAndStatus(status_it->second, request_headers)) { |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 154 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { | 155 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { |
| 155 if (!IsSpecialSpdyHeader(it, request_headers)) { | 156 if (!IsSpecialSpdyHeader(it, request_headers)) { |
| 156 request_headers->AppendHeader(it->first, it->second); | 157 if (it->second.empty()) { |
| 158 request_headers->AppendHeader(it->first, it->second); |
| 159 } else { |
| 160 DVLOG(2) << "Splitting value: [" << it->second << "]" |
| 161 << " for key: " << it->first; |
| 162 for (string value : |
| 163 base::SplitString(it->second, base::StringPiece("\0", 1), |
| 164 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 165 DVLOG(2) << "AppendHeader(" << it->first << ", " << value << ")"; |
| 166 request_headers->AppendHeader(it->first, StringPiece(value)); |
| 167 } |
| 168 } |
| 157 } | 169 } |
| 158 } | 170 } |
| 159 } | 171 } |
| 160 | 172 |
| 161 // static | 173 // static |
| 162 void SpdyHeadersToRequestHeaders(const SpdyHeaderBlock& header_block, | 174 void SpdyHeadersToRequestHeaders(const SpdyHeaderBlock& header_block, |
| 163 BalsaHeaders* request_headers) { | 175 BalsaHeaders* request_headers) { |
| 164 typedef SpdyHeaderBlock::const_iterator BlockIt; | 176 typedef SpdyHeaderBlock::const_iterator BlockIt; |
| 165 | 177 |
| 166 BlockIt authority_it = header_block.find(kV4Host); | 178 BlockIt authority_it = header_block.find(kV4Host); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 191 request_headers->AppendHeader("Scheme", scheme_it->second); | 203 request_headers->AppendHeader("Scheme", scheme_it->second); |
| 192 } | 204 } |
| 193 if (authority_it != end_it) { | 205 if (authority_it != end_it) { |
| 194 request_headers->AppendHeader("host", authority_it->second); | 206 request_headers->AppendHeader("host", authority_it->second); |
| 195 } else if (host_it != end_it) { | 207 } else if (host_it != end_it) { |
| 196 request_headers->AppendHeader("host", host_it->second); | 208 request_headers->AppendHeader("host", host_it->second); |
| 197 } | 209 } |
| 198 | 210 |
| 199 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { | 211 for (BlockIt it = header_block.begin(); it != header_block.end(); ++it) { |
| 200 if (!IsSpecialSpdyHeader(it, request_headers)) { | 212 if (!IsSpecialSpdyHeader(it, request_headers)) { |
| 201 request_headers->AppendHeader(it->first, it->second); | 213 if (it->second.empty()) { |
| 214 request_headers->AppendHeader(it->first, it->second); |
| 215 } else { |
| 216 DVLOG(2) << "Splitting value: [" << it->second << "]" |
| 217 << " for key: " << it->first; |
| 218 for (string value : |
| 219 base::SplitString(it->second, base::StringPiece("\0", 1), |
| 220 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 221 DVLOG(2) << "AppendHeader(" << it->first << ", " << value << ")"; |
| 222 request_headers->AppendHeader(it->first, StringPiece(value)); |
| 223 } |
| 224 } |
| 202 } | 225 } |
| 203 } | 226 } |
| 204 } | 227 } |
| 205 | 228 |
| 206 // static | 229 // static |
| 207 void SpdyHeadersToBalsaHeaders(const SpdyHeaderBlock& block, | 230 void SpdyHeadersToBalsaHeaders(const SpdyHeaderBlock& block, |
| 208 BalsaHeaders* headers, | 231 BalsaHeaders* headers, |
| 209 bool isResponse) { | 232 bool isResponse) { |
| 210 if (isResponse) { | 233 if (isResponse) { |
| 211 SpdyHeadersToResponseHeaders(block, headers); | 234 SpdyHeadersToResponseHeaders(block, headers); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 SpdyHeadersToBalsaHeaders(block, headers, true); | 295 SpdyHeadersToBalsaHeaders(block, headers, true); |
| 273 } | 296 } |
| 274 | 297 |
| 275 // static | 298 // static |
| 276 void SpdyBalsaUtils::SpdyHeadersToRequestHeaders(const SpdyHeaderBlock& block, | 299 void SpdyBalsaUtils::SpdyHeadersToRequestHeaders(const SpdyHeaderBlock& block, |
| 277 BalsaHeaders* headers) { | 300 BalsaHeaders* headers) { |
| 278 SpdyHeadersToBalsaHeaders(block, headers, false); | 301 SpdyHeadersToBalsaHeaders(block, headers, false); |
| 279 } | 302 } |
| 280 | 303 |
| 281 } // namespace net | 304 } // namespace net |
| OLD | NEW |