Skip to content

When I changed request body,the program enters an endless loop #209

Open

Description

@Fengxq2014
impl HttpContext for HttpHeadersBody {
    fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action {
        if !end_of_stream {
            return Action::Pause;
        }
        info!("on_http_request_body");
        match self.get_shared_data("changed") {
            (change, _) => {
                match change {
                    None => {}
                    Some(c) => {
                        info!("context-{}, changed:{}",self.context_id, String::from_utf8(c).unwrap());
                        return Action::Continue;
                    }
                }
            }
        }
        self.dispatch_http_call(
            "httpbin",
            vec![
                (":method", "GET"),
                (":path", "/bytes/1"),
                (":authority", "httpbin.org"),
            ],
            None,
            vec![],
            Duration::from_secs(5),
        )
            .unwrap();
        Action::Pause
    }
}

impl Context for HttpHeadersBody {
    fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) {
        info!("on_http_call_response");
        if let Some(body) = self.get_http_call_response_body(0, body_size) {
            if !body.is_empty() {
                let mod_body = "modify body";
                self.set_http_request_body(0, mod_body.as_bytes().len(), mod_body.as_bytes());
                self.set_shared_data("changed", Some("true".as_bytes()), None);
                self.resume_http_request();
                return;
            }
        }
        info!("Access forbidden.");
        self.send_http_response(
            403,
            vec![("Powered-By", "proxy-wasm")],
            Some(b"Access forbidden.\n"),
        );
    }
}

image

Activity

  1. PiotrSikora commented on Sep 25, 2023

    @PiotrSikora
    Member

    I don't see any loop in your logs, the context_id is clearly different across those log entries.

    The problem with your code is that the key-value store is global, not local to a request, so "changed" persists across requests, which probably breaks your logic.

  2. Fengxq2014 commented on Sep 27, 2023

    @Fengxq2014
    Author

    I only sent one request, and the log began to print indefinitely

  3. paulgreenfield1983 commented on Nov 23, 2023

    @paulgreenfield1983

    I have a very similar issue with the (unchanged) http_auth_random example - sending requests to localhost:10000/headers will always return "Access forbidden.". When I examine the logs I can see that multiple passes are made through on_http_request_headers until it hits send_http_response. The below were for a single request from the client:

    image
  4. changed the title [-]When I changed request body,he program enters an endless loop[/-] [+]When I changed request body,the program enters an endless loop[/+] on Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions