-
Notifications
You must be signed in to change notification settings - Fork 844
Add classes for convenient manipulation in plugins of components of HTTP messages. #5812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2d7a00a to
514e60a
Compare
|
This code might be interesting to look at as a comparison. |
include/tscpp/api/HttpMsgComp.h
Outdated
| ~MimeField(); | ||
|
|
||
| private: | ||
| MsgBase &_msg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to copy over the MBuffer and MLoc instead of carrying a reference. It's cheap to do and removes any scope dependencies between them. It's quite possible to envision logic that gets the field and passes it on after the base object has gone out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't envision logic where it would be desirable to have multiple copies of these. Especially given the problem that they may go stale if you carry them from one hook to another. I gave a link to an example in the comments showing that gcc is good at optimizing out references, even when they are class members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to have copies than a hidden lifetime dependency. The copies are cheap. Going stale is the same issue in either case - I don't see why it matters if the staleness is via reference or copy. In both cases all instances need to have been cleaned up.
Consider code like
MimeField host;
if (some_flag) {
HttpMsg msg = get_proxy_request();
host = msg.findMimeField("Host");
} else {
HttpMsg msg = get_proxy_response();
host = msg.findMimeField("Host");
}
field.assign(pristine_host); // Woops, field depends on an out of scope object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with copies, your example is problematic. My current design is that ~HttpMsg() releases the TMLoc for the message. If it's not done in the destructor, then where? Why not:
HttpMsg msgReq = get_proxy_request();
HttpMsg msgRes = get_proxy_response();
MimeField host = (some_flag ? msgReq : msgResp).findMimeField("Host");
host.assign(pristine_host);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each object tracks its own TSMLoc and releases it when destructed.
Your example could be simplified down to
MimeFile host = (some_flag ? get_proxy_request() : get_proxy_response()).findMimeField("Host");
host.assign(pristine_host);
Which causes the problem again. Certainly the reference style could be made to work, but it imposes additional very non-obvious requirements on how the classes can be used, for very little (if any) benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what you're saying is that MimeField doesn't get its MBuffer and TSMLoc instances by a simple assign, it gets new values that refer to the same buffer and message header. What is the TS API call to get these new values? Is there a TS API call that can check that two distinct MBuffer/TSMLoc instances refer to the same object?
Certainly there are advantages to having pointers be shared_ptr or something similar (or using some other form of garbage collection). But it's not the C++ way to use this approach exclusively. Rightly or wrongly, the perception is that the CPP API is too high-overhead. So that argues against increasing overhead to make it perfectly ironclad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you are making multiple simple copies of the TSMLoc for the message headers: https://github.com/SolidWallOfCode/txn_box/blob/03093bf02e46f092691afe70d7b3d87151b2953a/plugin/include/txn_box/ts_util.h#L116 . Seems like your are leaking them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK looking at TSHandleMLocRelease(), it doesn't actually do anything for message header mlocs (HDR_HEAP_OBJ_HTTP_HEADER), are you saying we should rely on that fact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this function, https://github.com/SolidWallOfCode/txn_box/blob/03093bf02e46f092691afe70d7b3d87151b2953a/plugin/src/txn_box.cc#L122 , at what point does the returned TextView become stale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW (some_flag ? get_proxy_request() : get_proxy_response()).findMimeField("Host") would not compile in my stuff because moving is deleted for the message classes.
9a45bdb to
46be42a
Compare
|
@SolidWallOfCode for the "Transaction Box" stuff, do you have any gold tests that exercise it? If you're saying I should drop what I'm doing and work on Transaction Box instead, the problem is, it's not clear to me what all its goals are. I believe that a C++ utility, and yea even life itself, can still be worthwhile even if it uses neither std::tuple nor std::function. |
| MimeField | ||
| newMimeField() | ||
| { | ||
| assert(hasMsg()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use the ink_assert or ink_release_assert ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header is exported to plugin code, so it has to be TSAssert(). See line 31, I removed the use of C assert. I verified that __OPTIMIZE__ is defined by both clang and gcc. The problem with using TSAssert (or ink_assert) directly is that (as in the check above) you also don't want any functions in the boolean expression called in the non-debug build. (Although, it this particular case, it wouldn't matter as hasMsg() would be inlined and elided by the optimizer.)
include/tscpp/api/HttpMsgComp.h
Outdated
| bool | ||
| init(void *txnHndl) | ||
| { | ||
| assert(!hasMsg()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems obey the ATS Coding Style. See here https://cwiki.apache.org/confluence/display/TS/Coding+Style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify? I don't find any mention of assert in the Coding Style.
|
TxnBox doesn't have any gold tests, but the equivalent classes are used extensively in the code so there is a lot of example use. I'm currently working on writing replay files for testing purposes. The goals of TxnBox as a plugin aren't really relevant to this discussion. What is important from there is that it needs to interact with the C plugin API and wants to have C++ wrappers to do that, for which reason I have added code very similar to this. The point to address is, what are the goals of those C++ wrappers for the C plugin API? My version has been driven by the use cases that have arisen in TxnBox. For instance, there is a directive to set a field on the proxy request. How would that look with your utilities? |
include/tscpp/api/HttpMsgComp.h
Outdated
|
|
||
| MimeField(MimeField &&source); | ||
|
|
||
| // Move assign only allowed if the two instances refer to the same message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this restriction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you can't change a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you can, I do it, but it is a bit of a cheat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you do it?
|
@SolidWallOfCode It seems to me like what I'm doing is a thinner layer over the TS API HTTP message access functions. It's not immediately apparent to me what your goals are with the added complexity. |
|
Setting a field to a single new value, in the general case, would look like: |
4bc5467 to
6d93bc5
Compare
|
I'm not sure what you mean by "added complexity". I think copying the TS C API values is a simpler implementation that using references across objects, so in my view your implementation has added complexity both internally and externally. My goal is to make the use of the classes as simple and robust as possible. Users shouldn't have to carefully design their use to accommodate internal implementation restrictions - the implementation should accommodate any reasonable use. |
|
This is blocked by https://www.mail-archive.com/dev@trafficserver.apache.org/msg15104.html . Implementing this would allow the message objects to be copyable, which @SolidWallOfCode thinks is important. |
7be5328 to
e98399f
Compare
|
Note: this is TS CPPAPI, not Core. |
|
[approve ci autest] |
| # limitations under the License. | ||
|
|
||
| Test.Summary = ''' | ||
| Test tscpp/api/MsgComp.h:w |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No :w.
| 'proxy.config.diags.debug.tags': 'test_msg_comp', | ||
| }) | ||
|
|
||
| Test.PreparePlugin(Test.Variables.AtsTestToolsDir + '/plugins/test_msg_comp.cc', ts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to change this to build in core since that's the New World Order.
|
|
||
| #include <tscpp/api/HttpMsgComp.h> | ||
|
|
||
| // TSReleaseAssert() doesn't seem to produce any logging output for a debug build, so do both kinds of assert. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work now so change to simply use TSReleaseAssert().
a89efec to
626c6fb
Compare
…TTP messagess. These classes may be used independently of other parts of the TS CPP API.
|
This PR is working properly, but marked as draft because we're not sure we want it. |
…response body. Also add classes to CPP API for convenient manipulation of components of HTTP messagess. These classes may be used independently of other parts of the TS CPP API. (This PR is absorbing PR apache#5812.) Adds Au test with plugin forcing various errors on various hooks, with default body or set body.
…response body. Also add classes to CPP API for convenient manipulation of components of HTTP messagess. These classes may be used independently of other parts of the TS CPP API. (This PR is absorbing PR apache#5812.) Adds Au test with plugin forcing various errors on various hooks, with default body or set body.
…response body. Also add classes to CPP API for convenient manipulation of components of HTTP messagess. These classes may be used independently of other parts of the TS CPP API. (This PR is absorbing PR apache#5812.) Adds Au test with plugin forcing various errors on various hooks, with default body or set body.
|
As an alternative to HttpMsgComp.h, Alan proposes https://github.com/SolidWallOfCode/txn_box/blob/master/plugin/include/txn_box/ts_util.h https://github.com/SolidWallOfCode/txn_box/blob/master/plugin/src/ts_util.cc |
These classes may be used independently of other parts of the TS CPP API.