| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. |
| 8 * (http://www.torchmobile.com/) |
| 8 * | 9 * |
| 9 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 11 * modify it under the terms of the GNU Library General Public |
| 11 * License as published by the Free Software Foundation; either | 12 * License as published by the Free Software Foundation; either |
| 12 * version 2 of the License, or (at your option) any later version. | 13 * version 2 of the License, or (at your option) any later version. |
| 13 * | 14 * |
| 14 * This library is distributed in the hope that it will be useful, | 15 * This library is distributed in the hope that it will be useful, |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 * Library General Public License for more details. | 18 * Library General Public License for more details. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 buffer.append(string.data(), string.length()); | 46 buffer.append(string.data(), string.length()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 static inline void appendPercentEncoded(Vector<char>& buffer, unsigned char c) { | 49 static inline void appendPercentEncoded(Vector<char>& buffer, unsigned char c) { |
| 49 append(buffer, '%'); | 50 append(buffer, '%'); |
| 50 appendByteAsHex(c, buffer); | 51 appendByteAsHex(c, buffer); |
| 51 } | 52 } |
| 52 | 53 |
| 53 static void appendQuotedString(Vector<char>& buffer, const CString& string) { | 54 static void appendQuotedString(Vector<char>& buffer, const CString& string) { |
| 54 // Append a string as a quoted value, escaping quotes and line breaks. | 55 // Append a string as a quoted value, escaping quotes and line breaks. |
| 55 // FIXME: Is it correct to use percent escaping here? Other browsers do not en
code these characters yet, | 56 // FIXME: Is it correct to use percent escaping here? Other browsers do not |
| 56 // so we should test popular servers to find out if there is an encoding form
they can handle. | 57 // encode these characters yet, so we should test popular servers to find out |
| 58 // if there is an encoding form they can handle. |
| 57 size_t length = string.length(); | 59 size_t length = string.length(); |
| 58 for (size_t i = 0; i < length; ++i) { | 60 for (size_t i = 0; i < length; ++i) { |
| 59 char c = string.data()[i]; | 61 char c = string.data()[i]; |
| 60 | 62 |
| 61 switch (c) { | 63 switch (c) { |
| 62 case 0x0a: | 64 case 0x0a: |
| 63 append(buffer, "%0A"); | 65 append(buffer, "%0A"); |
| 64 break; | 66 break; |
| 65 case 0x0d: | 67 case 0x0d: |
| 66 append(buffer, "%0D"); | 68 append(buffer, "%0D"); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 boundary.append( | 134 boundary.append( |
| 133 0); // Add a 0 at the end so we can use this as a C-style string. | 135 0); // Add a 0 at the end so we can use this as a C-style string. |
| 134 return boundary; | 136 return boundary; |
| 135 } | 137 } |
| 136 | 138 |
| 137 void FormDataEncoder::beginMultiPartHeader(Vector<char>& buffer, | 139 void FormDataEncoder::beginMultiPartHeader(Vector<char>& buffer, |
| 138 const CString& boundary, | 140 const CString& boundary, |
| 139 const CString& name) { | 141 const CString& name) { |
| 140 addBoundaryToMultiPartHeader(buffer, boundary); | 142 addBoundaryToMultiPartHeader(buffer, boundary); |
| 141 | 143 |
| 142 // FIXME: This loses data irreversibly if the input name includes characters y
ou can't encode | 144 // FIXME: This loses data irreversibly if the input name includes characters |
| 143 // in the website's character set. | 145 // you can't encode in the website's character set. |
| 144 append(buffer, "Content-Disposition: form-data; name=\""); | 146 append(buffer, "Content-Disposition: form-data; name=\""); |
| 145 appendQuotedString(buffer, name); | 147 appendQuotedString(buffer, name); |
| 146 append(buffer, '"'); | 148 append(buffer, '"'); |
| 147 } | 149 } |
| 148 | 150 |
| 149 void FormDataEncoder::addBoundaryToMultiPartHeader(Vector<char>& buffer, | 151 void FormDataEncoder::addBoundaryToMultiPartHeader(Vector<char>& buffer, |
| 150 const CString& boundary, | 152 const CString& boundary, |
| 151 bool isLastBoundary) { | 153 bool isLastBoundary) { |
| 152 append(buffer, "--"); | 154 append(buffer, "--"); |
| 153 append(buffer, boundary); | 155 append(buffer, boundary); |
| 154 | 156 |
| 155 if (isLastBoundary) | 157 if (isLastBoundary) |
| 156 append(buffer, "--"); | 158 append(buffer, "--"); |
| 157 | 159 |
| 158 append(buffer, "\r\n"); | 160 append(buffer, "\r\n"); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void FormDataEncoder::addFilenameToMultiPartHeader( | 163 void FormDataEncoder::addFilenameToMultiPartHeader( |
| 162 Vector<char>& buffer, | 164 Vector<char>& buffer, |
| 163 const WTF::TextEncoding& encoding, | 165 const WTF::TextEncoding& encoding, |
| 164 const String& filename) { | 166 const String& filename) { |
| 165 // FIXME: This loses data irreversibly if the filename includes characters you
can't encode | 167 // FIXME: This loses data irreversibly if the filename includes characters you |
| 166 // in the website's character set. | 168 // can't encode in the website's character set. |
| 167 append(buffer, "; filename=\""); | 169 append(buffer, "; filename=\""); |
| 168 appendQuotedString( | 170 appendQuotedString( |
| 169 buffer, encoding.encode(filename, WTF::QuestionMarksForUnencodables)); | 171 buffer, encoding.encode(filename, WTF::QuestionMarksForUnencodables)); |
| 170 append(buffer, '"'); | 172 append(buffer, '"'); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void FormDataEncoder::addContentTypeToMultiPartHeader(Vector<char>& buffer, | 175 void FormDataEncoder::addContentTypeToMultiPartHeader(Vector<char>& buffer, |
| 174 const CString& mimeType) { | 176 const CString& mimeType) { |
| 175 append(buffer, "\r\nContent-Type: "); | 177 append(buffer, "\r\nContent-Type: "); |
| 176 append(buffer, mimeType); | 178 append(buffer, mimeType); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 appendPercentEncoded(buffer, c); | 228 appendPercentEncoded(buffer, c); |
| 227 } | 229 } |
| 228 } else { | 230 } else { |
| 229 appendPercentEncoded(buffer, c); | 231 appendPercentEncoded(buffer, c); |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 } | 235 } |
| 234 | 236 |
| 235 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |