How To Customize Your Nginx Server Name
- src/core/nginx.h
#define NGINX_VER "MYWS/“ NGINX_VERSION
- http/ngx_http_special_response.c
"<hr><center>MYWS</center>” CRLF
- http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: MYWS" CRLF;
- src/http/v2/ngx_http_v2_filter_module.c
static const u_char nginx[5] = "\x84\xd1\xcf\x96\xef";
第4点是为http2 做的修改.
字节码生成:
package main
import (
"fmt"
"golang.org/x/net/http2/hpack"
)
func main() {
fmt.Println("nginx", "→", Encode("MYWS"))
fmt.Println("nginx", "→", Encode("nginx"))
fmt.Println("apache", "→", Encode("apache"))
fmt.Println("-----")
fmt.Println("\\x84\\xaa\\x63\\x55\\xe7", "→", Decode("\x84\xaa\x63\x55\xe7"))
fmt.Println("\\x84\\x1d\\x63\\x24\\xe5", "→", Decode("\x84\x1d\x63\x24\xe5"))
}
func Encode(s string) string {
var result string
hd := hpack.AppendHuffmanString(nil, s)
hl := hpack.HuffmanEncodeLength(s) | 0x80
result += RenderByte(byte(hl))
for _, b := range hd {
result += RenderByte(b)
}
return result
}
func Decode(s string) string {
data := []byte(s)
result, _ := hpack.HuffmanDecodeToString(data[1:])
return result
}
func RenderByte(b byte) string {
return fmt.Sprintf("\\x%x", b)
}
参考 https://stackoverflow.com/questions/35655448/how-does-this-code-result-in-the-string-nginx0人点赞nginx“小礼物走一走,来简书
作者:未兆谋
链接:https://www.jianshu.com/p/5167cca96837
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。