Compare commits
2 Commits
chore/upgr
...
fix/add-ca
| Author | SHA1 | Date | |
|---|---|---|---|
| ba97f2ad03 | |||
| e4d2680019 |
@ -51,6 +51,8 @@ func (s *saasCallImpl) Do(ctx context.Context, args *InvocationArgs) (request st
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
s.injectUserAgentHeader(ctx, httpReq)
|
||||
|
||||
var reqBodyBytes []byte
|
||||
if httpReq.GetBody != nil {
|
||||
reqBody, err := httpReq.GetBody()
|
||||
@ -118,6 +120,9 @@ func (s *saasCallImpl) injectAuthInfo(ctx context.Context, httpReq *http.Request
|
||||
httpReq.Header.Set("Authorization", "Bearer "+saasapiClient.APIKey)
|
||||
return nil
|
||||
}
|
||||
func (s *saasCallImpl) injectUserAgentHeader(ctx context.Context, httpReq *http.Request) {
|
||||
httpReq.Header.Set("User-Agent", "open_coze/1.0.0")
|
||||
}
|
||||
|
||||
func (s *saasCallImpl) buildHTTPRequest(ctx context.Context, args *InvocationArgs) (httpReq *http.Request, err error) {
|
||||
tool := args.Tool
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FileData struct {
|
||||
@ -49,12 +50,36 @@ func URLToBase64(url string) (*FileData, error) {
|
||||
|
||||
var mimeType string
|
||||
|
||||
mimeType = resp.Header.Get("Content-Type")
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
if contentType != "" {
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err == nil && mediaType != "" {
|
||||
mimeType = mediaType
|
||||
}
|
||||
}
|
||||
|
||||
if mimeType == "" {
|
||||
ext := filepath.Ext(url)
|
||||
detectedType := http.DetectContentType(fileContent)
|
||||
if detectedType != "application/octet-stream" {
|
||||
mimeType = detectedType
|
||||
}
|
||||
}
|
||||
|
||||
if mimeType == "" || mimeType == "application/octet-stream" {
|
||||
urlPath := url
|
||||
if idx := strings.Index(urlPath, "?"); idx != -1 {
|
||||
urlPath = urlPath[:idx]
|
||||
}
|
||||
if idx := strings.Index(urlPath, "#"); idx != -1 {
|
||||
urlPath = urlPath[:idx]
|
||||
}
|
||||
|
||||
ext := filepath.Ext(urlPath)
|
||||
if ext != "" {
|
||||
mimeType = mime.TypeByExtension(ext)
|
||||
extMimeType := mime.TypeByExtension(ext)
|
||||
if extMimeType != "" {
|
||||
mimeType = extMimeType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user