Copilot commented on code in PR #3634:
URL: https://github.com/apache/thrift/pull/3634#discussion_r3566563424
##########
test/tests.json:
##########
@@ -444,6 +444,9 @@
"ruby",
"../integration/TestClient.rb",
"--"
+ ],
+ "transports": [
+ "http"
]
},
Review Comment:
`rb` target now restricts the Ruby **client** to `http` only, which drops
existing buffered/framed client coverage in the cross-test matrix (client
transports override the target-level transports). If the intent is to add HTTP
client coverage while keeping the previous transports, include `buffered` and
`framed` here as well.
##########
lib/rb/lib/thrift/server/rack_application.rb:
##########
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require 'rack'
+require 'stringio'
+require 'thrift/multiplexed_processor'
+require 'thrift/transport/io_stream_transport'
+require 'thrift/transport/memory_buffer_transport'
+require 'thrift/types'
+
+module Thrift
+ class RackApplication
+ THRIFT_HEADER = "application/x-thrift"
+
+ def initialize(processor, protocol_factory = BinaryProtocolFactory.new)
+ @processor = processor
+ @protocol_factory = protocol_factory
+ end
+
+ def call(env)
+ request = Rack::Request.new(env)
+
+ if self.class.valid_thrift_request?(request)
+ self.class.successful_request(request, @processor,
@protocol_factory).finish
+ else
+ self.class.failed_request.finish
+ end
+ end
+
+ def self.mapped(path, processor, protocol_factory =
BinaryProtocolFactory.new)
+ Rack::Builder.new do
+ use Rack::CommonLogger
+ use Rack::ShowExceptions
+ use Rack::Lint
+ use Rack::ContentLength
+ map path do
+ run RackApplication.new(processor, protocol_factory)
+ end
+ end
+ end
+
+ def self.successful_request(rack_request, processor, protocol_factory)
+ response = Rack::Response.new([], 200, {Rack::CONTENT_TYPE =>
THRIFT_HEADER})
+ input_protocol = request_protocol(rack_request, protocol_factory).first
+ output_protocol =
protocol_factory.get_protocol(IOStreamTransport.new(StringIO.new, response))
+ processor.process input_protocol, output_protocol
+
+ response
+ end
+
+ def self.failed_request
+ Rack::Response.new(['Not Found'], 404, {Rack::CONTENT_TYPE =>
THRIFT_HEADER})
+ end
+
+ def self.valid_thrift_request?(rack_request)
+ rack_request.post? && rack_request.content_type == THRIFT_HEADER
+ end
Review Comment:
`valid_thrift_request?` compares `content_type` using strict equality. Real
clients (and some Rack stacks) may attach parameters (e.g.
`application/x-thrift; charset=binary`), which would currently be treated as
404. Stripping parameters before comparison improves interoperability without
weakening the method check.
##########
lib/rb/lib/thrift/server/rack_application.rb:
##########
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require 'rack'
+require 'stringio'
+require 'thrift/multiplexed_processor'
+require 'thrift/transport/io_stream_transport'
+require 'thrift/transport/memory_buffer_transport'
+require 'thrift/types'
+
+module Thrift
+ class RackApplication
+ THRIFT_HEADER = "application/x-thrift"
+
+ def initialize(processor, protocol_factory = BinaryProtocolFactory.new)
+ @processor = processor
+ @protocol_factory = protocol_factory
+ end
+
+ def call(env)
+ request = Rack::Request.new(env)
+
+ if self.class.valid_thrift_request?(request)
+ self.class.successful_request(request, @processor,
@protocol_factory).finish
+ else
+ self.class.failed_request.finish
+ end
+ end
+
+ def self.mapped(path, processor, protocol_factory =
BinaryProtocolFactory.new)
+ Rack::Builder.new do
+ use Rack::CommonLogger
+ use Rack::ShowExceptions
+ use Rack::Lint
+ use Rack::ContentLength
Review Comment:
`RackApplication.mapped` unconditionally adds `Rack::ShowExceptions` and
`Rack::Lint`. Those middlewares are typically development-only (ShowExceptions
can expose stack traces; Lint adds overhead) and may be surprising in a library
convenience constructor. Consider leaving middleware selection to the host app
/ server wrapper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]