-
Notifications
You must be signed in to change notification settings - Fork 7
/
mailbox.go
41 lines (34 loc) · 876 Bytes
/
mailbox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package proxy
import (
"io"
"strings"
"github.com/gin-gonic/gin"
"github.com/harryzcy/mailbox-browser/bff/request"
"github.com/harryzcy/mailbox-browser/bff/transport/rest/ginutil"
)
func MailboxProxy(ctx *gin.Context) {
method := ctx.Request.Method
payload, err := io.ReadAll(ctx.Request.Body)
if err != nil {
ginutil.InternalError(ctx, err)
return
}
resp, err := request.AWSRequest(ctx, request.Options{
Method: method,
Path: strings.TrimPrefix(ctx.Request.URL.Path, "/web"),
Query: ctx.Request.URL.Query(),
Payload: payload,
})
if err != nil {
ginutil.InternalError(ctx, err)
return
}
headers := make(map[string]string)
for k, v := range resp.Header {
if k == "Content-Type" {
continue
}
headers[k] = v[0]
}
ctx.DataFromReader(resp.StatusCode, resp.ContentLength, resp.Header.Get("Content-Type"), resp.Body, headers)
}