Code Monkey home page Code Monkey logo

httptest's Issues

Content-Type 形如 application/json; charset=utf-8 时,无法进行 JSON 解析

https://github.com/qiniu/httptest/blob/master/response.go#L92

使用switch-case来匹配响应头中的Content-Type

switch p.BodyType {
    case "application/json":
        p.Err = json.Unmarshal(p.RawBody, &p.BodyObj)
        fmt.Println(p.BodyObj)
        if p.Err != nil {
            p.ctx.Fatal("unmarshal response body failed:", p.Err)
        }
    case "application/bson":
        p.Err = bson.Unmarshal(p.RawBody, &p.BodyObj)
        if p.Err != nil {
            p.ctx.Fatal("unmarshal response body failed:", p.Err)
        }
        b, _ := json.Marshal(p.BodyObj)
        p.BodyObj = nil
        p.Err = json.Unmarshal(b, &p.BodyObj)
    default:
        p.BodyObj = string(p.RawBody)
}

Gin 返回 Content-Type 为application/json; charset=utf-8时,会进入default将 Body 当做 string 处理,使得后面的 JSON 比较失败。

是否应该换成strings.Contains()匹配 Content-Type?

cannot install

cannot install by 'go get -u qiniupkg.com/httptest.v1'

go get 没有代码?

λ go get -u qiniupkg.com/httptest.v1
package qiniupkg.com/httptest.v1: no buildable Go source files in E:\go\gopath\src\qiniupkg.com\httptest.v1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.