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

Add support for 'data-raw' #15

Closed
wants to merge 2 commits into from
Closed

Conversation

dnkmdg
Copy link
Contributor

@dnkmdg dnkmdg commented Oct 13, 2022

Added support for providing data-raw according to #8.

My reasoning for the proposed solution is that they should never be present simultaneously, and if data-raw isn't present, then go for default behavior with the -d|data-option, giving data-raw a slight precedence over data.

@jasonmccreary
Copy link
Collaborator

After reading the man pages a few times, --data-raw is just --data without the file interpretation of @. As such, I don't believe it's mutually exclusive. Even though it is probably commonly used independently.

It does seem to have the raw aspect to it when used independently. So to align with the behavior of curl, I think there's more work to do here.

@dnkmdg
Copy link
Contributor Author

dnkmdg commented Oct 13, 2022

Yeah, there's some room for interpretation. While testing I found that when providing both --data-raw and --data in a cURL they're both ignored, at least in a Laravel context. I did try using both -d and --data, both yielding the same results. My conclusion is that either Laravel has a slight bug here, or at least an inconsistency in handling requests with multiple bodies. With that said, I would argue that it's better to be deterministic in this case, and treat them as mutually exclusive.

Route::post('/curl-test', function (Request $request) {
    return [
        '-d' => $request->simple_data,
        '--data-raw' => $request->raw_data,
    ];
});

Posting:

curl 'http://api.test/curl-test' \
  -H 'Content-Type: application/json' \
  --data-raw '{"raw_data":"test"}' 

yields {"-d":null,"--data-raw":"test"} as expected.

Posting:

curl 'http://api.test/curl-test' \
  -H 'Content-Type: application/json' \
  -d '{"simple_data":"test"}'

yields {"-d":"test","--data-raw":null} as expected.

However, posting:

curl 'http://api.test/curl-test' \
  -H 'Content-Type: application/json' \
  --data-raw '{"raw_data":"test"}' \
  -d '{"simple_data":"test"}'

Yields: {"-d":null,"--data-raw":null}

@jasonmccreary
Copy link
Collaborator

Agreed there's some interpretation here. I'm going off what curl does and not necessarily what Laravel does.

I think the way I'd like to handle it is if --data-raw is used independently, it's considered the raw body. If it is used with -d (which curl seems to allow), it's treated as another form data field.

I can code this up as it has some nuance.

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