-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Compatible API header parsing plugin #60516
Closed
pgomulka
wants to merge
40
commits into
elastic:master
from
pgomulka:compat_plugin_inside_rest_request
Closed
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c6aeb38
draft
pgomulka e85833e
compatible version from a plugin
pgomulka 7f8b84a
moving compatibility function to a plugin
pgomulka 88598dc
remove unused interface
pgomulka c009235
suggested changes
jakelandis dce47ac
cleanup
jakelandis 3470081
more cleanup
jakelandis 72d7b13
Merge pull request #21 from jakelandis/jake-xpack-spi-request
pgomulka 6b06d7f
interface instead of function
pgomulka 5ec8038
testcase for combinations
pgomulka a45171e
add hascontent argumetn and pass tests
pgomulka 4ccf457
precommit
pgomulka 8770870
RestCompatibility plugin injected into RestRequest
pgomulka 0c6a5f7
Merge branch 'master' into compat_plugin_inside_rest_request
pgomulka 8e834b6
precommit
pgomulka 29fcc81
header validation test
pgomulka 8a0952b
precommit
pgomulka b3c626e
compatibleWithVersion on RestHandler
pgomulka 8f42c1d
import
pgomulka 924a35e
fake request with a default to current
pgomulka 0e0e590
split plugin interface
pgomulka 51376bb
rename file
pgomulka 03e9a63
remove evaluaiton depends on
pgomulka e790a5d
remove compatible function fron http server transport
pgomulka a2bc52f
cleanup
pgomulka 6724dda
add version to channel
pgomulka 3f606a3
fix nullpointer
pgomulka e834a9c
Apply suggestions from code review
pgomulka 4014a8d
javadoc and exception repalce
pgomulka 1a9339a
Merge branch 'master' into compat_plugin_channel2
pgomulka 541cf6d
remove exception and empty lines
pgomulka fd34207
Apply suggestions from code review
pgomulka b3e7654
add testcase to node init
pgomulka 1d5b099
unused import
pgomulka 1bb983b
Update server/src/main/java/org/elasticsearch/node/Node.java
pgomulka 448a8e7
Merge branch 'master' into compat_plugin_inside_rest_request
pgomulka 91011cc
Merge branch 'compat_plugin_inside_rest_request' of github.com:pgomul…
pgomulka 89d50f5
use media type parser
pgomulka 97baf91
spotless
pgomulka 324dd57
Merge branch 'master' into compat_plugin_inside_rest_request
pgomulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
server/src/main/java/org/elasticsearch/plugins/RestCompatibilityPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.plugins; | ||
|
||
import org.elasticsearch.ElasticsearchStatusException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Nullable; | ||
|
||
|
||
/** | ||
* An extension point for Compatible API plugin implementation. | ||
*/ | ||
public interface RestCompatibilityPlugin { | ||
/** | ||
* Returns a version which was requested on Accept and Content-Type headers | ||
* | ||
* @param acceptHeader - a media-type value from Accept header | ||
* @param contentTypeHeader - a media-type value from Content-Type header | ||
* @param hasContent - a flag indicating if a request has content | ||
* @return a requested Compatible API Version | ||
*/ | ||
Version getCompatibleVersion(@Nullable String acceptHeader, @Nullable String contentTypeHeader, Boolean hasContent) | ||
throws ElasticsearchStatusException; | ||
pgomulka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
35 changes: 35 additions & 0 deletions
35
server/src/main/java/org/elasticsearch/rest/CompatibleVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.rest; | ||
|
||
import org.elasticsearch.ElasticsearchStatusException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Nullable; | ||
|
||
/** | ||
* An interface used to specify a function that returns a compatible API version | ||
* Intended to be used in a code base instead of a plugin. | ||
*/ | ||
@FunctionalInterface | ||
public interface CompatibleVersion { | ||
jaymode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Version get(@Nullable String acceptHeader, @Nullable String contentTypeHeader, boolean hasContent) throws ElasticsearchStatusException; | ||
pgomulka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
CompatibleVersion CURRENT_VERSION = (acceptHeader, contentTypeHeader, hasContent) -> Version.CURRENT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,11 +79,18 @@ public boolean isContentConsumed() { | |
return contentConsumed; | ||
} | ||
|
||
// for testing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also if we make mediatypeparser even more strict, we could remove the RestRequest.parseContentType (line 504) and line 60 |
||
protected RestRequest(NamedXContentRegistry xContentRegistry, Map<String, String> params, String path, | ||
Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) { | ||
this(xContentRegistry, params, path, headers, httpRequest, httpChannel, requestIdGenerator.incrementAndGet()); | ||
} | ||
|
||
protected RestRequest(RestRequest restRequest) { | ||
this(restRequest.getXContentRegistry(), restRequest.params(), restRequest.path(), restRequest.getHeaders(), | ||
restRequest.getHttpRequest(), restRequest.getHttpChannel(), restRequest.getRequestId()); | ||
} | ||
|
||
|
||
private RestRequest(NamedXContentRegistry xContentRegistry, Map<String, String> params, String path, | ||
Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel, long requestId) { | ||
final XContentType xContentType; | ||
|
@@ -104,10 +111,7 @@ private RestRequest(NamedXContentRegistry xContentRegistry, Map<String, String> | |
this.requestId = requestId; | ||
} | ||
|
||
protected RestRequest(RestRequest restRequest) { | ||
this(restRequest.getXContentRegistry(), restRequest.params(), restRequest.path(), restRequest.getHeaders(), | ||
restRequest.getHttpRequest(), restRequest.getHttpChannel(), restRequest.getRequestId()); | ||
} | ||
|
||
|
||
/** | ||
* Invoke {@link HttpRequest#releaseAndCopy()} on the http request in this instance and replace a pooled http request | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add tests for this? Maybe in
NodeTests