proxy-wasm / proxy-wasm-rust-sdk

WebAssembly for Proxies (Rust SDK)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`dispatch_http_call` always fails with BadArgument

mflorin opened this issue · comments

Hello,

I'm trying to send an http call to a configured envoy cluster. The call fails with BadArgument every time.

    fn on_tick(&mut self) {
        let result = self.dispatch_http_call(
            "codex_updater",
            vec![
                (":host", "codex_updater"),
                (":method", "GET"),
                (":path", "/update"),
            ],
            None,
            vec![],
            Duration::from_secs(60),
        );

        match result {
            Ok(_) => {
                self.log("call dispatched to codex updater");
            },
            Err(status) => {
                self.error(format!("Error dispatching call to updater service: {:?}", status).as_str())
            }
        }
    }

The envoy cluster configuration looks like this:

static_resources:
...
  clusters:
    - name: codex_updater
      type: strict_dns
      lb_policy: round_robin
      load_assignment:
        cluster_name: codex_updater
        endpoints:
        - lb_endpoints:
          - endpoint:
              address:
                socket_address:
                  address: codex_updater
                  port_value: 9001

(":host", "codex_updater")

There is no :host pseudo-header, it should be :authority.

Thanks @PiotrSikora - it looks like it does work with :authority however it also works with host (without the :).
Not sure if I missed the docs but I think this should be documented somewhere, as it is a bit confusing.

I also found this very confusing. Though I am not an envoy expert by any means. For anyone else who's searching, here's my current limited understanding.

self.dispatch_http_call(
    // an envoy cluster name that can resolve your host
   "my-cluster",
  // pseudo headers
  vec![
      // the hostname that gets resolved by the cluster
      (":authority", "my-cluster"),
      (":method", "POST"),
      (":path", "/endpoint/to/call"),
    ],
    None,
    vec![],
    Duration::from_millis(20),
)

@averagechris it should be :authority (pseudo-header) not authority:. Same for the other two.

@averagechris it should be :authority (pseudo-header) not authority:. Same for the other two.

Oh yes, of course. Thanks for noticing my typos. I'll edit the comment for any future copy pasters 👍