Skip to content

JSON handle from the request body is implicitly cleared #32

@Xelson

Description

@Xelson

We should at least provide an option to control this behavior

Proposal

There are two ways to improve this DX:

  1. Provide bool:delete_after_request = true argument for ezjson_option_set_body_from_json
native bool:ezhttp_option_set_body_from_json(EzHttpOptions:options_id, EzJSON:json, bool:pretty = false, bool:delete_after_request = true);
  1. Introduce ezjson_copy and ezjson_move to explicitly pass JSON handles with decided behaviour
MOVE_EzJSON:ezjson_move(EzJSON:handle) {
    return MOVE_EzJSON:handle;
}

MOVE_EzJSON:ezjson_copy(EzJSON:handle) {
    return MOVE_EzJSON:ezjson_deep_copy(handle);
}

and update function signature:

native bool:ezhttp_option_set_body_from_json(EzHttpOptions:options_id, MOVE_EzJSON:json, bool:pretty = false);

This approach will force compiler to throw tag mismatch warning when use JSON handles directly and will encourage developers to explicitly choose how to delegate JSON handles. For handles that were just created in the scope of calling this function, ezjson_move is suitable, while ezjson_copy is suitable for global handles

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions