Skip to content

Commit

Permalink
fix: localhost resolution RFC6761 (#70)
Browse files Browse the repository at this point in the history
* 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
filfreire authored Nov 22, 2024
1 parent 4b316bc commit fb41cb2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- macos-13-xlarge
- ubuntu-22.04
libcurl-release:
- 7.79.1
- 7.86.0
node-libcurl-cpp-std:
- c++17
node:
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
- macos-13-xlarge
- ubuntu-22.04
libcurl-release:
- 7.79.1
- 7.86.0
node:
- 20.16.0
electron-version:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- macos-13-xlarge
- ubuntu-22.04
libcurl-release:
- 7.79.1
- 7.86.0
node-libcurl-cpp-std:
- c++17
node:
Expand All @@ -53,7 +53,7 @@ jobs:
- os: ubuntu-latest
node: 20.16.0
node-libcurl-cpp-std: c++17
libcurl-release: 7.79.1
libcurl-release: 7.86.0
run-lint-and-tsc: true

env:
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
- macos-13-xlarge
- ubuntu-22.04
libcurl-release:
- 7.79.1
- 7.86.0
node:
- 20.16.0
electron-version:
Expand Down
2 changes: 1 addition & 1 deletion deps/curl-for-windows
Submodule curl-for-windows updated 3075 files
75 changes: 75 additions & 0 deletions test/curl/localhost.spec.ts
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()
})
})

0 comments on commit fb41cb2

Please sign in to comment.