Skip to content

net/http: HTTPS requests when the server does not support it -> record overflow #11111

Closed
@eidge

Description

@eidge

Making an HTTPS request against a server that has no TLS enabled returns an 'record overflow' error.

I wonder if the message couldn't be a bit more helpful, like: 'No valid TLS certificate found. Aborting request.'

The sample program below illustrates the problem.

package main

import "net"
import "net/http"
import "net/http/httptest"
import "fmt"

func main() {
    server := httptest.NewUnstartedServer(
        http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            fmt.Fprintf(w, "it works")
        }))

    server.Listener, _ = net.Listen("tcp", ":8080")
    server.Start()
    defer server.Close()

    req, err := http.NewRequest("GET", "https://localhost:8080", nil)
    if err != nil {
        panic(err.Error())
    }
    _, err = http.DefaultClient.Do(req)
    if err != nil {
        panic(err.Error()) // Will throw 'record overflow' here, works fine if one requests http instead of https though.
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions