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

net_http_request table from net plugin fails to handle jsonb_build_object in WHERE clauses #255

Open
hellupline opened this issue Nov 12, 2022 · 1 comment

Comments

@hellupline
Copy link

when I use a jsonb_object with both keys and values as literal arrays, the request runs as expected,
but when I use an ARRAY [...] or jsonb_build_object the result is a empty set,
when the request hit the target server, the request is also missing headers,
and if using jsonb_build_object on body, body also goes empty

this snipplet contains 3 example cases

-- success
SELECT *
FROM net_http_request
WHERE
    url = 'https://webhook.site/6cf89317-df09-40bb-b14a-30b4e83412a9?case=1'
    AND method = 'POST'
    AND request_headers = jsonb_object(
        '{accept, content-type, authorization}',
        '{application/json, application/json, Bearer testing}'
    )
    AND request_body = jsonb_object(
        '{key}',
        ARRAY ['value']
    )::TEXT;
​
​
--- no headers sent
SELECT *
FROM net_http_request
WHERE
    url = 'https://webhook.site/6cf89317-df09-40bb-b14a-30b4e83412a9?case=2'
    AND method = 'POST'
    AND request_headers = jsonb_object(
        '{accept, content-type, authorization}',
        ARRAY ['application/json', 'application/json', FORMAT('Bearer %s', 'testing')]
    )
    AND request_body = jsonb_object(
        '{key}',
        ARRAY ['value']
    )::TEXT;
​
​
-- no header, no body sent
SELECT *
FROM net_http_request
WHERE
    url = 'https://webhook.site/6cf89317-df09-40bb-b14a-30b4e83412a9?case=3'
    AND method = 'POST'
    AND request_headers = jsonb_build_object(
        'accept', 'application/json',
        'content-type', 'application/json',
        'authorization', 'Bearer testing'
    )
    AND request_body = jsonb_build_object(
        'key', ARRAY ['value']
    )::TEXT;
​
​
​-- all 3 json objects on `TEXT` serialization are equal
SELECT
    jsonb_object(
        '{accept, content-type, authorization}',
        ARRAY ['application/json', 'application/json', FORMAT('Bearer %s', 'testing')]
    )::TEXT =
    jsonb_object(
        '{accept, content-type, authorization}',
        '{application/json, application/json, Bearer testing}'
    )::TEXT,
    jsonb_object(
        '{accept, content-type, authorization}',
        ARRAY ['application/json', 'application/json', FORMAT('Bearer %s', 'testing')]
    )::TEXT =
    jsonb_build_object(
        'accept', 'application/json',
        'content-type', 'application/json',
        'authorization', 'Bearer testing'
    )::TEXT;
@hellupline
Copy link
Author

hellupline commented Nov 14, 2022

update:
I did manage to avoid the issue using a "proxy" function:

CREATE OR REPLACE FUNCTION fix_jsonb(token TEXT) RETURNS TEXT
    LANGUAGE SQL
    IMMUTABLE
    RETURN jsonb_object(
        '{accept, content-type, authorization}',
        ARRAY ['application/json', 'application/json', FORMAT('Bearer %s', token)]
    )::TEXT;
SELECT *
FROM net_http_request
WHERE
    url = 'https://webhook.site/6cf89317-df09-40bb-b14a-30b4e83412a9?case=2'
    AND method = 'POST'
    AND request_headers = fix_jsonb('hello')::JSONB
    AND request_body = jsonb_object(
        '{key}',
        ARRAY ['value']
    )::TEXT;

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

No branches or pull requests

1 participant