Apigee emulator: getting "plain HTTP request was sent to HTTPS port" when using target server

Hi! I'm trying to use TargetServers to decouple concrete endpoint URLs from TargetEndpoint configurations, as specified here: https://cloud.google.com/apigee/docs/api-platform/deploy/load-balancing-across-backend-servers .

When developing locally using VSCode plugin, I'm getting "plain HTTP request was sent to HTTPS port" when trying to hit HTTPS backends.

This is working fine when deploying to apigee.google.com. However, when developing locally using VSCode plugin, I'm getting "plain HTTP request was sent to HTTPS port" when trying to hit HTTPS backends.

Apigee emulator runtime version: 1.6.1.

Restarting/resetting the emulator doesn't help.

 

apiproxies/sample-v1/apiproxy/targets/default.xml:

 

<TargetEndpoint name="default">
    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="sample-backend"/>
        </LoadBalancer>
    </HTTPTargetConnection>
</TargetEndpoint>

 

 

environments\local\targetservers.json:

 

[{
  "name": "sample-backend",
  "host": "httpbin.org",
  "port": 443,
  "sSLInfo": {
    "enabled": "true"
  }
}]

 

 

When issuing this command:

 

curl -v http://127.0.0.1:8998/sample/v1/get

 

 

I'm getting the following response:

 

*   Trying 127.0.0.1:8998...
* Connected to 127.0.0.1 (127.0.0.1) port 8998 (#0)
> GET /sample/v1/get HTTP/1.1
> Host: 127.0.0.1:8998
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Server: awselb/2.0
< Date: Wed, 30 Mar 2022 09:54:30 GMT
< Content-Type: text/html
< Content-Length: 220
< X-Apigee-Message-ID: 9cb22ade-5b57-46fd-8379-b875591035fc8
< x-request-id: 9cb22ade-5b57-46fd-8379-b875591035fc8
< X-Apigee-organization: hybrid
< X-Apigee-proxy: /organizations/hybrid/environments/local/apiproxies/sample-v1/revisions/0
< X-Apigee-proxy-basepath: /sample/v1
< X-Apigee-fault-flag: false
< X-Apigee-fault-source: target
< X-Apigee-fault-code: messaging.adaptors.http.flow.ErrorResponseCode
< X-Apigee-fault-policy: null/null
< X-Apigee-fault-revision: /organizations/hybrid/environments/local/apiproxies/sample-v1/revisions/0
< X-Apigee-target-latency: 336
<
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact

 

 

PoC repo to reproduce the problem: https://github.com/mixefy/apigee-emulator-targetservers

1 6 876
6 REPLIES 6

Thanks for an excellent description @gaeshi I am following up on this internally and get back to this when I get an update.

@strebel Thank you!

I had opened https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues/551 previously as I think there's a mis-match between the target server API and the vs code JSON format. I'm guessing (based on very little) the ssl info doesn't actually get applied to anything and that there's not actually a way to do HTTPS target server in vs code

Thank you @emarcotte . I have upvoted the issue and added the link to the PoC of the problem.

Memo: there is an (abandoned since June?) issue on GitHub about this: https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues/595

Just tried with the configuration below it should work with emulator version >1.9 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="order">
 
  <HTTPTargetConnection>
    <Properties/>
    <LoadBalancer>
      <Server name="order-target"/>
    </LoadBalancer>
    <Path>/post</Path>
    <SSLInfo>
      <Enabled>true</Enabled>
    </SSLInfo>
  </HTTPTargetConnection>
</TargetEndpoint
{
        "enabled": true,
        "name": "order-target",
        "description": "order-target",
        "host": "httpbin.org",
        "port": 443,
        "sSLInfo": {
            "enabled": true
        },
        "protocol": "HTTP"
    }