Skip to content

Commit

Permalink
download json file status code = 200, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomingqiang committed Sep 29, 2021
1 parent 24bd966 commit 00d14a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions api/core/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,17 @@ func validateResponseFunc(_ *core.Context, req *request.Request) {
resp := req.HTTPResponse
contentType := resp.Header.Get(coreconst.ContentType)
if req.IsResponseStream {
if resp.StatusCode == http.StatusOK {
req.IsResponseStreamReal = true
return
}
if strings.Contains(contentType, coreconst.ContentTypeJson) {
req.IsResponseStreamReal = false
return
}
if resp.StatusCode != http.StatusOK {
req.Err = fmt.Errorf("response is stream, but status code:%d", resp.StatusCode)
req.Err = fmt.Errorf("response is stream, but status code:%d, contentType:%s", resp.StatusCode, contentType)
}
req.IsResponseStreamReal = true
return
}
if !strings.Contains(contentType, coreconst.ContentTypeJson) {
Expand Down
6 changes: 3 additions & 3 deletions sample/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var conf = configs.TestConfigWithLogrusAndRedisStore(core.DomainFeiShu)

func main() {
//testSendMessage()
testSendCardMessage()
//testSendCardMessage()
//testUploadFile()
//testDownloadFile()
testDownloadFile()
}

// send card message
Expand Down Expand Up @@ -142,7 +142,7 @@ func testDownloadFile() {
*/
req := request.NewRequestWithNative("/open-apis/image/v4/get", "GET",
request.AccessTokenTypeTenant, nil, ret,
request.SetQueryParams(map[string]interface{}{"image_key": "[image key]"}), request.SetResponseStream())
request.SetQueryParams(map[string]interface{}{"image_key": "img_v2_f6203671-41d6-46ed-adc9-c50aa840330g"}), request.SetResponseStream())
err := api.Send(coreCtx, conf, req)
fmt.Println(coreCtx.GetRequestID())
fmt.Println(coreCtx.GetHTTPStatusCode())
Expand Down

0 comments on commit 00d14a7

Please sign in to comment.