| 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/http/http_content_disposition.h" | 5 #include "net/http/http_content_disposition.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
| 10 #include "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // | 62 // |
| 63 void HttpContentDisposition::Parse(const std::string& header, | 63 void HttpContentDisposition::Parse(const std::string& header, |
| 64 const std::string& referrer_charset) { | 64 const std::string& referrer_charset) { |
| 65 DCHECK(type_ == INLINE); | 65 DCHECK(type_ == INLINE); |
| 66 DCHECK(filename_.empty()); | 66 DCHECK(filename_.empty()); |
| 67 | 67 |
| 68 std::string::const_iterator pos = header.begin(); | 68 std::string::const_iterator pos = header.begin(); |
| 69 std::string::const_iterator end = header.end(); | 69 std::string::const_iterator end = header.end(); |
| 70 pos = ConsumeDispositionType(pos, end); | 70 pos = ConsumeDispositionType(pos, end); |
| 71 | 71 |
| 72 std::string name; |
| 72 std::string filename; | 73 std::string filename; |
| 73 std::string ext_filename; | 74 std::string ext_filename; |
| 74 | 75 |
| 75 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); | 76 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); |
| 76 while (iter.GetNext()) { | 77 while (iter.GetNext()) { |
| 77 if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 78 if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 78 iter.name_end(), | 79 iter.name_end(), |
| 79 "filename")) { | 80 "filename")) { |
| 80 DecodeFilenameValue(iter.value(), referrer_charset, &filename); | 81 DecodeFilenameValue(iter.value(), referrer_charset, &filename); |
| 81 } else if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 82 } else if (name.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 82 iter.name_end(), | 83 iter.name_end(), |
| 83 "name")) { | 84 "name")) { |
| 84 DecodeFilenameValue(iter.value(), referrer_charset, &filename); | 85 DecodeFilenameValue(iter.value(), referrer_charset, &name); |
| 85 } else if (ext_filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 86 } else if (ext_filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 86 iter.name_end(), | 87 iter.name_end(), |
| 87 "filename*")) { | 88 "filename*")) { |
| 88 DecodeExtValue(iter.raw_value(), &ext_filename); | 89 DecodeExtValue(iter.raw_value(), &ext_filename); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 filename_ = ext_filename.empty() ? filename : ext_filename; | 93 if (!ext_filename.empty()) |
| 94 filename_ = ext_filename; |
| 95 else if (!filename.empty()) |
| 96 filename_ = filename; |
| 97 else |
| 98 filename_ = name; |
| 93 } | 99 } |
| 94 | 100 |
| 95 } // namespace net | 101 } // namespace net |
| OLD | NEW |