{"record":{"id":"4de05d4b50e008b8","repo":"TooTallNate/Java-WebSocket","slug":"not-an-http-header","errorCode":null,"errorMessage":"not an http header","messagePattern":"not an http header","errorType":"exception","errorClass":"InvalidHandshakeException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft.java","lineNumber":117,"sourceCode":"    String line = readStringLine(buf);\n    if (line == null) {\n      throw new IncompleteHandshakeException(buf.capacity() + 128);\n    }\n\n    String[] firstLineTokens = line.split(\" \", 3);// eg. HTTP/1.1 101 Switching the Protocols\n    if (firstLineTokens.length != 3) {\n      throw new InvalidHandshakeException();\n    }\n    if (role == Role.CLIENT) {\n      handshake = translateHandshakeHttpClient(firstLineTokens, line);\n    } else {\n      handshake = translateHandshakeHttpServer(firstLineTokens, line);\n    }\n    line = readStringLine(buf);\n    while (line != null && line.length() > 0) {\n      String[] pair = line.split(\":\", 2);\n      if (pair.length != 2) {\n        throw new InvalidHandshakeException(\"not an http header\");\n      }\n      // If the handshake contains already a specific key, append the new value\n      if (handshake.hasFieldValue(pair[0])) {\n        handshake.put(pair[0],\n            handshake.getFieldValue(pair[0]) + \"; \" + pair[1].replaceFirst(\"^ +\", \"\"));\n      } else {\n        handshake.put(pair[0], pair[1].replaceFirst(\"^ +\", \"\"));\n      }\n      line = readStringLine(buf);\n    }\n    if (line == null) {\n      throw new IncompleteHandshakeException();\n    }\n    return handshake;\n  }\n\n  /**\n   * Checking the handshake for the role as server","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft.java#L99-L135","documentation":"This is a format validation inside Draft.translateHandshakeHttp while parsing the HTTP handshake headers. Each header line must be a 'Name: value' pair; a line that does not split into exactly two parts on ':' is not a valid HTTP header, and the library aborts the whole handshake with InvalidHandshakeException rather than guessing. The faulty input is a malformed header line (missing colon, empty name, or corrupt line) in the WebSocket opening-handshake data received from the remote peer.","triggerScenarios":"Thrown at src/main/java/org/java_websocket/drafts/Draft.java:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the raw handshake bytes/lines sent by the peer and fix any header missing a colon separator","Ensure the peer is a compliant WebSocket/HTTP endpoint producing well-formed 'Header: value' lines","Check for proxies or intermediaries mangling or injecting non-header lines into the handshake response","On the server side, validate client handshake headers before sending; on the client side, verify the server URL points to a real WebSocket endpoint"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d","analyzedAt":"2026-09-09T14:39:47.546Z","contentChangedAt":"2026-09-09T14:39:47.546Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}