File: connection.rb

package info (click to toggle)
ruby-protocol-http1 0.35.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 376 kB
  • sloc: ruby: 2,367; makefile: 4
file content (71 lines) | stat: -rw-r--r-- 1,634 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2025, by Samuel Williams.

require_relative "../../../../protocol/http1/connection"

Traces::Provider(Protocol::HTTP1::Connection) do
	def write_request(authority, method, target, version, headers)
		attributes = {
			authority: authority,
			method: method,
			target: target,
			version: version,
			headers: headers&.to_h,
		}
		
		Traces.trace("protocol.http1.connection.write_request", attributes: attributes) do
			super
		end
	end
	
	def write_response(version, status, headers, reason = nil)
		attributes = {
			version: version,
			status: status,
			headers: headers&.to_h,
		}
		
		Traces.trace("protocol.http1.connection.write_response", attributes: attributes) do
			super
		end
	end
	
	def write_interim_response(version, status, headers, reason = nil)
		attributes = {
			version: version,
			status: status,
			headers: headers&.to_h,
			reason: reason,
		}
		
		Traces.trace("protocol.http1.connection.write_interim_response", attributes: attributes) do
			super
		end
	end
	
	def write_body(version, body, head = false, trailer = nil)
		attributes = {
			version: version,
			head: head,
			trailer: trailer,
			body: body&.as_json,
		}
		
		Traces.trace("protocol.http1.connection.write_body", attributes: attributes) do |span|
			super
		rescue => error
			# Capture the body state at the time of the error for EPIPE debugging:
			span["error.body"] = body&.as_json
			span["error.connection"] = {
				state: @state,
				persistent: @persistent,
				count: @count,
				stream_closed: @stream.nil?
			}
			
			raise error
		end
	end
end