| 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" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 HttpContentDisposition::HttpContentDisposition( | 14 HttpContentDisposition::HttpContentDisposition( |
| 15 const std::string& header, const std::string& referrer_charset) | 15 const std::string& header, const std::string& default_charset) |
| 16 : type_(INLINE) { | 16 : type_(INLINE) { |
| 17 Parse(header, referrer_charset); | 17 Parse(header, default_charset); |
| 18 } | 18 } |
| 19 | 19 |
| 20 HttpContentDisposition::~HttpContentDisposition() { | 20 HttpContentDisposition::~HttpContentDisposition() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 std::string::const_iterator HttpContentDisposition::ConsumeDispositionType( | 23 std::string::const_iterator HttpContentDisposition::ConsumeDispositionType( |
| 24 std::string::const_iterator begin, std::string::const_iterator end) { | 24 std::string::const_iterator begin, std::string::const_iterator end) { |
| 25 DCHECK(type_ == INLINE); | 25 DCHECK(type_ == INLINE); |
| 26 std::string::const_iterator delimiter = std::find(begin, end, ';'); | 26 std::string::const_iterator delimiter = std::find(begin, end, ';'); |
| 27 | 27 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 // disposition-parm = filename-parm | disp-ext-parm | 54 // disposition-parm = filename-parm | disp-ext-parm |
| 55 // | 55 // |
| 56 // filename-parm = "filename" "=" value | 56 // filename-parm = "filename" "=" value |
| 57 // | "filename*" "=" ext-value | 57 // | "filename*" "=" ext-value |
| 58 // | 58 // |
| 59 // disp-ext-parm = token "=" value | 59 // disp-ext-parm = token "=" value |
| 60 // | ext-token "=" ext-value | 60 // | ext-token "=" ext-value |
| 61 // ext-token = <the characters in token, followed by "*"> | 61 // ext-token = <the characters in token, followed by "*"> |
| 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& default_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 filename; | 72 std::string filename; |
| 73 std::string ext_filename; | 73 std::string ext_filename; |
| 74 | 74 |
| 75 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); | 75 HttpUtil::NameValuePairsIterator iter(pos, end, ';'); |
| 76 while (iter.GetNext()) { | 76 while (iter.GetNext()) { |
| 77 if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 77 if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 78 iter.name_end(), | 78 iter.name_end(), |
| 79 "filename")) { | 79 "filename")) { |
| 80 DecodeFilenameValue(iter.value(), referrer_charset, &filename); | 80 DecodeFilenameValue(iter.value(), default_charset, &filename); |
| 81 } else if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 81 } else if (filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 82 iter.name_end(), | 82 iter.name_end(), |
| 83 "name")) { | 83 "name")) { |
| 84 DecodeFilenameValue(iter.value(), referrer_charset, &filename); | 84 DecodeFilenameValue(iter.value(), default_charset, &filename); |
| 85 } else if (ext_filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), | 85 } else if (ext_filename.empty() && LowerCaseEqualsASCII(iter.name_begin(), |
| 86 iter.name_end(), | 86 iter.name_end(), |
| 87 "filename*")) { | 87 "filename*")) { |
| 88 DecodeExtValue(iter.raw_value(), &ext_filename); | 88 DecodeExtValue(iter.raw_value(), &ext_filename); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 filename_ = ext_filename.empty() ? filename : ext_filename; | 92 filename_ = ext_filename.empty() ? filename : ext_filename; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace net | 95 } // namespace net |
| OLD | NEW |