{"action":"created","issue":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4524","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4524/labels{/name}","comments_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4524/comments","events_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4524/events","html_url":"https://github.com/orientechnologies/orientdb/issues/4524","id":93578812,"number":4524,"title":"HTTP response with status 100 and JSON error has bad \"Content-Length\" (tested with OrientDB v.2.1-rc5)","user":{"login":"d1g1t4l","id":250577,"avatar_url":"https://avatars.githubusercontent.com/u/250577?v=3","gravatar_id":"","url":"https://api.github.com/users/d1g1t4l","html_url":"https://github.com/d1g1t4l","followers_url":"https://api.github.com/users/d1g1t4l/followers","following_url":"https://api.github.com/users/d1g1t4l/following{/other_user}","gists_url":"https://api.github.com/users/d1g1t4l/gists{/gist_id}","starred_url":"https://api.github.com/users/d1g1t4l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d1g1t4l/subscriptions","organizations_url":"https://api.github.com/users/d1g1t4l/orgs","repos_url":"https://api.github.com/users/d1g1t4l/repos","events_url":"https://api.github.com/users/d1g1t4l/events{/privacy}","received_events_url":"https://api.github.com/users/d1g1t4l/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-07T16:59:18Z","updated_at":"2015-07-07T17:24:14Z","closed_at":null,"body":"The last message in the following dump contains a JSON object but the \"Content-Length\" header is set to 0. This breaks HTTP clients such as libcurl4 (default version on Ubuntu 14.04).\r\n\r\n```\r\n$ sudo ngrep -W byline -d lo port 2480\r\ninterface: lo (127.0.0.0/255.0.0.0)\r\nfilter: (ip or ip6) and ( port 2480 )\r\n####\r\nT 127.0.0.1:38188 -> 127.0.0.1:2480 [AP]\r\nGET /connect/test HTTP/1.1.\r\nAuthorization: Basic ...\r\nHost: localhost:2480.\r\nAccept: */*.\r\nAccept-Encoding: gzip,deflate.\r\nContent-Type: text/plain.\r\nContent-Length: 0.\r\n.\r\n\r\n##\r\nT 127.0.0.1:2480 -> 127.0.0.1:38188 [AP]\r\nHTTP/1.1 204 OK.\r\nCache-Control: no-cache, no-store, max-age=0, must-revalidate.\r\nPragma: no-cache.\r\nDate: Tue Jul 07 09:48:32 PDT 2015.\r\nContent-Type: text/plain; charset=utf-8.\r\nServer: OrientDB Server v.2.1-rc5 (build 14).\r\nConnection: Keep-Alive.\r\nSet-Cookie: OSESSIONID=OS1436287712434-1318519948869441833; Path=/; HttpOnly.\r\nContent-Length: 0.\r\n.\r\n\r\n##\r\nT 127.0.0.1:38188 -> 127.0.0.1:2480 [AP]\r\nPOST /command/test/sql HTTP/1.1.\r\nAuthorization: Basic ...\r\nHost: localhost:2480.\r\nAccept: */*.\r\nAccept-Encoding: gzip,deflate.\r\nContent-Type: text/plain.\r\nContent-Length: 22.\r\nExpect: 100-continue.\r\n.\r\n\r\n#\r\nT 127.0.0.1:2480 -> 127.0.0.1:38188 [AP]\r\nHTTP/1.1 100 null.\r\nCache-Control: no-cache, no-store, max-age=0, must-revalidate.\r\nPragma: no-cache.\r\nDate: Tue Jul 07 09:48:32 PDT 2015.\r\nContent-Type: application/json; charset=utf-8.\r\nServer: OrientDB Server v.2.1-rc5 (build 14).\r\nConnection: Keep-Alive.\r\nContent-Length: 0.\r\n.\r\n{.\r\n  \"errors\": [{.\r\n      \"code\": 100,.\r\n      \"reason\": 100,.\r\n      \"content\": null.\r\n      }.\r\n  ].\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/comments/119274934","html_url":"https://github.com/orientechnologies/orientdb/issues/4524#issuecomment-119274934","issue_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4524","id":119274934,"user":{"login":"d1g1t4l","id":250577,"avatar_url":"https://avatars.githubusercontent.com/u/250577?v=3","gravatar_id":"","url":"https://api.github.com/users/d1g1t4l","html_url":"https://github.com/d1g1t4l","followers_url":"https://api.github.com/users/d1g1t4l/followers","following_url":"https://api.github.com/users/d1g1t4l/following{/other_user}","gists_url":"https://api.github.com/users/d1g1t4l/gists{/gist_id}","starred_url":"https://api.github.com/users/d1g1t4l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d1g1t4l/subscriptions","organizations_url":"https://api.github.com/users/d1g1t4l/orgs","repos_url":"https://api.github.com/users/d1g1t4l/repos","events_url":"https://api.github.com/users/d1g1t4l/events{/privacy}","received_events_url":"https://api.github.com/users/d1g1t4l/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T17:24:14Z","updated_at":"2015-07-07T17:24:14Z","body":"I tracked the bug to `sendJsonContent` in `server/network/protocol/http/ONetworkProtocolHttpAbstract.java`:\r\n\r\n```\r\n  protected void sendJsonContent(final int iCode, final String iReason, String iHeaders, final String iContentType,\r\n      final String iContent, final boolean iKeepAlive) throws IOException {\r\n\r\n    final boolean empty = iContent == null || iContent.length() == 0; <-- iContent == null => empty = true\r\n\r\n    sendStatus(empty && iCode == 200 ? 204 : iCode, iReason);\r\n    sendResponseHeaders(iContentType, iKeepAlive);\r\n\r\n    if (iHeaders != null)\r\n      writeLine(iHeaders);\r\n\r\n    ODocument response = new ODocument();\r\n    ODocument error = new ODocument();\r\n\r\n    error.field(\"code\", iCode);\r\n    error.field(\"reason\", iCode);\r\n    error.field(\"content\", iContent);\r\n\r\n    List<ODocument> errors = new ArrayList<ODocument>();\r\n    errors.add(error);\r\n\r\n    response.field(\"errors\", errors);\r\n\r\n    final byte[] binaryContent = response.toJSON(\"prettyPrint\").getBytes(utf8);\r\n    writeLine(OHttpUtils.HEADER_CONTENT_LENGTH + (empty ? 0 : binaryContent.length)); <-- empty == true => ContentLength = 0\r\n```"}}