{"action":"created","issue":{"url":"https://api.github.com/repos/valyala/fasthttp/issues/37","labels_url":"https://api.github.com/repos/valyala/fasthttp/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/valyala/fasthttp/issues/37/comments","events_url":"https://api.github.com/repos/valyala/fasthttp/issues/37/events","html_url":"https://github.com/valyala/fasthttp/issues/37","id":126219595,"number":37,"title":"Connection Close","user":{"login":"sschepens","id":3072509,"avatar_url":"https://avatars.githubusercontent.com/u/3072509?v=3","gravatar_id":"","url":"https://api.github.com/users/sschepens","html_url":"https://github.com/sschepens","followers_url":"https://api.github.com/users/sschepens/followers","following_url":"https://api.github.com/users/sschepens/following{/other_user}","gists_url":"https://api.github.com/users/sschepens/gists{/gist_id}","starred_url":"https://api.github.com/users/sschepens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschepens/subscriptions","organizations_url":"https://api.github.com/users/sschepens/orgs","repos_url":"https://api.github.com/users/sschepens/repos","events_url":"https://api.github.com/users/sschepens/events{/privacy}","received_events_url":"https://api.github.com/users/sschepens/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-12T16:38:19Z","updated_at":"2016-01-12T17:26:17Z","closed_at":null,"body":"I have an issue where a webserver is returning a 204 response with Connection: keep-alive, but fasthttp sets Connection: close and closes the connection, this does not happen with curl or net/http.\r\n\r\nThis is the response according to fasthttp:\r\n```\r\nResponse: 204 - HTTP/1.1 204 No Content\r\nServer: fasthttp\r\nDate: Tue, 12 Jan 2016 16:34:26 GMT\r\nContent-Type: text/plain; charset=utf-8\r\nX-Powered-By: Express\r\nEtag: W/\"2-2745614147\"\r\nDate: Tue, 12 Jan 2016 16:34:30 GMT\r\nConnection: keep-alive\r\nTransfer-Encoding: identity\r\nConnection: close\r\n```\r\n\r\nThis is the response according to net/http:\r\n```go\r\n&{Status:204 No Content StatusCode:204 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[X-Powered-By:[Express] Etag:[W/\"2-2745614147\"] Date:[Tue, 12 Jan 2016 16:34:30 GMT] Connection:[keep-alive]] Body:0xc8200de580 ContentLength:0 TransferEncoding:[] Close:false Trailer:map[] Request:0xc820112000 TLS:<nil>}\r\n```\r\n\r\nAnd this is according to curl:\r\n```\r\n< HTTP/1.1 204 No Content\r\n< X-Powered-By: Express\r\n< ETag: W/\"2-2745614147\"\r\n< Date: Tue, 12 Jan 2016 16:35:39 GMT\r\n< Connection: keep-alive\r\n< \r\n* Connection #0 to host xxx left intact\r\n```\r\n\r\nThis is the code i'm using:\r\n```go\r\n\treq := fasthttp.AcquireRequest()\r\n\tres := fasthttp.AcquireResponse()\r\n\tdefer fasthttp.ReleaseRequest(req)\r\n\tdefer fasthttp.ReleaseResponse(res)\r\n\treq.SetRequestURI(\"URL\")\r\n\treq.Header.SetMethod(\"GET\")\r\n\treq.Header.Set(\"Accept\", \"application/json\")\r\n\terr := fasthttp.DoTimeout(req, res, 1*time.Second)\r\n```\r\n\r\nAm I doing something wrong or is it a bad behavior of fasthttp?"},"comment":{"url":"https://api.github.com/repos/valyala/fasthttp/issues/comments/170982343","html_url":"https://github.com/valyala/fasthttp/issues/37#issuecomment-170982343","issue_url":"https://api.github.com/repos/valyala/fasthttp/issues/37","id":170982343,"user":{"login":"sschepens","id":3072509,"avatar_url":"https://avatars.githubusercontent.com/u/3072509?v=3","gravatar_id":"","url":"https://api.github.com/users/sschepens","html_url":"https://github.com/sschepens","followers_url":"https://api.github.com/users/sschepens/followers","following_url":"https://api.github.com/users/sschepens/following{/other_user}","gists_url":"https://api.github.com/users/sschepens/gists{/gist_id}","starred_url":"https://api.github.com/users/sschepens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschepens/subscriptions","organizations_url":"https://api.github.com/users/sschepens/orgs","repos_url":"https://api.github.com/users/sschepens/repos","events_url":"https://api.github.com/users/sschepens/events{/privacy}","received_events_url":"https://api.github.com/users/sschepens/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T17:26:17Z","updated_at":"2016-01-12T17:26:17Z","body":"Apparently it has to do with with fasthttp detecting Transfer-Encoding as Identity when no Content-Length is set and forcing connection close:\r\n[http.go line 680](https://github.com/valyala/fasthttp/blob/master/http.go#L680)\r\n```go\r\n\tif !resp.mustSkipBody() {\r\n\t\tresp.body, err = readBody(r, resp.Header.ContentLength(), maxBodySize, resp.body)\r\n\t\tif err != nil {\r\n\t\t\tresp.Reset()\r\n\t\t\treturn err\r\n\t\t}\r\n\t\tresp.Header.SetContentLength(len(resp.body))\r\n\t}\r\n```\r\n\r\n[header.go line 200](https://github.com/valyala/fasthttp/blob/master/header.go#L200)\r\n```go\r\nfunc (h *ResponseHeader) SetContentLength(contentLength int) {\r\n\tif h.mustSkipContentLength() {\r\n\t\treturn\r\n\t}\r\n\th.contentLength = contentLength\r\n\tif contentLength >= 0 {\r\n\t\th.contentLengthBytes = AppendUint(h.contentLengthBytes[:0], contentLength)\r\n\t\th.h = delArg(h.h, strTransferEncoding)\r\n\t} else {\r\n\t\th.contentLengthBytes = h.contentLengthBytes[:0]\r\n\t\tvalue := strChunked\r\n\t\tif contentLength == -2 {\r\n\t\t\th.SetConnectionClose()\r\n\t\t\tvalue = strIdentity\r\n\t\t}\r\n\t\th.h = setArg(h.h, strTransferEncoding, value)\r\n\t}\r\n}\r\n```\r\n"}}