Skip to content
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

Remove coercion of Console GET requests to POST #39170

Closed

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Jun 18, 2019

To-do

Verify all of these on master, then create tests for them:

In master, we should remove support for proxyConfig and proxyFilters (#11670, #9823).

Alternative solution

This alternative uses the http Node library which is more low-level but removes the need for the request dependency.

import http from 'http';

/* ... */

    handler: async (req, h) => {
      const { payload, query } = req;
      const { path, method } = query;
      const uri = resolveUri(baseUrl, path);
      const { timeout, rejectUnauthorized, agent, headers } = getConfigForReq(req, uri);

      return await new Promise((resolve) => {
        const {
          protocol,
          hostname,
          port,
          pathname,
          search,
        } = new URL(uri);

        const requestHeaders = {
          ...headers,
          ...getProxyHeaders(req),
        };

        const esRequest = http.request({
          protocol,
          host: hostname,
          port,
          path: `${pathname}${search}`,
          method,
          timeout,
          headers: requestHeaders,
        }, (esResponse) => {
          const {
            statusCode,
            statusMessage,
            headers: { warning },
          } = esResponse;

          const data = [];

          esResponse.setEncoding('utf8');

          esResponse.on('data', (chunk) => {
            data.push(chunk);
          });

          esResponse.on('end', () => {
            const responseBody = data.join();
            let result;

            if (method.toUpperCase() !== 'HEAD') {
              result = h
                .response(responseBody)
                .code(statusCode)
                .header('warning', warning);
            } else {
              result = h
                .response(`${statusCode} - ${statusMessage}`)
                .code(statusCode)
                .type('text/plain')
                .header('warning', warning);
            }

            resolve(result);
          });
        });

        esRequest.on('error', (e) => {
          reject(e);
        });

        // Write data to request body
        if (payload) {
          esRequest.write(JSON.stringify(payload));
        }

        esRequest.end();
      });
    },

@cjcenizal cjcenizal added Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.3.0 labels Jun 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui

@elasticmachine
Copy link
Contributor

💔 Build Failed

@cjcenizal cjcenizal requested a review from bmcconaghy June 18, 2019 20:03
@cjcenizal cjcenizal force-pushed the console/fix-get-request-body branch 3 times, most recently from 8a69b29 to 849818e Compare June 18, 2019 20:27
@elasticmachine
Copy link
Contributor

💔 Build Failed

@cjcenizal cjcenizal added v7.4.0 and removed v7.3.0 labels Jul 3, 2019
@cjcenizal cjcenizal force-pushed the console/fix-get-request-body branch from 849818e to 9cb1661 Compare July 14, 2019 20:22
@cjcenizal cjcenizal force-pushed the console/fix-get-request-body branch from c4bb28a to ca52e53 Compare July 14, 2019 20:37
@elasticmachine
Copy link
Contributor

💔 Build Failed

@cjcenizal
Copy link
Contributor Author

Closing in favor of #46200

@cjcenizal cjcenizal closed this Sep 20, 2019
@cjcenizal cjcenizal deleted the console/fix-get-request-body branch April 19, 2021 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants