apache / apache/apisix-go-plugin-runner

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

Open
#154 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
198
Forks
68
PR merge metrics
No merged PRs in 30d

Description

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

```go
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 "", 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.