panhow opened a new issue, #9029:
URL: https://github.com/apache/apisix/issues/9029
### Current Behavior
i was testing k8s discovery .
I met this promblem when i use `discovery.kubernetes.client.token_file`
instead `discovery.kubernetes.client.token` .
`util.read_file()` return the string with "LF"(the last character of the
file) . as a result, k8s client will get a response with `400 bad request:
missing required Host header`, because when http client build a request, "LF"
in a http header lines is a line break. As a consequence, invalid http request
sent to api server.
### Expected Behavior
`util.read_file` return a string with no "LF" in the end.
here is the minimum reproducable code written by lua:
```lua
local f = io.open("/tmp/t")
local s = f:read("*all")
print(s:byte(1,-1))
```
bash script
```bash
cat <<EOF >> test.lua
local f = io.open("/tmp/t")
local s = f:read("*all")
print(s:byte(1,-1))
EOF
echo "a" >> /tmp/t
resty test.lua
```
this example will get a result:
```
9710
```
### Error Logs
Error Log:
```
2023/03/07 20:00:47 [error] 20047#20047: *480073452 [lua]
informer_factory.lua:295: list failed, kind: Endpoints, reason: Bad Request:
missing required Host header, message : 400 Bad Request: missing required Host
header, context: ngx.timer
```
tcpdump to capture the http request:

Set token as `abc`.
Add logs to find what the token is, also print every byte in the token
string.

### Steps to Reproduce
1.add k8s discovery to `config.yaml `
```yaml
discovery:
kubernetes:
service:
schema: https
host: "127.0.0.1"
port: "6443"
client:
token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
```
2. reload apisix
error logs :
```
2023/03/07 20:00:47 [error] 20047#20047: *480073452 [lua]
informer_factory.lua:295: list failed, kind: Endpoints, reason: Bad Request:
missing required Host header, message : 400 Bad Request: missing required Host
header, context: ngx.timer
```
### Environment
- APISIX version (run `apisix version`): 2.15.1
- Operating system (run `uname -a`): centos7
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`): 1.21.4.1
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`):3.4.15
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]