File: net_http.rb

package info (click to toggle)
ruby-samuel 0.3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 172 kB
  • sloc: ruby: 735; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Samuel
  module LogEntries
    class NetHttp < Base
      def host
        @http.address
      end

      def path
        @request.path.split("?")[0]
      end

      def query
        @request.path.split("?")[1]
      end

      def scheme
        @http.use_ssl? ? "https" : "http"
      end

      def port
        @http.port
      end

      def method
        @request.method.to_s.upcase
      end

      def status_code
        @response.code
      end

      def status_message
        @response.message.strip
      end

      def error?
        error_classes = %w(Exception Net::HTTPClientError Net::HTTPServerError)
        response_ancestors = @response.class.ancestors.map { |a| a.to_s }
        (error_classes & response_ancestors).any?
      end
    end
  end
end