lib/puma/request.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method fast_write_response has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
Open

    def fast_write_response(socket, body, io_buffer, chunked, content_length)
      if body.is_a?(::File) && body.respond_to?(:read)
        if chunked  # would this ever happen?
          while chunk = body.read(BODY_LEN_MAX)
            io_buffer.append chunk.bytesize.to_s(16), LINE_END, chunk, LINE_END
Severity: Minor
Found in lib/puma/request.rb - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method str_headers has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

    def str_headers(env, status, headers, res_body, io_buffer, force_keep_alive)

      line_ending = LINE_END
      colon = COLON

Severity: Minor
Found in lib/puma/request.rb - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File request.rb has 427 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Puma
  #———————————————————————— DO NOT USE — this class is for internal use only ———


  # The methods here are included in Server, but are separated into this file.
Severity: Minor
Found in lib/puma/request.rb - About 6 hrs to fix

    Method prepare_response has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        def prepare_response(status, headers, res_body, requests, client)
          env = client.env
          socket = client.io
          io_buffer = client.io_buffer
    
    
    Severity: Minor
    Found in lib/puma/request.rb - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method handle_request has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_request(client, requests)
          env = client.env
          io_buffer = client.io_buffer
          socket  = client.io   # io may be a MiniSSL::Socket
          app_body = nil
    Severity: Minor
    Found in lib/puma/request.rb - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method normalize_env has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def normalize_env(env, client)
          if host = env[HTTP_HOST]
            # host can be a hostname, ipv4 or bracketed ipv6. Followed by an optional port.
            if colon = host.rindex("]:") # IPV6 with port
              env[SERVER_NAME] = host[0, colon+1]
    Severity: Minor
    Found in lib/puma/request.rb - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method prepare_response has 79 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def prepare_response(status, headers, res_body, requests, client)
          env = client.env
          socket = client.io
          io_buffer = client.io_buffer
    
    
    Severity: Major
    Found in lib/puma/request.rb - About 3 hrs to fix

      Method fast_write_response has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def fast_write_response(socket, body, io_buffer, chunked, content_length)
            if body.is_a?(::File) && body.respond_to?(:read)
              if chunked  # would this ever happen?
                while chunk = body.read(BODY_LEN_MAX)
                  io_buffer.append chunk.bytesize.to_s(16), LINE_END, chunk, LINE_END
      Severity: Major
      Found in lib/puma/request.rb - About 2 hrs to fix

        Method handle_request has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def handle_request(client, requests)
              env = client.env
              io_buffer = client.io_buffer
              socket  = client.io   # io may be a MiniSSL::Socket
              app_body = nil
        Severity: Major
        Found in lib/puma/request.rb - About 2 hrs to fix

          Method str_headers has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def str_headers(env, status, headers, res_body, io_buffer, force_keep_alive)
          
                line_ending = LINE_END
                colon = COLON
          
          
          Severity: Major
          Found in lib/puma/request.rb - About 2 hrs to fix

            Method normalize_env has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def normalize_env(env, client)
                  if host = env[HTTP_HOST]
                    # host can be a hostname, ipv4 or bracketed ipv6. Followed by an optional port.
                    if colon = host.rindex("]:") # IPV6 with port
                      env[SERVER_NAME] = host[0, colon+1]
            Severity: Minor
            Found in lib/puma/request.rb - About 1 hr to fix

              Method str_early_hints has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  def str_early_hints(headers)
                    eh_str = +""
                    headers.each_pair do |k, vs|
                      next if illegal_header_key?(k)
              
              
              Severity: Minor
              Found in lib/puma/request.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method req_env_post_parse has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def req_env_post_parse(env)
                    to_delete = nil
                    to_add = nil
              
                    env.each do |k,v|
              Severity: Minor
              Found in lib/puma/request.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method fast_write_str has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def fast_write_str(socket, str)
                    n = 0
                    byte_size = str.bytesize
                    while n < byte_size
                      begin
              Severity: Minor
              Found in lib/puma/request.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method str_headers has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def str_headers(env, status, headers, res_body, io_buffer, force_keep_alive)
              Severity: Minor
              Found in lib/puma/request.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if empty_body
                            io_buffer << CLOSE_CHUNKED
                            fast_write_str socket, io_buffer.read_and_reset
                          else
                            fast_write_str socket, CLOSE_CHUNKED
                Severity: Major
                Found in lib/puma/request.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              next if (byte_size = part.bytesize).zero?
                  Severity: Major
                  Found in lib/puma/request.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if io_buffer.length > IO_BUFFER_LEN_MAX
                                  fast_write_str socket, io_buffer.read_and_reset
                                end
                    Severity: Major
                    Found in lib/puma/request.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  if io_buffer.length > IO_BUFFER_LEN_MAX
                                    fast_write_str socket, io_buffer.read_and_reset
                                  end
                      Severity: Major
                      Found in lib/puma/request.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    next if part.bytesize.zero?
                        Severity: Major
                        Found in lib/puma/request.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                      next if part.nil? || (byte_size = part.bytesize).zero?
                          Severity: Major
                          Found in lib/puma/request.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        next if part.bytesize.zero?
                            Severity: Major
                            Found in lib/puma/request.rb - About 45 mins to fix

                              Method fast_write_response has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  def fast_write_response(socket, body, io_buffer, chunked, content_length)
                              Severity: Minor
                              Found in lib/puma/request.rb - About 35 mins to fix

                                Method prepare_response has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    def prepare_response(status, headers, res_body, requests, client)
                                Severity: Minor
                                Found in lib/puma/request.rb - About 35 mins to fix

                                  There are no issues that match your filters.

                                  Category
                                  Status