SolidWallOfCode commented on a change in pull request #5812: URL: https://github.com/apache/trafficserver/pull/5812#discussion_r426095251
########## File path: include/tscpp/api/HttpMsgComp.h ########## @@ -0,0 +1,472 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/** + * @file HttpMsgComp.h + * + * Classes for convenient manipulation of HTTP message components. + */ + +/* +Note: The clases in this include file may be used independently from the rest of the C++ API. +*/ + +#pragma once + +#undef assert +#if defined(__OPTIMIZE__) +#define assert(EXPR) static_cast<void>(0) +#else +#define assert TSAssert +#endif + +#include <string_view> +#include <utility> + +#include <ts/ts.h> + +#include <tscpp/api/noncopyable.h> + +/* +Note: These clases are designed to create intances as local variables in functions. It is expected that compiler +optimization will prevent the use of references from creating run-time overhead (see https://godbolt.org/z/KJZkno ). +In TS API hook handling code, no TS API function may be called after the call to TSHttpTxnReenable() (which is +called by the resume() and error() member functions of atscppapi::Transaction). TS API functions are called by the +destructors of these classes. Therefore, blocks containing instances of these claesses must end before the call to +TSHttpTxnReenable(). +*/ + +namespace atscppapi +{ +class MsgBase; + +class MimeField +{ +public: + // If loc is TS_NULL_MLOC, instance constructed in empty state. + // + explicit MimeField(MsgBase &msg, TSMLoc loc = TS_NULL_MLOC) : _msg(msg), _loc(loc) {} + + // MimeField at (zero-base) index idx in HTTP message. + // + MimeField(MsgBase &msg, int idx); + + // MimeField with given name in HTTP message. + // + MimeField(MsgBase &msg, std::string_view name); + + TSMLoc + loc() const + { + return _loc; + } + + MsgBase & + msg() const + { + return _msg; + } + + // Valid means non-empty. + // + bool valid() const; + + // Put instance into empty state, releasing resources as appropriate. + // + void reset(); + + // Can not copy, only move. + + MimeField(const MimeField &) = delete; + MimeField &operator=(const MimeField &) = delete; + + MimeField(MimeField &&source); + + // Move assign only allowed if the two instances refer to the same message. Review comment: Actually, you can, I do it, but it is a bit of a cheat. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
