opa icon indicating copy to clipboard operation
opa copied to clipboard

Make http.send accept any json variant as application/json

Open mrvanes opened this issue 2 months ago • 7 comments

What is the underlying problem you're trying to solve?

Our SCIM server returns application/scim+json as a Content-Type header. We need to enable force_json_decode to get the raw_body parsed into body.

Describe the ideal solution

It would be nice if opa would understand that application/variant+json is just a variant of application/json for any variant of json so it would not be necessary to add force_json_decode to the request body.

Describe a "Good Enough" solution

users_request := {
    "url": "https://scimserver/Users",
    "method": "GET",
    "headers": {
        "x-api-key": "secret",
        "accept": "application/scim+json"
    }
}

... would return a valid decoded body in the result.

mrvanes avatar Apr 09 '24 09:04 mrvanes

Sounds like a reasonable improvement to me. If you'd like to submit a PR, that'd be neat 🙂

anderseknert avatar Apr 09 '24 10:04 anderseknert

"For more information, please re-read." -- I've removed my comment re force_json_decode, you're already aware. 😅

srenatus avatar Apr 09 '24 11:04 srenatus

💭 Right now, application/json is json-decoded, and application/yaml + application/x-yaml are yaml-decoded. So if we go with

users_request := {
    "url": "https://scimserver/Users",
    "method": "GET",
    "headers": {
        "x-api-key": "secret",
        "accept": "application/scim+json"
    }
}

would this mean it should do JSON? How would I declare that a certain extra header value means that it should be treated as YAML?

srenatus avatar Apr 09 '24 11:04 srenatus

No, my suggestion was not to use the "accept" header, that's just to show a correct SCIM request body. My suggestion is to be lenient about the returned application/<anything+>json Content-Type.

mrvanes avatar Apr 09 '24 11:04 mrvanes

Ah! Thanks for clarifying. Yeah, that makes this a bit simpler.

srenatus avatar Apr 09 '24 11:04 srenatus

This method handles the response processing which would need to be updated I think. Feel free to submit a PR if you'd like. Thanks.

ashutosh-narkar avatar Apr 09 '24 16:04 ashutosh-narkar