Compare commits

...

2 Commits

Author SHA1 Message Date
ba97f2ad03 fix: add header 2025-10-27 10:54:26 +08:00
e4d2680019 fix: optimize base64url parser (#2376) 2025-10-23 07:01:25 +00:00
2 changed files with 33 additions and 3 deletions

View File

@ -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

View File

@ -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
}
}
}