-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
nsqd: fix mpub binary param parsing #921
Conversation
It was probably intended that you could specify "binary=true" or "binary=1" or "binary=True" etc. |
@ploxiln Yes, it is difficult for us to correct the non normalized uses now. I still suggest we correct and normalize the correct usage for v1.0, as the final release for 1.0 has not been released yet. :) We still has a time window to merge this. And, also we should record this backward uncompatibility clearly for end users. |
I agree with @ploxiln, I think the simplest improvement would be to explicitly check for |
We could treat values outside of the |
@jehiah Making
This seems good. However, we can not enumerate or simply assume that end users will only use As we are approaching to release v1.0, backward compatibility is an best effort instead of a guarantee. Please correct me if i am wrong. :) |
@andyxning sorry my comment might not have been clear. I'm saying that we can treat documented/expected values of ( |
@jehiah If i understand you correctly,
Is that correct? /cc @mreiferson @ploxiln |
Yes that's what we have in mind. |
If both of you agree with the |
👍🏻 |
b637c72
to
b876f94
Compare
Done. PTAL. |
b876f94
to
83022c3
Compare
Btw, can we make a appoint about at which version we will enforce the parse schema and forbid all deprecated binary param values? I think this may be needed to be placed in |
I think the functionality is correct. But the code (and the log message) is too verbose. Also, we need not accommodate anything but lowercase. So this can be shorter and simpler. One better option would be to use a single map like so: var boolParams = map[string]bool{
"true": true,
"false": false,
"1": true,
"0": false,
}
...
binary := false
param, ok := reqParams["binary"]
if ok {
binary, ok = boolParams[binaryParam]
if !ok {
binary = true
s.ctx.nsqd.logf(LOG_WARN, "deprecated value '%s' used for /mpub binary param")
}
}
if binary {
.... This even simpler version would also be fine in this situation, in my humble opinion: binary := false
param, ok := reqParams["binary"]
if param == "true" || param == "1" {
binary = true
} else if param == "false" || param == "0" {
binary = false
} else if ok {
binary = true
s.ctx.nsqd.logf(LOG_WARN, "deprecated value '%s' used for /mpub binary param")
}
if binary {
.... (I didn't use tabs just because I can't type them manually in this comment box.) I don't think it's worth testing that the log message is emitted. But it is a good idea to test that the binary param is interpreted the way we want (by having binary or text mode mpub requests accepted or rejected). |
0093e7d
to
ba48df8
Compare
@ploxiln Thanks for your advice. The code i wrote first was really complicated than yours. 👍 I have read your version and adjust may initial implementation. PTAL. Btw, i have added the binary param parse schema in the comment. |
nsqd/http.go
Outdated
} | ||
} | ||
|
||
if !ok || !binaryMode { |
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 this can just be if !binaryMode {
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.
Will do.
nsqd/http.go
Outdated
@@ -24,6 +24,13 @@ import ( | |||
"github.com/nsqio/nsq/internal/version" | |||
) | |||
|
|||
var binaryParams = map[string]bool{ |
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 called this "boolParams" because it could be used for other boolean params besides "binary" (we don't really have any other simple boolean params right now though).
If it was really only for "binary", we wouldn't put it in the file/package scope, we'd just put it in the only function that would use it.
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.
Sounds reasonable. Will do.
Looks OK to me. |
ba48df8
to
28389b0
Compare
@ploxiln Comments addressed. PTAL. |
Thanks for the updates. Still looks OK to me :) I have the ability to merge this, since just a few weeks ago, but I'd prefer to give more time for a thumbs-up from one of the other maintainers. |
Thanks @andyxning for the fix, and @ploxiln for leading review on this! |
Thanks for your review @ploxiln @jehiah @mreiferson |
According to the docs about
mput
.It indicates that:
binary
param is not specified, text mode is used.binary
param is specified"true"
, use binary mode"false"
, use text modeHowever, according to the implementation, if we specified
binary=false
in themput
url, it will be processed as binary mode which is wrong as we currently only check the existence ofbinary
url param. :)/cc @mreiferson @ploxiln @jehiah