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

perf: stream JSON in request body #5661

Merged

Conversation

anderseknert
Copy link
Member

Similar to how #5596 allowed streaming JSON from the response, do the same for the request. This has potentially bigger benefits, as the incoming request is commonly larger than the response (admission control, terraform, etc).

@netlify
Copy link

netlify bot commented Feb 15, 2023

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 9e2885d
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/63ecda26d2734400081fb30e
😎 Deploy Preview https://deploy-preview-5661--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

}
} else {
dec := util.NewJSONDecoder(r.Body)
if err := dec.Decode(&x); err != nil && err != io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't the decoder accept multiple JSON documents that are concatenated? Not sure what happens if we send {}{}{} for input... Probably nothing of consequence.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try!

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like it's accepted, but only the first form is read, which seems acceptable to me

curl -d '{"foo": "bar"}{"x":1}' localhost:8181/v0/data
{"decision_id":"...","input":{"foo":"bar"}

Similar to how open-policy-agent#5596
allowed streaming JSON in the response, do the same for the request.
This has potentially bigger benefits, as the incoming request is
commonly larger than the response (admission control, terraform, etc).

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert anderseknert merged commit ab14541 into open-policy-agent:main Feb 15, 2023
@anderseknert anderseknert deleted the json-stream-request branch February 15, 2023 13:32
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.

None yet

2 participants