forked from JCMais/node-libcurl
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: localhost resolution RFC6761 (#70)
* spike: investigate localhost resolution RFC6761 * bump curl to 7.85.0 * fix * pull latest curl-for-windows & bump to 7.86.0
- Loading branch information
Showing
4 changed files
with
81 additions
and
6 deletions.
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
Submodule curl-for-windows
updated
3075 files
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,75 @@ | ||
import 'should' | ||
import { app, host, port, server } from '../helper/server' | ||
import { Curl } from '../../lib' | ||
|
||
let curl: Curl | ||
const urlLocalhost = `http://localhost:${port}/` | ||
const urlTestLocalhost = `http://test.localhost:${port}/` | ||
|
||
describe('DNS Resolution', () => { | ||
before((done) => { | ||
server.listen(port, host, () => done()) | ||
|
||
app.get('/', (req, res) => { | ||
res.send({ message: 'resolved', ip: req.ip }) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
server.close() | ||
app._router.stack.pop() | ||
done() | ||
}) | ||
|
||
beforeEach(() => { | ||
curl = new Curl() | ||
}) | ||
|
||
afterEach(() => { | ||
curl.close() | ||
}) | ||
|
||
it('should resolve localhost to 127.0.0.1', (done) => { | ||
curl.setOpt('URL', urlLocalhost) | ||
|
||
curl.on('end', (status, data) => { | ||
if (status !== 200) { | ||
throw Error(`Invalid status code: ${status}`) | ||
} | ||
|
||
const result = JSON.parse(data as string) | ||
result.message.should.be.equal('resolved') | ||
result.ip.should.be.equal('::1') | ||
|
||
done() | ||
}) | ||
|
||
curl.on('error', done) | ||
curl.perform() | ||
}) | ||
|
||
it('should resolve test.localhost to 127.0.0.1', (done) => { | ||
// skip this test if windows because it does not support *.localhost on hosts file? | ||
// https://stackoverflow.com/questions/138162/wildcards-in-a-windows-hosts-file/4166967#4166967 | ||
// if (process.platform === 'win32') { | ||
// done() | ||
// return | ||
// } | ||
curl.setOpt('URL', urlTestLocalhost) | ||
|
||
curl.on('end', (status, data) => { | ||
if (status !== 200) { | ||
throw Error(`Invalid status code: ${status}`) | ||
} | ||
|
||
const result = JSON.parse(data as string) | ||
result.message.should.be.equal('resolved') | ||
result.ip.should.be.equal('::1') | ||
|
||
done() | ||
}) | ||
|
||
curl.on('error', done) | ||
curl.perform() | ||
}) | ||
}) |