HttpHeaders: header field names are case insensitive.
Whitespace before and after tokens should be ignored.
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <cstring>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
|
||||
#include <String.h>
|
||||
@@ -37,10 +38,10 @@ BHttpHeader::BHttpHeader(const char* string)
|
||||
|
||||
BHttpHeader::BHttpHeader(const char* name, const char* value)
|
||||
:
|
||||
fName(name),
|
||||
fValue(value),
|
||||
fRawHeaderValid(false)
|
||||
{
|
||||
SetName(name);
|
||||
SetValue(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +59,7 @@ BHttpHeader::SetName(const char* name)
|
||||
{
|
||||
fRawHeaderValid = false;
|
||||
fName = name;
|
||||
fName.Trim().CapitalizeEachWord();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,27 +68,25 @@ BHttpHeader::SetValue(const char* value)
|
||||
{
|
||||
fRawHeaderValid = false;
|
||||
fValue = value;
|
||||
fValue.Trim();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BHttpHeader::SetHeader(const char* string)
|
||||
{
|
||||
BString strLine(string);
|
||||
|
||||
fRawHeaderValid = false;
|
||||
fName.Truncate(0);
|
||||
fValue.Truncate(0);
|
||||
|
||||
int32 separatorLocation = strLine.FindFirst(": ");
|
||||
const char* separator = strchr(string, ':');
|
||||
|
||||
if (separatorLocation == B_ERROR)
|
||||
if (separator == NULL)
|
||||
return false;
|
||||
|
||||
strLine.MoveInto(fName, 0, separatorLocation);
|
||||
strLine.Remove(0, 2);
|
||||
fValue = strLine;
|
||||
|
||||
fName.SetTo(string, separator - string);
|
||||
fName.Trim().CapitalizeEachWord();
|
||||
SetValue(separator + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ BHttpHeader::Header() const
|
||||
bool
|
||||
BHttpHeader::NameIs(const char* name) const
|
||||
{
|
||||
return fName == BString(name);
|
||||
return fName == BString(name).Trim().CapitalizeEachWord();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user