Skip to content

Conversation

@martinheidegger
Copy link
Contributor

Improved implementation of #27. I used the findings of #27 and restructured the changes a bit, fixing a few things:

  • Add option (and docs) to specify how many redirects are allowed.
  • Add mention in the log where the redirect is heading to
  • Fixing log statement to show consistently where the well-known file is actually loaded.
  • Moving the redirect code to own function for clearer code (to not explode the side of the main function)
  • Using lowerCamelCase variable names
  • Only prefix the path with .well-known for the first request (but not redirects)
  • Adds test for too many redirects.
  • Uses a domain dedicated to test the redirects.

Closes #25

Copy link
Contributor

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Added some minor feedback

README.md Outdated
// dont use .well-known/dat
datDns.resolveName('foo.com', {noWellknownDat: true})

// specify amount of redirects (default: 7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it 7 or 6? (Just looking at the constant in index.js)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 6, fixed in ed33316

index.js Outdated
var ignoreCachedMiss = opts && opts.ignoreCachedMiss
var noDnsOverHttps = opts && opts.noDnsOverHttps
var noWellknownDat = opts && opts.noWellknownDat
var followRedirects = (opts && opts.followRedirects) || DEFAULT_FOLLOW_REDIRECTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we modify this so that 0 is allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added support & test in 7a488de - thanks for noticing.

index.js Outdated
if ([301, 302, 307, 308].includes(res.statusCode)) {
if (!'location' in res.headers) {
debug('.well-known/' + recordName + ' lookup redirect did not contain destination Location header.')
throw new Error('Well record redirected to nowhere')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo in this error description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjust both this and the next error message in 7edfc1b

index.js Outdated
// resolve relative paths with original URL as base URL
const uri = new URL(res.headers['location'], 'https://' + host)
if (uri.protocol !== 'https:') {
throw new Error('DNS record redirected to non https: protocol: ' + uri.href)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it the DNS record or the HTTP response?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should follow same-origin redirects

4 participants