|
@@ -7,7 +7,6 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"net/http"
|
|
|
- "net/url"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
@@ -43,24 +42,17 @@ func forwardRequestWithJWT(c *gin.Context, targetURL string) (interface{}, error
|
|
|
|
|
|
req.Header.Set("Authorization", jwtToken)
|
|
|
|
|
|
+ // Set content type
|
|
|
if c.Request.Method == "POST" {
|
|
|
if strings.Contains(targetURL, "/api/set-password") {
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
- // Parse JSON body and convert to form data
|
|
|
- if len(bodyBytes) > 0 {
|
|
|
- var jsonData map[string]interface{}
|
|
|
- if err := json.Unmarshal(bodyBytes, &jsonData); err != nil {
|
|
|
- return nil, fmt.Errorf("parse json error: %v", err)
|
|
|
- }
|
|
|
- formData := url.Values{}
|
|
|
- for k, v := range jsonData {
|
|
|
- formData.Set(k, fmt.Sprintf("%v", v))
|
|
|
- }
|
|
|
- req.Body = io.NopCloser(strings.NewReader(formData.Encode()))
|
|
|
- }
|
|
|
+ } else if contentType := c.GetHeader("Content-Type"); contentType != "" {
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
} else {
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
}
|
|
|
+ } else if contentType := c.GetHeader("Content-Type"); contentType != "" {
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
}
|
|
|
|
|
|
// Accept gzip encoding
|