nushell/crates/nu-command
Anas Alkhatib b072d75300
http post --content-type should set Content-Type header (#9431)
Parse the data from string to json if the `--content-type
"application/json"` flag is used for the request.

Fixes: https://github.com/nushell/nushell/issues/9408

In the issue, the actual data is a string `'{ "query": "{ greeting }"
}'` representing json, and it would match the case `Value::String { val,
.. }`


-------------------------

The example in the issue does set the `content-type` to
`application/json` but sends the body as a string note the `'`.

```
(
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   '{ "query": "{ greeting }" }'
::: )
```

```
╭─────────┬───────────────────────╮
│ headers │ {record 14 fields}    │
│ body    │ {"content_type":null} │
│ status  │ 200                   │
╰─────────┴───────────────────────╯
```

If we send the same request but using actual json as the body, the
Header is set correctly.

```
(        
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   { "query": "{ greeting }" }
::: )
```
```

╭─────────┬─────────────────────────────────────╮
│ headers │ {record 14 fields}                  │
│ body    │ {"content_type":"application/json"} │
│ status  │ 200                                 │
╰─────────┴─────────────────────────────────────╯
```
2023-06-15 06:51:35 -05:00
..
assets refactor html module (#5246) 2022-04-20 08:50:14 -05:00
src http post --content-type should set Content-Type header (#9431) 2023-06-15 06:51:35 -05:00
tests Break up interdependencies of command crates (#9429) 2023-06-14 23:12:55 +02:00
Cargo.toml Break up interdependencies of command crates (#9429) 2023-06-14 23:12:55 +02:00
LICENSE Fix rest of license year ranges (#8727) 2023-04-04 09:03:29 +12:00