Skip to content

fix(awc): some request methods incorrectly send body & body-headers#3705

Open
imgurbot12 wants to merge 3 commits into
actix:mainfrom
imgurbot12:fix/awc-req-body
Open

fix(awc): some request methods incorrectly send body & body-headers#3705
imgurbot12 wants to merge 3 commits into
actix:mainfrom
imgurbot12:fix/awc-req-body

Conversation

@imgurbot12

@imgurbot12 imgurbot12 commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

PR Type

Bug Fix

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

The existing implementation for awc incorrectly sends a request-body for http methods that don't support one, such as GET/HEAD/OPTIONS/TRACE. This is especially apparent when passing a stream into the request for all methods since it uses chunked content-encoding.

I discovered this whilst implementing a reverse-proxy using actix-web and awc.

Example:

GET / HTTP/1.1
transfer-encoding: chunked
accept-encoding: br, gzip, deflate, zstd
host: localhost:8000
date: Thu, 31 Jul 2025 03:51:41 GMT

0

You can verify this yourself with a simple script (I'm using netcat to view the request nc -lvp 8000):

use std::{
    pin::Pin,
    task::{Context, Poll},
};

use awc::{error::PayloadError, http::Method};
use bytes::Bytes;
use futures_core::Stream;

struct ReqStream;

impl Stream for ReqStream {
    type Item = Result<Bytes, PayloadError>;
    fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
        Poll::Ready(None)
    }
}

#[actix_rt::main]
async fn main() {
    let client = awc::Client::default();
    let res = client
        .request(Method::GET, "http://localhost:8000")
        .send_stream(ReqStream {})
        .await;
    println!("response: {res:?}");
}

The following changes ensure that the body and its associated headers are not included for the standard request methods, resulting in a correct request:

GET / HTTP/1.1
accept-encoding: br, gzip, deflate, zstd
host: localhost:8000
date: Thu, 31 Jul 2025 04:00:59 GMT

@JohnTitor JohnTitor added B-semver-major breaking change requiring a major version bump A-awc project: awc labels Oct 4, 2025
themavik

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-awc project: awc B-semver-major breaking change requiring a major version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants