Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加请求中间件设计 #235

Closed
guonaihong opened this issue Jun 23, 2020 · 0 comments
Closed

增加请求中间件设计 #235

guonaihong opened this issue Jun 23, 2020 · 0 comments
Labels

Comments

@guonaihong
Copy link
Owner

guonaihong commented Jun 23, 2020

目的

保持核心的精简

接口

  • RequestUse

通过中间件修改请求数据包

把数据包里面的hello修改为demo

type demoRequestMiddler struct{}

func (d *demoRequestMiddler) ModifyRequest(req *http.Request) error {
        req.Body = ioutil.NopCloser(strings.NewReader("demo"))
        req.ContentLength = 4
        return nil
}

func demoRequest() api.RequestMiddler {
        return &demoRequestMiddler{}
}

func Test_RequestModify(t *testing.T) {
New().POST(ts.URL).RequestUse(demoRequest()).SetBody("hello").BindBody(&s).Do()
        assert.NoError(t, err, fmt.Sprintf("test url:%s", ts.URL))
        assert.Equal(t, s, "demo")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant