-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix the CBOR Content Header-related issue. #464
Fix the CBOR Content Header-related issue. #464
Conversation
659b91f
to
58d8c2f
Compare
Here are the set of steps used for testing, where some steps become applicable once the the second
|
|
internal/common/utils.go
Outdated
ChecksumAlgoxxHash = "xxHash" | ||
checksumContextKey = "payload-checksum" |
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.
Following my other comment regarding unused functionality, this would also be removed if the other "Reader" functionality is removed.
internal/autoevent/executor.go
Outdated
@@ -75,7 +75,7 @@ func readResource(e *executor) (*dsModels.Event, common.AppError) { | |||
vars[common.NameVar] = e.deviceName | |||
vars[common.CommandVar] = e.autoEvent.Resource | |||
|
|||
evt, appErr := handler.CommandHandler(vars, "", common.GetCmdMethod, "") | |||
evt, appErr := handler.CommandHandler(vars, "", common.GetCmdMethod, "", nil) |
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.
Quickly looking at this, I think there may be a bug here. We are passing in nil
for the r *http.Request
. However, in the called function it never checks if the value is nil
but performs some operations on r
. For example:
device-sdk-go/internal/handler/command.go
Lines 488 to 494 in 58d8c2f
if r.Header.Get(clients.ContentType) == clients.ContentTypeCBOR { | |
// Handle Content-type CBOR and populate paramMap | |
err = codec.NewDecoderBytes([]byte(params), &codec.CborHandle{}).Decode(¶mMap) | |
} else if r.Header.Get(clients.ContentType) == clients.ContentTypeJSON { | |
// Handle Content-type JSON and populate paramMap | |
err = json.Unmarshal([]byte(params), ¶mMap) | |
} |
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.
- In revisiting this, one approach would be to change the signature of the following function (in
/device-sdk-go/internal/autoevent/executor.go
) as indicated below, which could then callevt, appErr := handler.CommandHandler(vars, "", req)
func readResource(e *executor, req *http.Request) (*dsModels.Event, common.AppError) {
...
...
evt, appErr := handler.CommandHandler(vars, "", req)
...
...
}
- The challenge will be the call
evt, appErr := readResource(e, nil)
from its calling function, which is as follows and, specifically, how to introduce and pass in a parameter of type*http.Request
:
// Run triggers this Executor executes the handler for the resource periodically
func (e *executor) Run() { ... }
@@ -452,3 +466,9 @@ func TestCommandHandler(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func newRequestWithContentType(contentType string) *http.Request { |
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 do not see any tests that cover using the application/cbor
content type nor an empty, or invalid content type. Can we add some tests to cover those cases?
Would be better to land the PR for edgexfoundry/edgex-go#2272 first? The reason I ask is because we can:
Also, if you decide to use the "Reader" functionality, it exists in |
|
121ae82
to
8eaf976
Compare
92ab471
to
9dc7c52
Compare
As per my conversation with @akramtexas, we are putting these changes on hold in favor of completing edgexfoundry/edgex-go#2272 first. This will allow us to ensure that the |
Yes, exactly, @AnthonyMBonafide and thanks for the excellent feedback on this and the other |
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.
Please re-request me for a review once the depending issue edgexfoundry/edgex-go#2272 has been completed.
Will do ✅ |
6e80231
to
a3da746
Compare
This PR is associated with #479 |
1556322
to
c997980
Compare
Codecov Report
@@ Coverage Diff @@
## master #464 +/- ##
==========================================
- Coverage 57.50% 54.61% -2.89%
==========================================
Files 25 25
Lines 3144 2479 -665
==========================================
- Hits 1808 1354 -454
+ Misses 1211 1019 -192
+ Partials 125 106 -19
Continue to review full report at Codecov.
|
c997980
to
093062c
Compare
Rebased. |
5992b07
to
1343d84
Compare
@@ -96,6 +96,9 @@ https://github.com/pmezard/go-difflib/blob/master/LICENSE | |||
stretchr/testify (MIT) https://github.com/stretchr/testify | |||
https://github.com/stretchr/testify/blob/master/LICENSE | |||
|
|||
ugorji/go (MIT) https://github.com/ugorji/go | |||
https://github.com/ugorji/go/blob/master/LICENSE | |||
|
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.
Please update the reference to the CBOR library per edgexfoundry/edgex-go#2490
Signed-off-by: Akram Ahmad <sftwr2020@gmail.com>
1343d84
to
f9e2813
Compare
Rebased |
Closing this PR as it is not needed to fix the bug we were originally intending to fix. Although this functionality is great it is not needed. A new feature request was created to add this functionality later( #488 ). There is a reference to this PR which can be used when we decide to take on that work. |
PR
s that will address Response of issueDeviceCommand is not providing CBOR Content-Type header edgex-go#2272 ("Response of issueDeviceCommand is not providing CBOR Content-Type header").PR
(inedgex-go
) will be submitted subsequently, since it is dependent on the work done in the firstPR
(this current one).