steve-chavez / ngx_pathological

An Nginx module that crafts bad HTTP responses.
MIT License
0 stars 0 forks source link

Mirror a post body #1

Open steve-chavez opened 1 week ago

steve-chavez commented 1 week ago

Currently this can be done with https://github.com/openresty/echo-nginx-module, like:

location /post {
  if ($request_method != 'POST'){
      return 405;
  }
  if ($http_content_type  != "application/json") {
      return 406;
  }
  default_type application/json;
  echo_read_request_body;
  echo $request_body;
}

But it would be more convenient to offer it out of the box here. With a custom query param:

GET /pathological?response_body=$request_body
steve-chavez commented 1 week ago

The Postman API also has a similar function:

curl https://postman-echo.com/post -d @- <<EOF
123
EOF

{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "123": ""
  },
  "headers": {
    "host": "postman-echo.com",
    "x-request-start": "t=1727193277.228",
    "connection": "close",
    "content-length": "3",
    "x-forwarded-proto": "https",
    "x-forwarded-port": "443",
    "x-amzn-trace-id": "Root=1-66f2e0bd-2c0883262b1fc6101b8c07c8",
    "user-agent": "curl/7.81.0",
    "accept": "*/*",
    "content-type": "application/x-www-form-urlencoded"
  },
  "json": {
    "123": ""
  },
  "url": "https://postman-echo.com/post"
}