Skip to content

Commit

Permalink
Filling default values for middleboxes.
Browse files Browse the repository at this point in the history
Crappy code, I know :P
  • Loading branch information
PoneyClairDeLune committed Aug 7, 2024
1 parent 586d372 commit a7cf93b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions transport/internet/splithttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ type DefaultDialerClient struct {
dialUploadConn func(ctxInner context.Context) (net.Conn, error)
}

func splitHttpWriteHeaderWhenEmpty(headers *http.Header, key string, value string) {
if headers.Get(key) == "" {
headers.Add(key, value)
}
}

func (c *DefaultDialerClient) OpenDownload(ctx context.Context, baseURL string) (io.ReadCloser, gonet.Addr, gonet.Addr, error) {
var remoteAddr gonet.Addr
var localAddr gonet.Addr
Expand Down Expand Up @@ -74,6 +80,10 @@ func (c *DefaultDialerClient) OpenDownload(ctx context.Context, baseURL string)
}

req.Header = c.transportConfig.GetRequestHeader()
// Tell the middleboxes to expect an SSE response
splitHttpWriteHeaderWhenEmpty(&req.Header, "Accept", "text/event-stream")
// Tell the middleboxes to not serve from cache altogether
splitHttpWriteHeaderWhenEmpty(&req.Header, "Cache-Control", "no-cache")

response, err := c.download.Do(req)
gotConn.Close()
Expand Down

0 comments on commit a7cf93b

Please sign in to comment.