Skip to content

Commit 862f5bf

Browse files
committed
fix: handle 204 response status code
1 parent 4e365b3 commit 862f5bf

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/1.1/coroutines/send.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl SendHttp {
195195
}
196196
};
197197

198-
trace!("resume after sending HTTP response");
198+
trace!("resume after sending HTTP request");
199199

200200
self.state = State::ReceiveHeaders {
201201
read: ReadStream::default(),
@@ -208,7 +208,7 @@ impl SendHttp {
208208
ReadStreamResult::Err(err) => return SendHttpResult::Err(err.into()),
209209
ReadStreamResult::Io(io) => return SendHttpResult::Io(io),
210210
ReadStreamResult::Eof => {
211-
return SendHttpResult::Err(SendHttpError::UnexpectedEof)
211+
return SendHttpResult::Err(SendHttpError::UnexpectedEof);
212212
}
213213
};
214214

@@ -237,6 +237,7 @@ impl SendHttp {
237237
}
238238

239239
let mut response = Response::builder();
240+
let mut no_content = false;
240241

241242
match parsed.version {
242243
Some(0) => {
@@ -250,6 +251,7 @@ impl SendHttp {
250251
}
251252

252253
if let Some(code) = parsed.code {
254+
no_content = code == 204;
253255
response = response.status(code);
254256
}
255257

@@ -273,6 +275,14 @@ impl SendHttp {
273275
self.is_conn_closed = self.is_http_10;
274276
}
275277

278+
if no_content {
279+
break SendHttpResult::Ok(SendHttpOk {
280+
request: mem::take(&mut self.request),
281+
response: response.body(vec![]).unwrap(),
282+
keep_alive: !self.is_http_10,
283+
});
284+
}
285+
276286
if let Some(encoding) = headers.get(TRANSFER_ENCODING) {
277287
if encoding == "chunked" {
278288
let mut read = ReadStream::with_capacity(output.buffer.capacity());

0 commit comments

Comments
 (0)