Skip to content
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

Add redirect support (limit: 6) #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add redirect support (limit: 6) #29

wants to merge 4 commits into from

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
@@ -39,6 +39,9 @@ datDns.resolveName('foo.com', {noDnsOverHttps: true})
// 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
@@ -69,6 +70,7 @@ function createDatDNS (datDnsOpts) {
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
3 participants