respondHTTPS writes a response to the DoH client. d must not be nil.
(d *DNSContext)
| 288 | |
| 289 | // respondHTTPS writes a response to the DoH client. d must not be nil. |
| 290 | func (p *Proxy) respondHTTPS(d *DNSContext) (err error) { |
| 291 | resp := d.Res |
| 292 | w := d.HTTPResponseWriter |
| 293 | |
| 294 | if resp == nil { |
| 295 | // Indicate the response's absence via a http.StatusInternalServerError. |
| 296 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| 297 | |
| 298 | return nil |
| 299 | } |
| 300 | |
| 301 | bytes, err := resp.Pack() |
| 302 | if err != nil { |
| 303 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| 304 | |
| 305 | return fmt.Errorf("packing message: %w", err) |
| 306 | } |
| 307 | |
| 308 | if srvHeader := p.HTTPConfig.ServerHeader; srvHeader != "" { |
| 309 | w.Header().Set(httphdr.Server, srvHeader) |
| 310 | } |
| 311 | |
| 312 | w.Header().Set(httphdr.ContentType, "application/dns-message") |
| 313 | _, err = w.Write(bytes) |
| 314 | |
| 315 | return err |
| 316 | } |
| 317 | |
| 318 | // realIPFromHdrs extracts the actual client's IP address from the first |
| 319 | // suitable r's header. It returns an error if r doesn't contain any |