Skip to content

Commit

Permalink
HttpHeaders: Small code refactorings
Browse files Browse the repository at this point in the history
Also check BList::Add() for success when adding a BHttpHeader.
  • Loading branch information
stippi committed Jun 5, 2014
1 parent 79852c5 commit cb1a99c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions headers/os/net/HttpHeaders.h
Expand Up @@ -76,6 +76,7 @@ class BHttpHeaders {

private:
void _EraseData();
bool _AddOrDeleteHeader(BHttpHeader* header);

private:
BList fHeaderList;
Expand Down
37 changes: 17 additions & 20 deletions src/kits/network/libnetapi/HttpHeaders.cpp
Expand Up @@ -147,12 +147,11 @@ BHttpHeaders::BHttpHeaders()
}


BHttpHeaders::BHttpHeaders(const BHttpHeaders& copy)
BHttpHeaders::BHttpHeaders(const BHttpHeaders& other)
:
fHeaderList()
{
for (int32 i = 0; i < copy.CountHeaders(); i++)
AddHeader(copy.HeaderAt(i).Name(), copy.HeaderAt(i).Value());
*this = other;
}


Expand Down Expand Up @@ -215,7 +214,7 @@ BHttpHeaders::HasHeader(const char* name) const
return i;
}

return B_ERROR;
return -1;
}


Expand All @@ -225,28 +224,14 @@ BHttpHeaders::HasHeader(const char* name) const
bool
BHttpHeaders::AddHeader(const char* line)
{
BHttpHeader* heapHeader = new(std::nothrow) BHttpHeader(line);

if (heapHeader != NULL) {
fHeaderList.AddItem(heapHeader);
return true;
}

return false;
return _AddOrDeleteHeader(new(std::nothrow) BHttpHeader(line));
}


bool
BHttpHeaders::AddHeader(const char* name, const char* value)
{
BHttpHeader* heapHeader = new(std::nothrow) BHttpHeader(name, value);

if (heapHeader != NULL) {
fHeaderList.AddItem(heapHeader);
return true;
}

return false;
return _AddOrDeleteHeader(new(std::nothrow) BHttpHeader(name, value));
}


Expand Down Expand Up @@ -315,3 +300,15 @@ BHttpHeaders::_EraseData()
delete header;
}
}


bool
BHttpHeaders::_AddOrDeleteHeader(BHttpHeader* header)
{
if (header != NULL) {
if (fHeaderList.AddItem(header))
return true;
delete header;
}
return false;
}

0 comments on commit cb1a99c

Please sign in to comment.