Class: ElasticGraph::Support::FaradayMiddleware::MSearchUsingGetInsteadOfPost
- Inherits:
-
Data
- Object
- Data
- ElasticGraph::Support::FaradayMiddleware::MSearchUsingGetInsteadOfPost
- Defined in:
- lib/elastic_graph/support/faraday_middleware/msearch_using_get_instead_of_post.rb
Overview
Custom Faraday middleware that forces msearch calls to use an HTTP GET instead of an HTTP POST. While not necessary, it preserves a useful property: all “read” calls made by ElasticGraph use an HTTP GET, and HTTP POST requests are “write” calls. This allows the access policy to only grant HTTP GET access from the GraphQL endpoint, which leads to a more secure setup (as the GraphQL endpoint can be blocked from performing any writes).
Note: before elasticsearch-ruby 7.9.0, msearch used an HTTP GET request, so this simply restores that behavior. This results in an HTTP GET with a request body, but it works just fine and its what the Ruby Elasticsearch client did for years.
For more info, see: github.com/elastic/elasticsearch-ruby/issues/1005
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
-
#call(env) ⇒ Faraday::Response
Processes a Faraday request, converting
_msearchPOST requests to GET requests.
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app
24 25 26 |
# File 'lib/elastic_graph/support/faraday_middleware/msearch_using_get_instead_of_post.rb', line 24 def app @app end |
Instance Method Details
#call(env) ⇒ Faraday::Response
Processes a Faraday request, converting _msearch POST requests to GET requests.
31 32 33 34 |
# File 'lib/elastic_graph/support/faraday_middleware/msearch_using_get_instead_of_post.rb', line 31 def call(env) env.method = :get if env.url.path.to_s.end_with?("/_msearch") app.call(env) end |