Custom Http Status Code Failing in Http Client

Hi ,
We are rewriting an old integration with a service from python to golang. This service uses Custom status codes. For example the status code is 8000. But while I am trying to get the response it is giving me error as “malformed HTTP status code”. Can some one help me to resolve this issue. Gone through the code and found the following piece of code that throws the error if the status code is not having length of 3.

       if len(statusCode) != 3 {
 		return nil, &badStringError{"malformed HTTP status code", statusCode}

HTTP status codes are three digits as per the HTTP spec. Your service speaks something similar to but different from HTTP. I think your best bet is correcting the service to speak HTTP, or fork the Go HTTP library into your own not-quite-HTTP library.

1 Like

Just as background, status codes were designed so that only the first byte is needed to drive a DFA, and that subsequent bytes added information useful to a human. The best description is probably Jon Postel’s,

SMTP, FTP and HTTP alls have distinct code sets, but use the same grammar. You might consider writing a new instance rather than a new protocol (;-))

Thanks. The service I am re-integrating a legacy code of a Banking system. So I cannot / dont have the access to change the service’s implementation. So I am left with the way of changing the net/http package only(which I wanted to avoid)

Given that you’re stuck resorting to hacks there are things you can do which doesn’t require forking the http package. For example, you can implement a hacking status code converting connection type.

type httpConnFixer struct {

func (c * httpConnFixer) Read(buf []byte) (int, error) {
    // implement the reader so that it looks at the first line
    // and modifies the status code to be compliant

and then use a http.Client with a Dial function that does the regular dial and then wraps the connection in your fixer.

func someDial(network, addr string) (net.Conn, error) {
    // dial
    return &httpConnFixer{conn}, err

cli := &http.Client{
    Transport: &http.Transport{
        Dial: someDialFunc,

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.