-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(headers): support all types of line breaks (#1046)
Now it only works properly if the line break is `\r\n`. Using the `splitLines` function solves this problem. Rewritten the function `checkParseHeaders` and renamed it to `extractHeaders` for better readability.
- Loading branch information
1 parent
23f39fb
commit 4c11754
Showing
4 changed files
with
46 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
// TestParseHeaderArr 测试 parseHeaderArr | ||
func TestParseHeaderArr(t *testing.T) { | ||
headers := "a : 1\r\nb:2\r\n" | ||
expected := `map[a:1 b:2]` | ||
parsedHeaders := checkParseHeaders(headers) | ||
resultStr := fmt.Sprintf("%v", parsedHeaders) | ||
if resultStr != expected { | ||
t.Error("解析Header失败", resultStr) | ||
func TestExtractHeaders(t *testing.T) { | ||
input := ` | ||
a: foo | ||
b: bar` | ||
expected := map[string]string{ | ||
"a": "foo", | ||
"b": "bar", | ||
} | ||
|
||
parsedHeaders := extractHeaders(input) | ||
if !reflect.DeepEqual(parsedHeaders, expected) { | ||
t.Errorf("Expected %v, got %v", expected, parsedHeaders) | ||
} | ||
} |
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
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