[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: request body rewrite cannot automatically modify content-length request header. #154

Open
zxyao145 opened this issue Jan 5, 2024 · 0 comments

Comments

@zxyao145
Copy link
zxyao145 commented Jan 5, 2024

Issue description

I am trying to rewrite the request body and response body , and the RequestFilter method code is roughly as follows:

origBody := []byte("{\"keyword\": \"xxxxx\"}")
log.Infof("request get Content-Length 1: %s", r.Header().Get("Content-Length"))
r.SetBody(origBody)
log.Infof("request get Content-Length 2: %s", r.Header().Get("Content-Length"))
r.Header().Set("Content-Length", strconv.Itoa(len(origBody)))
log.Infof("request get Content-Length 3: %s", r.Header().Get("Content-Length"))

and the log as follows:

request get Content-Length 1: 158
request get Content-Length 2: 158
request get Content-Length 3: 20

If I don't manually set the Content-Length, I will find that ResponseFilter method of the same plugin cannot be triggered and a timeout exception will occur.

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

If this is by design, please update the documentation and the demo.

Environment

  • APISIX Go Plugin Runner's version:
    github.com/apache/apisix-go-plugin-runner v0.5.1-0.20231128010119-a265bcd63ca1
  • APISIX version:
    3.6.0
  • Go version:
    1.19
  • OS (cmd: uname -a):
    debian:bullseye-slim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant