Skip to content
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

support json HTTP announce #1296

Merged
merged 5 commits into from
Feb 22, 2023
Merged

support json HTTP announce #1296

merged 5 commits into from
Feb 22, 2023

Conversation

LexLuthr
Copy link
Contributor

Context

Fixes #1093

Proposed Changes

Instead of only accepting CBOR:

Read the request Content-Type header
if it is JSON,
parse the body as JSON
convert to CBOR
and pass onto the indexer internal handlers
Otherwise, fallback on CBOR decoding as it is working currently.

Tests

TestJSONSend

Revert Strategy

Change is safe to revert.

@LexLuthr LexLuthr requested a review from masih February 21, 2023 11:26
@masih masih requested a review from gammazero February 21, 2023 11:27
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2023

Codecov Report

Base: 54.66% // Head: 54.56% // Decreases project coverage by -0.11% ⚠️

Coverage data is based on head (f355f35) compared to base (2b664a8).
Patch coverage: 40.74% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1296      +/-   ##
==========================================
- Coverage   54.66%   54.56%   -0.11%     
==========================================
  Files         152      152              
  Lines       15657    15698      +41     
==========================================
+ Hits         8559     8565       +6     
- Misses       6126     6157      +31     
- Partials      972      976       +4     
Impacted Files Coverage Δ
announce/httpsender/sender.go 60.16% <37.50%> (-13.33%) ⬇️
server/ingest/http/server.go 46.07% <46.15%> (-1.18%) ⬇️
server/ingest/handler/ingest_handler.go 52.25% <100.00%> (+0.52%) ⬆️
dagsync/p2p/protocol/head/head.go 72.41% <0.00%> (-5.75%) ⬇️
dagsync/test/util.go 80.09% <0.00%> (-0.48%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines 93 to 99
buff := new(bytes.Buffer)
err = am.MarshalCBOR(buff)
if err != nil {
httpserver.HandleError(w, err, "announce")
return
}
err = s.ingestHandler.Announce(buff)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to pass the decoded message into Announce instead of re-encoding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making changes as per the suggestion

@LexLuthr LexLuthr requested a review from gammazero February 22, 2023 12:55
@gammazero gammazero merged commit d235c25 into main Feb 22, 2023
@gammazero gammazero deleted the lexluthr/json-http-announce branch February 22, 2023 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support JSON content type for direct HTTP announce
3 participants