400 Bad Request[Kong Hybrid Mode]

Data Setup:

Service:
name: test-service
host: m1.com
port: 8080
protocol: http

Route:
name: test-service-route
paths: /testapi
protocol: https
method: GET
strip_path: false
preserve_host: false
service: 34343444434(test-service)

upstreams/targets:
upstream_name > target_datails
test.api > m1.com:8080
api1.com > api1.com:443
api2.com > api2.com:443

External Proxy Details:
external_url > internal_url
https://api1.com > m1.com:8443 (kong data-plane1)
https://api2.com > m2.com:8443 (kong data-plane2)

Kong is deployed on hybrid mode, https://api1.com is data-plane1(m1.com:8443) and https://api2.com is data-plane2(m2.com:8443) and the sample API is deployed on m1.com:8080(http).

Use case 1: when a request is made to https://api1.com/testapi we are doing few evaluations on a custom plugin and we are returning the upstream “test.api”(m1.com:8080) and it works.

Use case 2: when a request is made to https://api2.com/testapi after the evaluations we are returning the upstream “api1.com”(api1.com:443) and it fails with “400 bad request”(Your browser sent a request that this server could not understand. Reason: You’re speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.).

On use case2 when the system returns to upstream “api1.com” the functionality should have worked same as use case1 but its not working.

Note: The same use cases are working perfectly fine when the service protocol is https.

Please let me know in case of any mistakes and help me out in solving this.