正在测试的http文件示例: https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/file
我用netty-4.1.0.beta8编译了上面的例子。
My test result:
$ ab -k -n 2 -c 1 -v 6 http://127.0.0.1:8080/test.sh
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)...INFO: POST header ==
---
GET /test.sh HTTP/1.0
Connection: Keep-Alive
Host: 127.0.0.1:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
content-length: 462
content-type: application/octet-stream
date: Fri, 26 Feb 2016 06:34:52 GMT
expires: Fri, 26 Feb 2016 06:35:52 GMT
cache-control: private, max-age=60
last-modified: Fri, 19 Feb 2016 02:35:40 GMT
connection: keep-alive
LOG: Response code = 200
LOG: header received:
**MY TEST.SH CONTENT**
WARNING: Response code not 2xx (500)
apr_poll: The timeout specified has expired (70007)
Total of 1 requests completed
我的test.sh内容似乎被认为是第二个请求的标题。
我的进一步测试:
$ ab -k -n 1 -c 1 -v 6 http://127.0.0.1:8080/test.sh
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)...INFO: POST header ==
---
GET /test.sh HTTP/1.0
Connection: Keep-Alive
Host: 127.0.0.1:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
content-length: 462
content-type: application/octet-stream
date: Fri, 26 Feb 2016 06:39:02 GMT
expires: Fri, 26 Feb 2016 06:40:02 GMT
cache-control: private, max-age=60
last-modified: Fri, 19 Feb 2016 02:35:40 GMT
connection: keep-alive
LOG: Response code = 200
..done
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8080
Document Path: /test.sh
Document Length: 0 bytes
Concurrency Level: 1
Time taken for tests: 0.005 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Keep-Alive requests: 1
Total transferred: 263 bytes
HTML transferred: 0 bytes
Requests per second: 209.25 [#/sec] (mean)
Time per request: 4.779 [ms] (mean)
Time per request: 4.779 [ms] (mean, across all concurrent requests)
Transfer rate: 53.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 5 5 0.0 5 5
Waiting: 5 5 0.0 5 5
Total: 5 5 0.0 5 5
您可以看到文档长度为0字节。
我对www.google.com运行类似的命令,它运行正常。 你能帮忙吗?提前谢谢。
答案 0 :(得分:2)
这是ApacheBench中的一个错误。
ApacheBench不完全遵循http规范,并假设标头具有一定的大小写。由于netty应用程序返回的标头没有ApacheBench期望的字符大小写,因此它假定内容长度的默认值为0字节。
<强> Http specification 4.2: 强>
HTTP标头字段,包括通用标头(第4.5节), request-header(第5.3节),response-header(第6.2节)和 entity-header(第7.1节)字段,遵循相同的通用格式 RFC 822 [9]的3.1节中给出的。每个标题字段包含 名称后跟冒号(“:”)和字段值。 字段名称 不区分大小写。字段值可以在任何数量的前面 LWS,虽然单个SP是首选。标题字段可以扩展 通过在每个额外的行之前用至少一个SP在多行上 或HT。应用程序应该遵循“常见形式”,其中一个是已知的 或指示,当生成HTTP构造时,因为可能存在 一些实现无法接受除常见形式之外的任何内容。
因为ApacheBench的keep-alive开关强制它假设服务器支持keep alive,所以它不会检测到keep alive数据包的“丢失”标头。
如果在ApacheBench中应该解决某些问题,则会出现此问题,因为该应用程序中的错误会导致错过正确的内容长度。