我使用 gwan 生成图像,所以我需要设置正确的内容类型,但是 G-WAN 3.12.26 在经过一些加载后会添加自己的内容类型为 text/html 的标头并返回带有 2 个 http 标头的页面。
如何重现这个:
使用 gwan 包中的 setheaders.c servlet,启动 gwan 并打开这个页面,假设http://localhost/?setheaders.c
你会得到这个(正确的响应):
HTTP/1.1 200 OK
Date: Sat, 29 Dec 2012 20:37:52 GMT
Last-Modified: Sat, 29 Dec 2012 20:37:52 GMT
Content-type: text/html
Content-Length: 371
Connection: close
<!DOCTYPE HTML><html lang="en"><head><title>Setting response headers</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link href="imgs/style.css" rel="stylesheet" type="text/css"></head><body style="margin:16px;"><h1>Setting response headers</h1><br>This reply was made with custom HTTP headers, look at the servlet source code.<br></body></html>`
现在运行 apache bench:ab -n 1000 'http://localhost/?setheaders.c'
(1000 个请求对我的系统来说已经足够了)。
不要重新启动 GWAN,http://localhost/?setheaders.c
再次打开,这就是你应该得到的(不正确的响应,2 个 http 标头):
HTTP/1.1 200 OK
Server: G-WAN
Date: Sat, 29 Dec 2012 20:43:34 GMT
Last-Modified: Fri, 16 Jan 1970 16:53:33 GMT
ETag: "be86ada7-14b40d-16f"
Vary: Accept-Encoding
Accept-Ranges: bytes
Content-Type: text/html; charset=UTF-8
Content-Length: 367
Content-Encoding: gzip
Connection: close
HTTP/1.1 200 OK
Date: Sat, 29 Dec 2012 20:43:34 GMT
Last-Modified: Sat, 29 Dec 2012 20:43:34 GMT
Content-type: text/html
Content-Length: 371
Connection: close
<!DOCTYPE HTML><html lang="en"><head><title>Setting response headers</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link href="imgs/style.css" rel="stylesheet" type="text/css"></head><body style="margin:16px;"><h1>Setting response headers</h1><br>This reply was made with custom HTTP headers, look at the servlet source code.<br></body></html>
如果 gzip 和 x-gzip 未在请求标头 ( Accept-Encoding: gzip, x-gzip
) 中设置为可接受的编码,GWAN 将返回正确的响应。
是否有可能解决这个修改只是servlet?如果是,那么如何?