Skip to content

WIP: DNS-over-HTTP support for Client#649

Closed
tmthrgd wants to merge 3 commits intomiekg:masterfrom
tmthrgd:doh
Closed

WIP: DNS-over-HTTP support for Client#649
tmthrgd wants to merge 3 commits intomiekg:masterfrom
tmthrgd:doh

Conversation

@tmthrgd
Copy link
Copy Markdown
Collaborator

@tmthrgd tmthrgd commented Mar 19, 2018

This is a quick attempt at adding DNS-over-HTTP support to Client, inspired by #647 (comment).

This method uses http.Client and stubs the behaviour of the net.Conn present in Conn, it should be otherwise fully functional. It's entirely possible to build this same system from a raw *tls.Conn using the x/net/http2 package, but it's not clear to me how much benefit this would have.

Note: When using DNS-over-HTTPS, errors won't be surfaced from Dial, instead they'll show up in Write.

@tmthrgd tmthrgd requested a review from miekg March 19, 2018 10:38
Comment thread client.go

d := t.client.dialTimeout() + t.client.writeTimeout() + t.client.readTimeout()

ctx, cancel := context.WithTimeout(context.Background(), d)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not convinced this timeout code is remotely correct and I'd rather rip it out, although I'm not sure if there's any other place it can be inserted.

Comment thread client.go

req = req.WithContext(ctx)

resp, err := http.DefaultClient.Do(req)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It would be useful to allow the http.Client to be specified, perhaps by adding a field to Conn.

I'm pretty sure this is a false positive, but then again I've left
(*dohConn).Close a stub.
Comment thread leak_test.go
strings.Contains(stack, "closeWriteAndWait") ||
strings.Contains(stack, "testing.Main(") ||
strings.Contains(stack, "testing.(*T).Run(") ||
strings.Contains(stack, "created by net/http.(*http2Transport).newClientConn") ||
Copy link
Copy Markdown
Collaborator Author

@tmthrgd tmthrgd Mar 19, 2018

Choose a reason for hiding this comment

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

I'm pretty sure this is a false positive, but then again I've left (*dohConn).Close a stub.

@tmthrgd
Copy link
Copy Markdown
Collaborator Author

tmthrgd commented Mar 19, 2018

It would also be possible to simply push this upwards a layer and only support DNS-over-HTTPS in the various Exchange methods.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 19, 2018

Codecov Report

Merging #649 into master will increase coverage by 0.03%.
The diff coverage is 46.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #649      +/-   ##
==========================================
+ Coverage   57.91%   57.94%   +0.03%     
==========================================
  Files          37       37              
  Lines        9991    10045      +54     
==========================================
+ Hits         5786     5821      +35     
- Misses       3155     3172      +17     
- Partials     1050     1052       +2
Impacted Files Coverage Δ
client.go 58.17% <46.29%> (-1.68%) ⬇️
msg.go 78.6% <0%> (+1.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b169d1...67ba6d6. Read the comment docs.

@miekg
Copy link
Copy Markdown
Owner

miekg commented Mar 19, 2018 via email

@tmthrgd
Copy link
Copy Markdown
Collaborator Author

tmthrgd commented Mar 19, 2018

"I have some misgivings on supporting a transport in only some methods."

That's definitely understandable, although it would be the cleanest place to support this. I'd suggest any v2 rewrite (as you mentioned later) should probably only support Exchange style methods and drop the lower-level Read and Write methods.

"A quite like the hackiness of the approach you take :) But doing the actual Dial inside the WriteMsg method is icky."

It works 🤷‍♂️. I can try a different implementation that came to mind, that would move the Dial into Dial. I don't think it would be cleaner than this implementation though.

"Not sure if this will fit this library ever."

I think DOH support would be worthwhile, but it obviously depends on how cleanly it can be integrated—baring a rewrite.

@miekg
Copy link
Copy Markdown
Owner

miekg commented Mar 19, 2018 via email

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.

3 participants