From 132324b6586cefdaafbed07416e93a422294a2de Mon Sep 17 00:00:00 2001 From: Viola_Pioggia <114391708+ViolaPioggia@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:26:51 +0800 Subject: [PATCH] docs: add adaptor README.md (#9) * docs: add adaptor README.md * chore: adjust note --- adaptor/README.md | 13 +++++++++++++ adaptor/handler_test.go | 11 ++--------- 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 adaptor/README.md diff --git a/adaptor/README.md b/adaptor/README.md new file mode 100644 index 0000000..a0510ce --- /dev/null +++ b/adaptor/README.md @@ -0,0 +1,13 @@ +## Note: + +- When modifying the resp header in the server handler, please use `write` function to write the header. Otherwise, the modification will not take effect. + +```go +func handler(resp http.ResponseWriter, req *http.Request) { + resp.Header().Add("Content-Encoding", "test") + _, err := resp.Write([]byte("Content-Encoding: test\n")) + if err != nil { + panic(err) + } +} +``` \ No newline at end of file diff --git a/adaptor/handler_test.go b/adaptor/handler_test.go index 5c0ff89..e2e345f 100644 --- a/adaptor/handler_test.go +++ b/adaptor/handler_test.go @@ -43,7 +43,6 @@ package adaptor import ( "context" - "fmt" "io/ioutil" "net/http" "net/url" @@ -478,16 +477,10 @@ func TestFile(t *testing.T) { assert.NotEqual(t, req.Header.Get("Content-Type"), "application/x-www-form-urlencoded") err := req.ParseForm() - if err != nil { - fmt.Println(err) - panic(err) - } + assert.Nil(t, err) file, m, err := req.FormFile("file") - if err != nil { - fmt.Println(err) - panic(err) - } + assert.Nil(t, err) assert.DeepEqual(t, m.Filename, "handler.go")