Skip to content

net/http: add logging before returning error 400 HTTP request to HTTPS server #66501

Closed
@1f604

Description

@1f604

Proposal Details

Proposal

This proposal is specifically talking about this line of code here:

io.WriteString(re.Conn, "HTTP/1.0 400 Bad Request\r\n\r\nClient sent an HTTP request to an HTTPS server.\n")

My proposal is to add a line writing some error message to logs before returning the 400 error.

Motivation

Spent almost an hour today tracking down a bug which turned out to be due to Cloudflare proxy sending plain HTTP traffic (decrypted from TLS traffic) to my Go server which serves TLS.

It turns out that ListenAndServeTLS doesn't log any error messages when it receives a HTTP request, instead it just sends error: "Client sent an HTTP request to an HTTPS server." back to the client.

The problem is that my web browsers (tried both Firefox and Chrome, same result) don't display the message at all, it just shows an error 400 and that's it.

And in my Go program, there is no indication that it received any packets - no logging and there is no ability for me to add any logging to it at all.

I think the ideal solution would be to allow users to specify whether they want logging here, since some users might want it and some users might not.

But the simplest fix is to just add the logging for now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions