respond writes the specified response to the client (or does nothing if d.Res is empty)
(ctx context.Context, d *DNSContext)
| 138 | |
| 139 | // respond writes the specified response to the client (or does nothing if d.Res is empty) |
| 140 | func (p *Proxy) respond(ctx context.Context, d *DNSContext) { |
| 141 | // d.Conn can be nil in the case of a DoH request. |
| 142 | if d.Conn != nil { |
| 143 | _ = d.Conn.SetWriteDeadline(p.time.Now().Add(defaultTimeout)) |
| 144 | } |
| 145 | |
| 146 | var err error |
| 147 | |
| 148 | switch d.Proto { |
| 149 | case ProtoUDP: |
| 150 | err = p.respondUDP(d) |
| 151 | case ProtoTCP: |
| 152 | err = p.respondTCP(d) |
| 153 | case ProtoTLS: |
| 154 | err = p.respondTCP(d) |
| 155 | case ProtoHTTPS: |
| 156 | err = p.respondHTTPS(d) |
| 157 | case ProtoQUIC: |
| 158 | err = p.respondQUIC(d) |
| 159 | case ProtoDNSCrypt: |
| 160 | err = p.respondDNSCrypt(ctx, d) |
| 161 | default: |
| 162 | err = fmt.Errorf("SHOULD NOT HAPPEN - unknown protocol: %s", d.Proto) |
| 163 | } |
| 164 | |
| 165 | if err != nil { |
| 166 | logWithNonCrit(ctx, err, "responding request", d.Proto, p.logger) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // setMinMaxTTL sets the TTL values of all records according to the proxy |
| 171 | // settings. r must not be nil. |
no test coverage detected