Put the crate version in the User-Agent header. (#138)

* Put the crate version in the User-Agent header.

https://tools.ietf.org/html/rfc7231#section-5.5.3
Each product identifier consists of a name and optional version.

     product         = token ["/" product-version]
     product-version = token

* User-Agent of rust-ureq

* Update src/unit.rs

Co-authored-by: Martin Algesten <martin@algesten.se>
This commit is contained in:
Jacob Hoffman-Andrews
2020-09-13 05:13:54 -07:00
committed by GitHub
parent 99cdff7519
commit 5cb212f7b7

View File

@@ -369,7 +369,7 @@ fn send_prelude(unit: &Unit, stream: &mut Stream, redir: bool) -> IoResult<()> {
} }
} }
if !header::has_header(&unit.headers, "user-agent") { if !header::has_header(&unit.headers, "user-agent") {
write!(prelude, "User-Agent: ureq\r\n")?; write!(prelude, "User-Agent: ureq/{}\r\n", env!("CARGO_PKG_VERSION"))?;
} }
if !header::has_header(&unit.headers, "accept") { if !header::has_header(&unit.headers, "accept") {
write!(prelude, "Accept: */*\r\n")?; write!(prelude, "Accept: */*\r\n")?;