2

我使用 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?如果是,那么如何?

4

1 回答 1

0

您是否设置MIME type如下所示fractal.c

   // -------------------------------------------------------------------------
   // specify a MIME type so we don't have to build custom HTTP headers
   // -------------------------------------------------------------------------
   char *mime = (char*)get_env(argv, REPLY_MIME_TYPE);
   // note that we setup the FILE EXTENTION, not the MIME type:
   mime[0] = '.'; mime[1] = 'g'; mime[2] = 'i'; mime[3] = 'f'; mime[4] = 0;

如果您这样做,则无法混淆自动标题功能。

除此之外,由于我们的直接系统调用和 GLIBC 包装器,v3.12 还存在许多不稳定性问题(文件时间故障、pthread 故障、信号故障等) - 最初旨在使程序在所有版本的 Linux 上运行的努力。

我们发现(多亏了像你这样的许多报告),与其尝试一个一个地解决这些问题(毫无意义地与 GLIBC 作斗争,一个移动的目标,有许多不同的版本,每个版本都有自己的错误和特性)更安全的路径是放弃GLIBC。

这就是 G-WAN v4 将在几天后做的事情。

于 2012-12-30T09:29:34.690 回答