Allow more chars to be sent unencoded and encode space as '+'.

While this produces not strictly valid query strings, it reduces the
encoding overhead significantly.
This commit is contained in:
Michael Lotz 2012-07-01 20:30:35 +02:00
parent 39a26a0aa5
commit 5dc5dbbbb4

View File

@ -103,9 +103,21 @@ encode_url(const char* query, const char* data, int encodeLength,
|| (character >= 'A' && character <= 'Z') || (character >= 'A' && character <= 'Z')
|| (character >= '0' && character <= '9') || (character >= '0' && character <= '9')
|| character == '.' || character == '-' || character == '_' || character == '.' || character == '-' || character == '_'
|| character == '~') { || character == '~'
// These aren't strictly valid, but seem to work.
|| character == '/' || character == '(' || character == ')'
|| character == '=' || character == '^' || character == '?'
|| character == '|' || character == '*' || character == '@'
|| character == ';' || character == ':' || character == ','
|| character == '{' || character == '}' || character == '['
|| character == ']' || character == '<' || character == '>'
|| character == '!' || character == '\\') {
sEncodeBuffer[position++] = character; sEncodeBuffer[position++] = character;
sEncodeBuffer[position] = 0; sEncodeBuffer[position] = 0;
} else if (character == ' ') {
// Encode spaces as '+' as that's shorter than %20.
sEncodeBuffer[position++] = '+';
sEncodeBuffer[position] = 0;
} else { } else {
// Encode to a %xx escape. // Encode to a %xx escape.
if (encodeLength - position < 3) { if (encodeLength - position < 3) {