@@ -10,21 +10,22 @@ class LambdaServer
1010 LAMBDA_DEFAULT_SERVER_ADDRESS = '127.0.0.1:9001'
1111 LAMBDA_RUNTIME_API_VERSION = '2018-06-01'
1212
13- MAX_HEADER_SIZE = 1024 * 1024
14- LONG_TIMEOUT = 1_000_000
13+ MAX_HEADER_SIZE_BYTES = 1024 * 1024
14+ LONG_TIMEOUT_MS = 1_000_000
1515
16- def initialize ( server_address )
16+ def initialize ( server_address , user_agent )
1717 server_address ||= LAMBDA_DEFAULT_SERVER_ADDRESS
18- @server_address = 'http://' + server_address + '/' + LAMBDA_RUNTIME_API_VERSION
18+ @server_address = "http://#{ server_address } /#{ LAMBDA_RUNTIME_API_VERSION } "
19+ @user_agent = user_agent
1920 end
2021
2122 def next_invocation
2223 next_invocation_uri = URI ( @server_address + '/runtime/invocation/next' )
2324 begin
2425 http = Net ::HTTP . new ( next_invocation_uri . host , next_invocation_uri . port )
25- http . read_timeout = LONG_TIMEOUT
26+ http . read_timeout = LONG_TIMEOUT_MS
2627 resp = http . start do |connection |
27- connection . get ( next_invocation_uri . path )
28+ connection . get ( next_invocation_uri . path , { 'User-Agent' => @user_agent } )
2829 end
2930 if resp . is_a? ( Net ::HTTPSuccess )
3031 request_id = resp [ 'Lambda-Runtime-Aws-Request-Id' ]
@@ -51,7 +52,7 @@ def send_response(request_id:, response_object:, content_type: 'application/json
5152 Net ::HTTP . post (
5253 response_uri ,
5354 response_object ,
54- { 'Content-Type' => content_type }
55+ { 'Content-Type' => content_type , 'User-Agent' => @user_agent }
5556 )
5657 rescue StandardError => e
5758 raise LambdaErrors ::LambdaRuntimeError . new ( e )
@@ -61,8 +62,8 @@ def send_response(request_id:, response_object:, content_type: 'application/json
6162 def send_error_response ( request_id :, error_object :, error :, xray_cause :)
6263 response_uri = URI ( @server_address + "/runtime/invocation/#{ request_id } /error" )
6364 begin
64- headers = { 'Lambda-Runtime-Function-Error-Type' => error . runtime_error_type }
65- headers [ 'Lambda-Runtime-Function-XRay-Error-Cause' ] = xray_cause if xray_cause . bytesize < MAX_HEADER_SIZE
65+ headers = { 'Lambda-Runtime-Function-Error-Type' => error . runtime_error_type , 'User-Agent' => @user_agent }
66+ headers [ 'Lambda-Runtime-Function-XRay-Error-Cause' ] = xray_cause if xray_cause . bytesize < MAX_HEADER_SIZE_BYTES
6667 Net ::HTTP . post (
6768 response_uri ,
6869 error_object . to_json ,
@@ -79,7 +80,7 @@ def send_init_error(error_object:, error:)
7980 Net ::HTTP . post (
8081 uri ,
8182 error_object . to_json ,
82- { 'Lambda-Runtime-Function-Error-Type' => error . runtime_error_type }
83+ { 'Lambda-Runtime-Function-Error-Type' => error . runtime_error_type , 'User-Agent' => @user_agent }
8384 )
8485 rescue StandardError => e
8586 raise LambdaErrors ::LambdaRuntimeInitError . new ( e )
0 commit comments