Created
August 5, 2017 13:11
-
-
Save LucaDev/61c3323dbd5963dcbd36d36b5ca2fc09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"golang.org/x/net/http2/hpack" | |
) | |
func main() { | |
fmt.Println(EncodeString(os.Args[1])) | |
} | |
func EncodeString(in string) string { | |
hs := hpack.AppendHuffmanString(nil, in) | |
length := byte(hpack.HuffmanEncodeLength(in) | 0x80) | |
enc := FormatByte(length) | |
for _, b := range hs { | |
enc += FormatByte(b) | |
} | |
return fmt.Sprintf("static const u_char nginx[%d] = \"%s\";", len(hs)+1, enc) | |
} | |
func FormatByte(b byte) string { | |
return fmt.Sprintf("\\x%x", b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment