-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[spacetime] Http/2 support #123748
Closed
Closed
[spacetime] Http/2 support #123748
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7fe6ca9
install http js client with http/2 support
dfd35dc
add basic support for http/2 in Core Http service
3038db4
hack bfetch to be compatible with http2
834fffa
pick must work with an object without prototype
d2f6cb0
use got client with http/2 support to send request to Kibana in FTR
5dcda95
I did not fix the base path proxy yet
05dce08
prepare a few tests to be run in http/2 mode
faa3b40
use hacked hapi version
4ef6274
do not run test/functional with secure connection
2e4fb3d
use http2 for the performance tests
bb9f570
fix tests
03b7e52
ignore node warning on unsupported headers in http2
5a1b2cf
Revert "use hacked hapi version"
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
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
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 |
---|---|---|
|
@@ -8,9 +8,8 @@ | |
|
||
import Url from 'url'; | ||
import Https from 'https'; | ||
import Qs from 'querystring'; | ||
|
||
import Axios, { AxiosResponse, ResponseType } from 'axios'; | ||
import got, { Agents } from 'got'; | ||
import { ToolingLog, isAxiosRequestError, isAxiosResponseError } from '@kbn/dev-utils'; | ||
|
||
const isConcliftOnGetError = (error: any) => { | ||
|
@@ -67,11 +66,11 @@ export interface ReqOptions { | |
path: string; | ||
query?: Record<string, any>; | ||
method: 'GET' | 'POST' | 'PUT' | 'DELETE'; | ||
body?: any; | ||
body?: Record<string, any> | string; | ||
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. TODO: check whether we use |
||
retries?: number; | ||
headers?: Record<string, string>; | ||
ignoreErrors?: number[]; | ||
responseType?: ResponseType; | ||
responseType?: 'text' | 'json' | 'buffer'; | ||
} | ||
|
||
const delay = (ms: number) => | ||
|
@@ -86,16 +85,18 @@ interface Options { | |
|
||
export class KbnClientRequester { | ||
private readonly url: string; | ||
private readonly httpsAgent: Https.Agent | null; | ||
private readonly httpsAgent: Https.Agent | undefined; | ||
private ca?: Buffer[]; | ||
|
||
constructor(private readonly log: ToolingLog, options: Options) { | ||
this.url = options.url; | ||
this.ca = options.certificateAuthorities; | ||
this.httpsAgent = | ||
Url.parse(options.url).protocol === 'https:' | ||
? new Https.Agent({ | ||
ca: options.certificateAuthorities, | ||
}) | ||
: null; | ||
: undefined; | ||
} | ||
|
||
private pickUrl() { | ||
|
@@ -111,35 +112,41 @@ export class KbnClientRequester { | |
return Url.resolve(baseUrl, relative); | ||
} | ||
|
||
async request<T>(options: ReqOptions): Promise<AxiosResponse<T>> { | ||
async request<T>(options: ReqOptions): Promise<{ data: T; status: number; statusText?: string }> { | ||
const url = this.resolveUrl(options.path); | ||
const description = options.description || `${options.method} ${url}`; | ||
let attempt = 0; | ||
const maxAttempts = options.retries ?? DEFAULT_MAX_ATTEMPTS; | ||
|
||
const agents: Agents = { | ||
https: this.httpsAgent, | ||
}; | ||
while (true) { | ||
attempt += 1; | ||
|
||
try { | ||
const response = await Axios.request({ | ||
const response = await got({ | ||
// TODO make configurable | ||
http2: true, | ||
https: { | ||
certificateAuthority: this.ca, | ||
}, | ||
method: options.method, | ||
url, | ||
data: options.body, | ||
params: options.query, | ||
searchParams: options.query, | ||
headers: { | ||
...options.headers, | ||
'kbn-xsrf': 'kbn-client', | ||
}, | ||
httpsAgent: this.httpsAgent, | ||
body: typeof options.body === 'object' ? JSON.stringify(options.body) : options.body, | ||
agent: agents, | ||
responseType: options.responseType, | ||
// work around https://github.com/axios/axios/issues/2791 | ||
transformResponse: options.responseType === 'text' ? [(x) => x] : undefined, | ||
maxContentLength: 30000000, | ||
maxBodyLength: 30000000, | ||
paramsSerializer: (params) => Qs.stringify(params), | ||
}); | ||
|
||
return response; | ||
return { | ||
data: response.body as T, | ||
status: response.statusCode, | ||
statusText: response.statusMessage, | ||
}; | ||
} catch (error) { | ||
const conflictOnGet = isConcliftOnGetError(error); | ||
const requestedRetries = options.retries !== undefined; | ||
|
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
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.
in the case of http/2,
headers
object is created viaObject.create(null)
so it hasn't gothasOwnProperty
method