Skip to content

Instantly share code, notes, and snippets.

@oschaaf
Last active November 27, 2015 19:10
Show Gist options
  • Save oschaaf/d6436459e73891364f96 to your computer and use it in GitHub Desktop.
Save oschaaf/d6436459e73891364f96 to your computer and use it in GitHub Desktop.
cpp lazyinit
class EndToEndHeadersContainer {
public:
EndToEndHeadersContainer() {
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1
const int kReserveSize = 36;
int index = 0;
StringPieceVector names(kReserveSize);
names[index++] = StringPiece(HttpAttributes::kAccept);
names[index++] = StringPiece(HttpAttributes::kAcceptEncoding);
names[index++] = StringPiece(HttpAttributes::kAccessControlAllowOrigin);
names[index++] = StringPiece(HttpAttributes::kAccessControlAllowCredentials);
names[index++] = StringPiece(HttpAttributes::kAge);
names[index++] = StringPiece(HttpAttributes::kAllow);
names[index++] = StringPiece(HttpAttributes::kAuthorization);
names[index++] = StringPiece(HttpAttributes::kCacheControl);
names[index++] = StringPiece(HttpAttributes::kContentDisposition);
names[index++] = StringPiece(HttpAttributes::kContentEncoding);
names[index++] = StringPiece(HttpAttributes::kContentLanguage);
names[index++] = StringPiece(HttpAttributes::kContentLength);
names[index++] = StringPiece(HttpAttributes::kContentType);
names[index++] = StringPiece(HttpAttributes::kCookie);
names[index++] = StringPiece(HttpAttributes::kCookie2);
names[index++] = StringPiece(HttpAttributes::kDate);
names[index++] = StringPiece(HttpAttributes::kEtag);
names[index++] = StringPiece(HttpAttributes::kExpires);
names[index++] = StringPiece(HttpAttributes::kHost);
names[index++] = StringPiece(HttpAttributes::kIfModifiedSince);
names[index++] = StringPiece(HttpAttributes::kIfNoneMatch);
names[index++] = StringPiece(HttpAttributes::kLastModified);
names[index++] = StringPiece(HttpAttributes::kLink);
names[index++] = StringPiece(HttpAttributes::kLocation);
names[index++] = StringPiece(HttpAttributes::kOrigin);
names[index++] = StringPiece(HttpAttributes::kPragma);
names[index++] = StringPiece(HttpAttributes::kPurpose);
names[index++] = StringPiece(HttpAttributes::kReferer);
names[index++] = StringPiece(HttpAttributes::kRefresh);
names[index++] = StringPiece(HttpAttributes::kServer);
names[index++] = StringPiece(HttpAttributes::kSetCookie2);
names[index++] = StringPiece(HttpAttributes::kSetCookie);
names[index++] = StringPiece(HttpAttributes::kUserAgent);
names[index++] = StringPiece(HttpAttributes::kVary);
names[index++] = StringPiece(HttpAttributes::kVia);
names[index++] = StringPiece(HttpAttributes::kWarning);
DCHECK_EQ(kReserveSize, index);
names_ = names;
}
StringPieceVector names_;
};
// Use lazy initialization here to avoid static initialization
base::LazyInstance<EndToEndHeadersContainer>::Leaky
foo = LAZY_INSTANCE_INITIALIZER;
const StringPieceVector HttpAttributes::SortedEndToEndHeaders() {
return foo.Get().names_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment