{"record":{"id":"8f9bfb997e2d6776","repo":"urbanadventurer/WhatWeb","slug":"wrong-header-line-format","errorCode":null,"errorMessage":"wrong header line format","messagePattern":"wrong header line format","errorType":"exception","errorClass":"Net::HTTPBadResponse","httpStatus":null,"severity":"error","filePath":"lib/extend-http.rb","lineNumber":330,"sourceCode":"    [str] + m.captures\n  end\n\n  def each_response_header(sock)\n    key = value = nil\n    loop do\n      line = sock.readuntil(\"\\n\", true).sub(/\\s+\\z/, '')\n      # added for whatweb\n      @rawlines << line + \"\\n\" unless line.nil?\n      #\n      break if line.empty?\n\n      if line[0] == ' ' || line[0] == \"\\t\" && value\n        value << ' ' unless value.empty?\n        value << line.strip\n      else\n        yield key, value if key\n        key, value = line.strip.split(/\\s*:\\s*/, 2)\n        raise Net::HTTPBadResponse, 'wrong header line format' if value.nil?\n      end\n    end\n    yield key, value if key\n  end\n  end\n\n  ###################\n\n  public\n\n  #    include HTTPHeader\n\n  def initialize(httpv, code, msg) #:nodoc: internal use only\n    @http_version = httpv\n    @code         = code\n    @message      = msg\n    initialize_http_header nil\n    @body = nil","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/urbanadventurer/WhatWeb/blob/d279d93042d034f3fd29d5a893d44ccc0595d3f8/lib/extend-http.rb#L312-L348","documentation":"Net::HTTPBadResponse raised by each_response_header in lib/extend-http.rb when a header line from an HTTP response cannot be parsed into a key:value pair (the split on the ':' separator yields no value). The library uses this custom header parser (handling continuation lines starting with space/tab) and treats an unparseable line as a malformed response, aborting parsing. It indicates the remote server sent a response that does not conform to the HTTP header format.","triggerScenarios":"Calling Target#open or any WhatWeb plugin scan against a server whose response contains a header line without a ':' separator and no valid key already parsed (e.g. a raw garbage line, a binary/HTML body starting in the header area, or a non-HTTP service on the target port). Reached via read_new -> each_response_header during response reading.","commonSituations":"Scanning a port where a non-HTTP service (SSH, FTP, custom TCP daemon) answers; misconfigured proxies that inject non-header text; servers emitting malformed headers (missing colon, bare continuation lines without a preceding key); headless/embedded devices with broken HTTP implementations.","solutions":["Verify the target port actually speaks HTTP (curl -v http://host:port) before scanning","Skip or re-target ports that are not HTTP services; use a plain TCP probe first","If you control the server, fix it to emit RFC-compliant headers (each line must be 'Name: value')","Check for a broken/misconfigured proxy between you and the target stripping or corrupting headers"],"exampleFix":"// before: any port treated as HTTP\nTarget.new('http://example.com:22')\n// after: confirm HTTP first or catch\nbegin\n  Target.new('http://example.com:22')\nrescue Net::HTTPBadResponse\n  puts 'target does not speak HTTP'\nend","handlingStrategy":"try-catch","validationCode":"// Ruby: probe that the port speaks HTTP before scanning\ndef http?(host, port)\n  sock = TCPSocket.new(host, port)\n  sock.puts \"HEAD / HTTP/1.0\\r\\nHost: #{host}\\r\\n\\r\\n\"\n  first = sock.gets.to_s\n  sock.close\n  first.start_with?('HTTP/')\nrescue StandardError\n  false\nend","typeGuard":"def valid_target?(url)\n  uri = URI.parse(url) rescue nil\n  !uri.nil? && %w[http https].include?(uri.scheme)\nend","tryCatchPattern":"begin\n  target = Target.new(url)\nrescue Net::HTTPBadResponse => e\n  logger.warn(\"malformed HTTP response from #{url}: #{e.message}\")\n  next # skip this target\nend","preventionTips":["Verify target ports serve HTTP before scanning","Skip non-HTTP services detected by banner grabbing","Keep proxy configuration clean and RFC-compliant","Log and continue on per-target parse failures instead of aborting a batch"],"tags":["http","header-parsing","malformed-response"],"backgroundTag":"unexpected-response-shape","analyzedSha":"d279d93042d034f3fd29d5a893d44ccc0595d3f8","analyzedAt":"2026-09-15T13:51:42.453Z","contentChangedAt":"2026-09-15T13:51:42.453Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}