Repository navigation
feat: add https connection option to allow plain HTTP transport
#588
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7089cde
feat: add `https` connection option to allow plain HTTP transport
vuanhphung b51037b
fix: avoid doubling the kernel port when host already has one
vuanhphung 587552d
fix: do not read a bare IPv6 host as carrying a port
vuanhphung 3a38fda
fix: strip a trailing slash from the kernel http:// host
vuanhphung e62cc20
engineer-bot: address @mention on PR #588
peco-engineer-bot[bot] 47c527a
fix: satisfy lint in CloudFetch agent selection
vuanhphung e3a6fd6
engineer-bot: address @mention on PR #588
peco-engineer-bot[bot] 192a662
test: adapt retry fixture to protocol-specific agents
vuanhphung 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,81 @@ | ||
| import { expect } from 'chai'; | ||
| import http from 'http'; | ||
| import { AddressInfo, Socket } from 'net'; | ||
| import httpProxy from 'http-proxy'; | ||
| import { DBSQLClient } from '../../lib'; | ||
| import { ConnectionOptions } from '../../lib/contracts/IDBSQLClient'; | ||
| import { InternalConnectionOptions } from '../../lib/contracts/InternalConnectionOptions'; | ||
|
|
||
| import config from './utils/config'; | ||
|
|
||
| // Application --HTTP--> local reverse proxy --HTTPS--> Databricks | ||
| describe('Plain HTTP transport through a local reverse proxy', () => { | ||
| const requests: Array<{ method?: string; url?: string }> = []; | ||
| const sockets = new Set<Socket>(); | ||
| let server: http.Server; | ||
| let port: number; | ||
|
|
||
| before(async () => { | ||
| const proxy = httpProxy.createProxyServer({ target: `https://${config.host}`, changeOrigin: true, secure: true }); | ||
| server = http.createServer((req, res) => { | ||
| requests.push({ method: req.method, url: req.url }); | ||
| proxy.web(req, res, {}, (error) => { | ||
| res.writeHead(502); | ||
| res.end(String(error)); | ||
| }); | ||
| }); | ||
| server.on('connection', (socket: Socket) => { | ||
| sockets.add(socket); | ||
| socket.on('close', () => sockets.delete(socket)); | ||
| }); | ||
| await new Promise<void>((resolve) => { | ||
| server.listen(0, '127.0.0.1', resolve); | ||
| }); | ||
| port = (server.address() as AddressInfo).port; | ||
| }); | ||
|
|
||
| after(async () => { | ||
| const closed = new Promise<void>((resolve) => { | ||
| server.close(() => resolve()); | ||
| }); | ||
| sockets.forEach((socket) => socket.destroy()); | ||
| await closed; | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| requests.length = 0; | ||
| }); | ||
|
|
||
| [false, true].forEach((useKernel) => { | ||
| it(`runs a query with https: false (${useKernel ? 'kernel' : 'thrift'} backend)`, async () => { | ||
| const client = new DBSQLClient(); | ||
| await client.connect({ | ||
| host: '127.0.0.1', | ||
| port, | ||
| path: config.path, | ||
| token: config.token, | ||
| https: false, | ||
| useKernel, | ||
| } as ConnectionOptions & InternalConnectionOptions); | ||
|
|
||
| const session = await client.openSession({ initialCatalog: config.catalog, initialSchema: config.schema }); | ||
| const operation = await session.executeStatement('SELECT 1 AS one'); | ||
| const rows = (await operation.fetchAll()) as Array<Record<string, unknown>>; | ||
| await operation.close(); | ||
| await session.close(); | ||
| await client.close(); | ||
|
|
||
| expect(rows).to.have.length(1); | ||
| expect(Number(rows[0].one)).to.equal(1); | ||
| // The SQL traffic went through the plain-HTTP proxy: Thrift to the | ||
| // warehouse path, the kernel to the SQL Statement Execution API. | ||
| if (useKernel) { | ||
| expect(requests.some((request) => request.url?.startsWith('/api/2.0/sql/'))).to.be.true; | ||
| } else { | ||
| expect(requests.length).to.be.gte(1); | ||
| const path = config.path.startsWith('/') ? config.path : `/${config.path}`; | ||
| expect(requests.every((request) => request.url === path)).to.be.true; | ||
| } | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.