1
0
Fork 0

less string operations during batch request header parsing

This commit is contained in:
Jan Steemann 2014-09-29 13:56:45 +02:00
parent ec02ed2ccf
commit db0fdf24ec
1 changed files with 31 additions and 26 deletions

View File

@ -557,7 +557,7 @@ bool RestBatchHandler::extractPart (SearchHelper* helper) {
char* eol = strstr(found, "\r\n");
if (eol == 0) {
if (eol == nullptr) {
breakLength = 1;
eol = strchr(found, '\n');
@ -568,27 +568,30 @@ bool RestBatchHandler::extractPart (SearchHelper* helper) {
else {
char* eol2 = strchr(found, '\n');
if (eol2 != 0 && eol2 < eol) {
if (eol2 != nullptr && eol2 < eol) {
breakLength = 1;
eol = eol2;
}
}
if (eol == 0 || eol == found) {
if (eol == nullptr || eol == found) {
break;
}
// split key/value of header
char* colon = (char*) memchr(found, (int) ':', eol - found);
if (0 == colon) {
if (nullptr == colon) {
// invalid header, not containing ':'
return false;
}
// set up key/value pair
// set up the key
string key(found, colon - found);
StringUtils::trimInPlace(key);
if (key[0] == 'c' || key[0] == 'C') {
// got an interesting key. now process it
StringUtils::tolowerInPlace(&key);
// skip the colon itself
@ -598,10 +601,11 @@ bool RestBatchHandler::extractPart (SearchHelper* helper) {
++colon;
}
if ("content-type" == key) {
// extract the value, too
string value(colon, eol - colon);
StringUtils::trimInPlace(value);
if ("content-type" == key) {
if (_partContentType == value) {
hasTypeHeader = true;
}
@ -618,6 +622,7 @@ bool RestBatchHandler::extractPart (SearchHelper* helper) {
else {
// ignore other headers
}
}
found = eol + breakLength; // plus the \n
}