-
Notifications
You must be signed in to change notification settings - Fork 151
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
Add Message Headers #394
Add Message Headers #394
Conversation
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
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.
A few suggestions and comments.
src/NATS.Client/Msg.cs
Outdated
internal static readonly string Header = "NATS/1.0\r\n"; | ||
internal static readonly byte[] HeaderBytes = Encoding.UTF8.GetBytes(Header); | ||
internal static readonly int HeaderLen = HeaderBytes.Length; | ||
internal static readonly int MinimalValidHeaderLen = Encoding.UTF8.GetBytes(Header + "k:v\r\n\r\n").Length; |
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.
Does this mean there is always a value?
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.
Good point... while there's some debate it looks like some HTTP header implementations will support empty values - we should as well. I'll update and test for that. Thanks.
@@ -21,6 +21,7 @@ internal sealed class MsgArg | |||
internal string subject; | |||
internal string reply; | |||
internal long sid; | |||
internal int hdr; |
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.
internal int hdr; | |
internal int hdr; |
* Performance updates * Avoid warning in test API usage * Upgrade test packages * Require .NET 4.6 to use the latest NameValueCollection class Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
Signed-off-by: Colin Sullivan <[email protected]>
I think this should be good to go, would appreciate another quick pass @watfordgnf. I also addressed the performance issues with Splits. Had to move up to .NET 4.6 to use the IMO it should be OK to move to 4.6 as the oldest supported framework version. |
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 don't think you can get away with a simple map. You need to extend to make sure that keys are stored/retried in their canonical form.
Support for multiple values also means that key "Foo" may return an array of ["value1", "value2"] and not a single string of "value1, value2".
Finally, it is possible to receive a multiple line value. So this:
NATS/1.0\r\nTwo-Lines: this is\r\n a multilines value\r\n\r\n
needs to become "Tow-Lines": "this is a multilines value". Notice that the value spreads on 2 lines and start with a space:" a multilines..." the space will then be removed a concatenated to the previous line.
mh.Add("foo", "bar"); | ||
mh.Add("foo", "baz"); | ||
|
||
Assert.Equal("bar,baz", mh["foo"]); |
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 don't think this is correct. If there are 2 keys in the headers, you should return an array of strings, not a concatenated, comma separated, string.
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've updated the example documentation and tests, look for string[] values = mh.GetValues("foo");
@kozlovic , great points - thanks! Because MsgHeader is a subclass of I'll add tests for the |
I can also add checks to make sure the keys are in canonical form. The server handled the tests fine though... |
Because in most cases it does not do anything with the headers. But there is currently 1 case where the server will read headers, it is for JS publish de-dup and in that case it will look for "Msg-Id" and so if the user sets to "msg-id" and library doesn't use canonical form, then server won't de-dup. |
yeah, server doesnt follow http spec, so gotta be careful. Also soon hopefully we'll add headers for tracing. I dont know .net but since you mentioned a hash map I'll also say that order of headers cant change - technically only the order of the same header more than once - but in general its probably a good idea not to tweak order |
Signed-off-by: Colin Sullivan <[email protected]>
FYI, I've made various updates to cover what HTTP headers do, improve performance, and demonstrate multiple values in the documentation example and tests. |
Signed-off-by: Colin Sullivan <[email protected]>
Are we g2g? |
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.
Saw one fix and had some minor comments.
src/NATS.Client/Conn.cs
Outdated
@@ -2003,7 +2009,7 @@ private int setMsgArgsAryOffsets(byte[] buffer, long length) | |||
int i = 0; | |||
|
|||
// We only support 4 elements in this protocol version |
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.
Is this still 4?
src/NATS.Client/Msg.cs
Outdated
} | ||
|
||
// buffer for parsing strings | ||
public char[] stringBuf = new char[64]; |
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 should likely be internal.
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.
Oof - thanks - will fix!
Signed-off-by: Colin Sullivan <[email protected]>
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.
Looks good.
Thanks! Good catch on the size of the args, appreciate it. Turns out I didn't resize the array - embarrassing, but would have been much more so after a release. :) |
Signed-off-by: Colin Sullivan <[email protected]>
Adding NATS message headers to parallel nats-io/nats.go#560.
Also see https://github.com/nats-io/nats-server/blob/master/doc/adr/0004-nats-headers.md
This also includes a change in CI testing to pull the NATS server from a dependency repository. This allows for testing against unreleased edge features.