Skip to content

Commit

Permalink
🐛 fix: 누락된 헤더응답 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kms0219kms committed Sep 21, 2024
1 parent a89357f commit 4819858
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"

"encoding/json"

"github.com/common-nighthawk/go-figure"
"golang.org/x/net/proxy"
)
Expand Down Expand Up @@ -87,6 +88,16 @@ func handler(w http.ResponseWriter, req *http.Request) {
}
}

// Construct the return headers
responseHeaders := w.Header()

// Add CORS headers
responseHeaders.Set("Access-Control-Allow-Origin", headers.Get("Origin"))
responseHeaders.Set("Access-Control-Allow-Headers", "*")
responseHeaders.Set("Access-Control-Allow-Methods", "*")
responseHeaders.Set("Access-Control-Allow-Credentials", "true")
responseHeaders.Set("Cross-Origin-Resource-Policy", "cross-origin")

// 청크 단위로 요청
chunkStart := 0
for {
Expand Down Expand Up @@ -119,6 +130,24 @@ func handler(w http.ResponseWriter, req *http.Request) {
break
}

if chunkStart == 0 {
copyHeader("Accept-Ranges", responseHeaders, fetchRes.Header)
copyHeader("Alt-Svc", responseHeaders, fetchRes.Header)
copyHeader("Cache-Control", responseHeaders, fetchRes.Header)

copyHeader("Content-Length", responseHeaders, fetchRes.Header)
// copyHeader("Content-Range", responseHeaders, fetchRes.Header)
copyHeader("Content-Type", responseHeaders, fetchRes.Header)

copyHeader("Date", responseHeaders, fetchRes.Header)
copyHeader("Expires", responseHeaders, fetchRes.Header)
copyHeader("Last-Modified", responseHeaders, fetchRes.Header)

copyHeader("Server", responseHeaders, fetchRes.Header)
copyHeader("Vary", responseHeaders, fetchRes.Header)
copyHeader("X-Content-Type-Options", responseHeaders, fetchRes.Header)
}

// 응답 스트림을 클라이언트에 전달
if _, err := io.Copy(w, fetchRes.Body); err != nil {
log.Printf("Error writing response: %v", err)
Expand Down

0 comments on commit 4819858

Please sign in to comment.