The method returned false for present but empty "unknown" headers.
The fixed version is also faster, closing an old optimization XXX.
continue;
String value;
const char *name = e->name.termedBuf();
- if (!getByNameIfPresent(name, strlen(name), value) ||
+ if (!hasNamed(name, strlen(name), &value) ||
(value != fresh->getByName(name)))
return true;
}
{
String result;
// ignore presence: return undefined string if an empty header is present
- (void)getByNameIfPresent(name, strlen(name), result);
+ (void)hasNamed(name, strlen(name), &result);
return result;
}
{
String result;
// ignore presence: return undefined string if an empty header is present
- (void)getByNameIfPresent(name, result);
+ (void)hasNamed(name, &result);
return result;
}
HttpHeader::getById(Http::HdrType id) const
{
String result;
- (void)getByIdIfPresent(id,result);
+ (void)getByIdIfPresent(id, &result);
return result;
}
bool
-HttpHeader::getByNameIfPresent(const SBuf &s, String &result) const
+HttpHeader::hasNamed(const SBuf &s, String *result) const
{
- return getByNameIfPresent(s.rawContent(), s.length(), result);
+ return hasNamed(s.rawContent(), s.length(), result);
}
bool
-HttpHeader::getByIdIfPresent(Http::HdrType id, String &result) const
+HttpHeader::getByIdIfPresent(Http::HdrType id, String *result) const
{
if (id == Http::HdrType::BAD_HDR)
return false;
if (!has(id))
return false;
- result = getStrOrList(id);
+ if (result)
+ *result = getStrOrList(id);
return true;
}
bool
-HttpHeader::getByNameIfPresent(const char *name, int namelen, String &result) const
+HttpHeader::hasNamed(const char *name, int namelen, String *result) const
{
Http::HdrType id;
HttpHeaderPos pos = HttpHeaderInitPos;
while ((e = getEntry(&pos))) {
if (e->id == Http::HdrType::OTHER && e->name.size() == static_cast<String::size_type>(namelen) && e->name.caseCmp(name, namelen) == 0) {
found = true;
- strListAdd(&result, e->value.termedBuf(), ',');
+ if (!result)
+ break;
+ strListAdd(result, e->value.termedBuf(), ',');
}
}
String getByName(const SBuf &name) const;
String getByName(const char *name) const;
String getById(Http::HdrType id) const;
- /// sets value and returns true iff a [possibly empty] field identified by id is there
- bool getByIdIfPresent(Http::HdrType id, String &result) const;
- /// sets value and returns true iff a [possibly empty] named field is there
- bool getByNameIfPresent(const SBuf &s, String &value) const;
- bool getByNameIfPresent(const char *name, int namelen, String &value) const;
+ /// returns true iff a [possibly empty] field identified by id is there
+ /// when returning true, also sets the `result` parameter (if it is not nil)
+ bool getByIdIfPresent(Http::HdrType id, String *result) const;
+ /// returns true iff a [possibly empty] named field is there
+ /// when returning true, also sets the `value` parameter (if it is not nil)
+ bool hasNamed(const SBuf &s, String *value = 0) const;
+ bool hasNamed(const char *name, int namelen, String *value = 0) const;
String getByNameListMember(const char *name, const char *member, const char separator) const;
String getListMember(Http::HdrType id, const char *member, const char separator) const;
int has(Http::HdrType id) const;
return false;
value = hdr->getStrOrList(hdrId);
} else {
- if (!hdr->getByNameIfPresent(hdrName, value))
+ if (!hdr->hasNamed(hdrName, &value))
return false;
}
Adaptation::Ecap::HeaderRep::hasAny(const Name &name) const
{
const Http::HdrType squidId = TranslateHeaderId(name);
- // XXX: optimize to remove getByName: we do not need the value here
return squidId == Http::HdrType::OTHER ?
- theHeader.getByName(name.image().c_str()).size() > 0:
- (bool)theHeader.has(squidId);
+ theHeader.hasNamed(name.image().c_str(), name.image().size()) :
+ static_cast<bool>(theHeader.has(squidId));
}
Adaptation::Ecap::HeaderRep::Value
bool Adaptation::Icap::ModXact::expectIcapTrailers() const
{
String trailers;
- const bool promisesToSendTrailer = icapReply->header.getByIdIfPresent(Http::HdrType::TRAILER, trailers);
+ const bool promisesToSendTrailer = icapReply->header.getByIdIfPresent(Http::HdrType::TRAILER, &trailers);
const bool supportsTrailers = icapReply->header.hasListMember(Http::HdrType::ALLOW, "trailers", ',');
// ICAP Trailer specs require us to reject transactions having either Trailer
// header or Allow:trailers