Skip to content

Commit 79eef64

Browse files
committed
update
1 parent 8d81bad commit 79eef64

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/types/response.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,24 @@ impl Responder for StreamingResponse {
112112

113113
apply_hashmap_headers(&mut response_builder, &self.headers);
114114

115-
// Only add SSE-specific headers for event-stream responses
115+
// Only add SSE-specific headers for event-stream responses if not already present
116116
if self.media_type == "text/event-stream" {
117-
response_builder
118-
.append_header(("Connection", "keep-alive"))
119-
.append_header(("X-Accel-Buffering", "no")) // Disable nginx buffering
120-
.append_header(("Cache-Control", "no-cache, no-store, must-revalidate"))
121-
.append_header(("Pragma", "no-cache"))
122-
.append_header(("Expires", "0"));
117+
if !self.headers.contains("Connection".to_string()) {
118+
response_builder.append_header(("Connection", "keep-alive"));
119+
}
120+
if !self.headers.contains("X-Accel-Buffering".to_string()) {
121+
response_builder.append_header(("X-Accel-Buffering", "no")); // Disable nginx buffering
122+
}
123+
if !self.headers.contains("Cache-Control".to_string()) {
124+
response_builder
125+
.append_header(("Cache-Control", "no-cache, no-store, must-revalidate"));
126+
}
127+
if !self.headers.contains("Pragma".to_string()) {
128+
response_builder.append_header(("Pragma", "no-cache"));
129+
}
130+
if !self.headers.contains("Expires".to_string()) {
131+
response_builder.append_header(("Expires", "0"));
132+
}
123133
}
124134

125135
// Create the optimized stream from the Python generator

0 commit comments

Comments
 (0)