Skip to content

Commit

Permalink
SplitHTTP server: Add noSSEHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX committed Jul 29, 2024
1 parent 59f6685 commit 60553a6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type SplitHTTPConfig struct {
MaxConcurrentUploads Int32Range `json:"maxConcurrentUploads"`
MaxUploadSize Int32Range `json:"maxUploadSize"`
MinUploadIntervalMs Int32Range `json:"minUploadIntervalMs"`
NoSSEHeader bool `json:"noSSEHeader"`
}

// Build implements Buildable.
Expand Down Expand Up @@ -260,6 +261,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
From: c.MinUploadIntervalMs.From,
To: c.MinUploadIntervalMs.To,
},
NoSSEHeader: c.NoSSEHeader,
}
return config, nil
}
Expand Down
16 changes: 8 additions & 8 deletions transport/internet/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 29 additions & 19 deletions transport/internet/splithttp/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions transport/internet/splithttp/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message Config {
RandRangeConfig maxConcurrentUploads = 4;
RandRangeConfig maxUploadSize = 5;
RandRangeConfig minUploadIntervalMs = 6;
bool noSSEHeader = 7;
}

message RandRangeConfig {
Expand Down
8 changes: 6 additions & 2 deletions transport/internet/splithttp/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

type requestHandler struct {
config *Config
host string
path string
ln *Listener
Expand Down Expand Up @@ -182,8 +183,10 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req

// magic header instructs nginx + apache to not buffer response body
writer.Header().Set("X-Accel-Buffering", "no")
// magic header to make the HTTP middle box consider this as SSE to disable buffer
writer.Header().Set("Content-Type", "text/event-stream")
if !h.config.NoSSEHeader {
// magic header to make the HTTP middle box consider this as SSE to disable buffer
writer.Header().Set("Content-Type", "text/event-stream")
}

writer.WriteHeader(http.StatusOK)
// send a chunk immediately to enable CDN streaming.
Expand Down Expand Up @@ -267,6 +270,7 @@ func ListenSH(ctx context.Context, address net.Address, port net.Port, streamSet
var err error
var localAddr = gonet.TCPAddr{}
handler := &requestHandler{
config: shSettings,
host: shSettings.Host,
path: shSettings.GetNormalizedPath("", false),
ln: l,
Expand Down

0 comments on commit 60553a6

Please sign in to comment.