Skip to content

Commit

Permalink
Deal with non-RFC compliant servers (#375)
Browse files Browse the repository at this point in the history
There are hundreds of thousands of servers on the internet where the
"INTENT" is to be an HTTP service, but in reality they do not properly
conform to the HTTP RFC. In many cases, these servers will send back a
simple:

HTTP/1.1 404 Not Found

With no `Connection: close` header, and terminates the established
connection.

While it's understood these are not RFC compliant, I would still like to
see the servers that are intending to be HTTP servers.
  • Loading branch information
ycamper authored Feb 18, 2024
1 parent 413c2ce commit 7363919
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,11 @@ func (b *cancelTimerBody) Read(p []byte) (n int, err error) {
}

func (b *cancelTimerBody) Close() error {
err := b.rc.Close()
b.stop()
return err
defer b.stop()
if b.rc != nil {
return b.rc.Close()
}
return nil
}

func shouldCopyHeaderOnRedirect(headerKey string, initial, dest *url.URL) bool {
Expand Down
5 changes: 4 additions & 1 deletion lib/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ func (pc *persistConn) readLoop() {
closeErr = err
}

if err != nil {
if err != nil && (!pc.sawEOF || resp == nil) {
if pc.readLimit <= 0 {
err = fmt.Errorf("net/http: server response headers exceeded %d bytes; aborted", pc.maxHeaderResponseSize())
}
Expand Down Expand Up @@ -1657,6 +1657,9 @@ func (pc *persistConn) readResponse(rc requestAndChan, trace *httptrace.ClientTr
}
resp, err = ReadResponse(pc.br, rc.req)
if err != nil {
if err == io.ErrUnexpectedEOF {
pc.sawEOF = true
}
return
}
if rc.continueCh != nil {
Expand Down

0 comments on commit 7363919

Please sign in to comment.