Commit b9b9400
committed
Optionally require a valid content type for all rest requests with content (#22691)
This change adds a strict mode for xcontent parsing on the rest layer. The strict mode will be off by default for 5.x
and in a separate commit will be enabled by default for 6.0. The strict mode, which can be enabled by setting
`http.content_type.required: true` in 5.x, will require that all incoming rest requests have a valid and supported
content type header before the request is dispatched. In the non-strict mode, the Content-Type header will be inspected
and if it is not present or not valid, we will continue with auto detection of content like we have done previously.
The content type header is parsed to the matching XContentType value with the only exception being for plain text
requests. This value is then passed on with the content bytes so that we can reduce the number of places where we need
to auto-detect the content type.
As part of this, many transport requests and builders were updated to provide methods that accepted the XContentType
along with the bytes and the methods that would rely on auto-detection have been deprecated.
In the non-strict mode, deprecation warnings are issued whenever a request with body doesn't provide the Content-Type
header.
See #193881 parent 1925985 commit b9b9400
255 files changed
Lines changed: 3844 additions & 1053 deletions
File tree
- client
- benchmark/src/main/java/org/elasticsearch/client/benchmark/transport
- client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk
- core/src
- main/java/org/elasticsearch
- action
- admin
- cluster
- repositories/put
- settings
- snapshots
- create
- restore
- storedscripts
- indices
- analyze
- create
- mapping
- get
- put
- settings/put
- template/put
- bulk
- byscroll
- index
- ingest
- termvectors
- update
- client
- support
- cluster/metadata
- common
- settings
- loader
- xcontent
- json
- http
- index
- mapper
- query
- shard
- termvectors
- ingest
- rest
- action
- admin
- cluster
- indices
- document
- ingest
- search
- script
- test/java/org/elasticsearch
- action
- admin
- cluster
- node/tasks
- reroute
- storedscripts
- indices
- create
- mapping
- get
- put
- template
- put
- bulk
- byscroll
- index
- ingest
- search
- support
- termvectors
- update
- aliases
- bwcompat
- client
- cluster
- common
- settings
- loader
- xcontent/support
- discovery
- document
- get
- index
- engine
- mapper
- query
- replication
- shard
- translog
- indices
- analysis
- flush
- memory/breaker
- recovery
- stats
- template
- ingest
- mget
- recovery
- rest
- action
- admin/indices
- cat
- routing
- script
- search
- aggregations
- bucket
- metrics
- pipeline
- builder
- child
- fetch/subphase
- fields
- geo
- msearch
- preference
- query
- scroll
- simple
- sort
- snapshots
- test/search/aggregations/bucket
- threadpool
- update
- distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest
- docs/reference
- modules
- modules
- lang-expression/src/test/java/org/elasticsearch/script/expression
- lang-mustache/src
- main/java/org/elasticsearch/script/mustache
- test/java/org/elasticsearch/script/mustache
- percolator/src
- main/java/org/elasticsearch/percolator
- test/java/org/elasticsearch/percolator
- reindex/src
- main/java/org/elasticsearch/index/reindex
- remote
- test/java/org/elasticsearch/index/reindex
- remote
- transport-netty3/src/main/java/org/elasticsearch/http/netty3
- transport-netty4/src
- main/java/org/elasticsearch/http/netty4
- test/java/org/elasticsearch/http/netty4
- plugins
- mapper-size/src/test/java/org/elasticsearch/index/mapper/size
- repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage
- qa/smoke-test-http/src/test/java/org/elasticsearch/http
- test/framework/src/main/java/org/elasticsearch
- index/shard
- test
- rest
- yaml
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
| 99 | + | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
107 | | - | |
108 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
153 | 167 | | |
154 | 168 | | |
155 | 169 | | |
| |||
160 | 174 | | |
161 | 175 | | |
162 | 176 | | |
163 | | - | |
| 177 | + | |
164 | 178 | | |
165 | 179 | | |
166 | 180 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
96 | 98 | | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
102 | 117 | | |
103 | 118 | | |
104 | 119 | | |
| |||
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| |||
97 | 107 | | |
98 | 108 | | |
99 | 109 | | |
100 | | - | |
| 110 | + | |
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
| |||
122 | 132 | | |
123 | 133 | | |
124 | 134 | | |
| 135 | + | |
125 | 136 | | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
129 | 141 | | |
130 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
131 | 151 | | |
132 | 152 | | |
133 | 153 | | |
| |||
136 | 156 | | |
137 | 157 | | |
138 | 158 | | |
139 | | - | |
| 159 | + | |
140 | 160 | | |
141 | 161 | | |
142 | 162 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
| |||
84 | 95 | | |
85 | 96 | | |
86 | 97 | | |
| 98 | + | |
87 | 99 | | |
| 100 | + | |
88 | 101 | | |
89 | 102 | | |
90 | 103 | | |
91 | 104 | | |
92 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
93 | 114 | | |
94 | 115 | | |
95 | 116 | | |
| |||
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
| 292 | + | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| 298 | + | |
298 | 299 | | |
| 300 | + | |
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
303 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
304 | 320 | | |
305 | 321 | | |
306 | 322 | | |
| |||
313 | 329 | | |
314 | 330 | | |
315 | 331 | | |
316 | | - | |
| 332 | + | |
317 | 333 | | |
318 | 334 | | |
319 | 335 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| 151 | + | |
150 | 152 | | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
156 | 173 | | |
157 | 174 | | |
158 | 175 | | |
| |||
0 commit comments