Skip to content

Commit 72f96a2

Browse files
committed
in_http: add descriptions about Content-Type
Need to add `application/x-ndjson` and `application/csp-report`. Related: * fluent/fluentd#3616 * fluent/fluentd#4282 Signed-off-by: Daijiro Fukuda <[email protected]>
1 parent e8cda55 commit 72f96a2

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

input/http.md

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,43 @@ For the full list of the configurable options, see the [Parameters](http.md#para
2222

2323
## Basic Usage
2424

25-
Here is a simple example to post a record using `curl`, which uses the default Content-Type `application/x-www-form-urlencoded`
25+
By default, the data format depends on the `Content-Type`.
26+
In summary, you can send the follwoing format.
2627

27-
```text
28-
# Post a record with the tag "app.log"
29-
$ curl -X POST -d 'json={"foo":"bar"}' http://localhost:9880/app.log
28+
* `json`
29+
* `ndjson`
30+
* `msgpack`
31+
32+
Here is a simple example to post a record using `curl`, which uses the default Content-Type `application/x-www-form-urlencoded`.
33+
34+
Example: post JSON data with the tag "app.log":
35+
36+
```bash
37+
curl -X POST -d 'json={"foo":"bar"}' http://localhost:9880/app.log
38+
```
39+
40+
Example: post NDJSON data with the tag "app.log":
41+
42+
```bash
43+
ndjson=`echo -e 'ndjson={"k1":"v1"}\n{"k2":"v2"}\n'`
44+
curl -X POST -d "$ndjson" http://localhost:9880/app.log
45+
```
46+
47+
Example: post MessagePack data with the tag "app.log":
48+
49+
```bash
50+
msgpack=`echo -e "msgpack=\x81\xa3foo\xa3bar"`
51+
curl -X POST -d "$msgpack" http://localhost:9880/app.log
52+
```
53+
54+
Some `Content-Type` other than `application/x-www-form-urlencoded` support specific formats.
55+
In that case, the format type specification as `json=` in the data is not necessary.
56+
57+
Example: Post JSON data with `Content-Type: application/json`:
58+
59+
```bash
60+
curl -X POST -d '{"foo":"bar"}' -H 'Content-Type: application/json' \
61+
http://localhost:9880/app.log
3062
```
3163

3264
**For more details regarding the message body syntax and `Content-Type` see [How to use HTTP Content-Type Header](http.md#how-to-use-http-content-type-header)**
@@ -230,24 +262,39 @@ $ curl -X POST -d "msgpack=$msgpack" http://localhost:9880/app.log
230262

231263
`in_http` plugin recognizes HTTP `Content-Type` header in the incoming requests.
232264

233-
By default `curl` uses `-H "Content-Type: application/x-www-form-urlencoded"`, which allows the use of the syntax `json=` and `msgpack=` as seen on the previous examples.
234-
265+
If you use the default `<parse>` setting, the data format depends on the `Content-Type`.
266+
(If you set the `<parse>` directive to use a specific Parser, the `Content-Type` is not used).
235267

236-
However, you can send a JSON payload without the `json=` prefix by setting the content type `application/json`:
268+
By default `curl` uses `-H "Content-Type: application/x-www-form-urlencoded"`, which allows the use of the prefix `json=`, `ndjson=`, and `msgpack=` as seen on the previous examples.
237269

238-
```text
239-
$ curl -X POST -d '{"foo":"bar"}' -H 'Content-Type: application/json' \
270+
On the other hand, some `Content-Type` other than `application/x-www-form-urlencoded` support specific formats.
271+
In that case, the prefix such as `json=` in the data is not necessary.
272+
273+
Here is the list of supported `Content-Type`:
274+
275+
| `Content-Type` | data format | version |
276+
| :--- | :--- | :--- |
277+
| `application/json` | JSON | - |
278+
| `application/csp-report` | JSON | 1.17.0 |
279+
| `application/msgpack` | MessagePack | - |
280+
| `application/x-ndjson` | NDJSON | 1.14.5 |
281+
282+
Examples:
283+
284+
```bash
285+
curl -X POST -d '{"foo":"bar"}' -H 'Content-Type: application/json' \
240286
http://localhost:9880/app.log
241287
```
242288

243-
To use MessagePack, set the content type to `application/msgpack`:
244-
245-
```text
246-
$ msgpack=`echo -e "\x81\xa3foo\xa3bar"`
247-
$ curl -X POST -d "$msgpack" -H 'Content-Type: application/msgpack' \
289+
```bash
290+
msgpack=`echo -e "\x81\xa3foo\xa3bar"`
291+
curl -X POST -d "$msgpack" -H 'Content-Type: application/msgpack' \
248292
http://localhost:9880/app.log
249293
```
250294

295+
Also, you can use `multipart/form-data`.
296+
For more details about `multipart/form-data`, please see [Why `in_http` removes '+' from my log](http.md#why-in_http-removes--from-my-log).
297+
251298
### Handle Other Formats using Parser Plugins
252299

253300
You can handle various input formats by using the `<parse>` directive. For example, add the following settings to the configuration file:

0 commit comments

Comments
 (0)