mirror of https://github.com/fafhrd91/actix-web
Compare commits
8 Commits
09fe594fcb
...
ee80f0d11e
| Author | SHA1 | Date |
|---|---|---|
|
|
ee80f0d11e | |
|
|
d119500f93 | |
|
|
a3f95ee1ef | |
|
|
9ea97a676a | |
|
|
5037f9acd7 | |
|
|
1c8c860e7d | |
|
|
a992de888e | |
|
|
539e86a544 |
|
|
@ -345,7 +345,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "4.11.0"
|
version = "4.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-files",
|
"actix-files",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 3.11.3
|
||||||
|
|
||||||
|
- Update `HttpMessage`s `content_type` method to return `Option<&str>` instead of `&str`.
|
||||||
|
|
||||||
## 3.11.2
|
## 3.11.2
|
||||||
|
|
||||||
- Properly wake Payload receivers when feeding errors or EOF.
|
- Properly wake Payload receivers when feeding errors or EOF.
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,11 @@ pub trait HttpMessage: Sized {
|
||||||
|
|
||||||
/// Read the request content type. If request did not contain a *Content-Type* header, an empty
|
/// Read the request content type. If request did not contain a *Content-Type* header, an empty
|
||||||
/// string is returned.
|
/// string is returned.
|
||||||
fn content_type(&self) -> &str {
|
fn content_type(&self) -> Option<&str> {
|
||||||
if let Some(content_type) = self.headers().get(header::CONTENT_TYPE) {
|
self.headers()
|
||||||
if let Ok(content_type) = content_type.to_str() {
|
.get(header::CONTENT_TYPE)
|
||||||
return content_type.split(';').next().unwrap().trim();
|
.and_then(|ct| ct.to_str().ok())
|
||||||
}
|
.map(|ct| ct.split(';').next().unwrap().trim())
|
||||||
}
|
|
||||||
""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get content type encoding.
|
/// Get content type encoding.
|
||||||
|
|
@ -142,13 +140,13 @@ mod tests {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header(("content-type", "text/plain"))
|
.insert_header(("content-type", "text/plain"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(req.content_type(), "text/plain");
|
assert_eq!(req.content_type(), Some("text/plain"));
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header(("content-type", "application/json; charset=utf-8"))
|
.insert_header(("content-type", "application/json; charset=utf-8"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(req.content_type(), "application/json");
|
assert_eq!(req.content_type(), Some("application/json"));
|
||||||
let req = TestRequest::default().finish();
|
let req = TestRequest::default().finish();
|
||||||
assert_eq!(req.content_type(), "");
|
assert_eq!(req.content_type(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 4.12.0
|
||||||
|
|
||||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now sets `Content-Type` to `application/octet-stream` if `Content-Type` does not exist.
|
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now sets `Content-Type` to `application/octet-stream` if `Content-Type` does not exist.
|
||||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now calls `actix_web::response::builder::HttpResponseBuilder::no_chunking()` if `Content-Length` is set by user.
|
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now calls `actix_web::response::builder::HttpResponseBuilder::no_chunking()` and returns `SizedStream` if `Content-Length` is set by user.
|
||||||
- Add `ws` crate feature (on-by-default) which forwards to `actix-http` and guards some of its `ResponseError` impls.
|
- Add `ws` crate feature (on-by-default) which forwards to `actix-http` and guards some of its `ResponseError` impls.
|
||||||
- Add public export for `EitherExtractError` in `error` module.
|
- Add public export for `EitherExtractError` in `error` module.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "4.11.0"
|
version = "4.12.0"
|
||||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||||
keywords = ["actix", "http", "web", "framework", "async"]
|
keywords = ["actix", "http", "web", "framework", "async"]
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web)
|
[](https://crates.io/crates/actix-web)
|
||||||
[](https://docs.rs/actix-web/4.11.0)
|
[](https://docs.rs/actix-web/4.12.0)
|
||||||

|

|
||||||

|

|
||||||
[](https://deps.rs/crate/actix-web/4.11.0)
|
[](https://deps.rs/crate/actix-web/4.12.0)
|
||||||
<br />
|
<br />
|
||||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||||
[](https://codecov.io/gh/actix/actix-web)
|
[](https://codecov.io/gh/actix/actix-web)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use futures_core::Stream;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{BodyStream, BoxBody, MessageBody},
|
body::{BodyStream, BoxBody, MessageBody, SizedStream},
|
||||||
dev::Extensions,
|
dev::Extensions,
|
||||||
error::{Error, JsonPayloadError},
|
error::{Error, JsonPayloadError},
|
||||||
http::{
|
http::{
|
||||||
|
|
@ -335,17 +335,18 @@ impl HttpResponseBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(parts) = self.inner() {
|
let content_length = self
|
||||||
if let Some(length) = parts.headers.get(header::CONTENT_LENGTH) {
|
.inner()
|
||||||
if let Ok(length) = length.to_str() {
|
.and_then(|parts| parts.headers.get(header::CONTENT_LENGTH))
|
||||||
if let Ok(length) = length.parse::<u64>() {
|
.and_then(|value| value.to_str().ok())
|
||||||
self.no_chunking(length);
|
.and_then(|value| value.parse::<u64>().ok());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.body(BodyStream::new(stream))
|
if let Some(len) = content_length {
|
||||||
|
self.no_chunking(len);
|
||||||
|
self.body(SizedStream::new(len, stream))
|
||||||
|
} else {
|
||||||
|
self.body(BodyStream::new(stream))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a JSON body and build the `HttpResponse`.
|
/// Set a JSON body and build the `HttpResponse`.
|
||||||
|
|
|
||||||
|
|
@ -505,7 +505,10 @@ mod tests {
|
||||||
.set_form(&payload)
|
.set_form(&payload)
|
||||||
.to_request();
|
.to_request();
|
||||||
|
|
||||||
assert_eq!(req.content_type(), "application/x-www-form-urlencoded");
|
assert_eq!(
|
||||||
|
req.content_type().unwrap(),
|
||||||
|
"application/x-www-form-urlencoded"
|
||||||
|
);
|
||||||
|
|
||||||
let result: Person = call_and_read_body_json(&app, req).await;
|
let result: Person = call_and_read_body_json(&app, req).await;
|
||||||
assert_eq!(&result.id, "12345");
|
assert_eq!(&result.id, "12345");
|
||||||
|
|
@ -549,7 +552,7 @@ mod tests {
|
||||||
.set_json(&payload)
|
.set_json(&payload)
|
||||||
.to_request();
|
.to_request();
|
||||||
|
|
||||||
assert_eq!(req.content_type(), "application/json");
|
assert_eq!(req.content_type(), Some("application/json"));
|
||||||
|
|
||||||
let result: Person = call_and_read_body_json(&app, req).await;
|
let result: Person = call_and_read_body_json(&app, req).await;
|
||||||
assert_eq!(&result.id, "12345");
|
assert_eq!(&result.id, "12345");
|
||||||
|
|
|
||||||
|
|
@ -289,14 +289,17 @@ impl<T> UrlEncoded<T> {
|
||||||
/// Create a new future to decode a URL encoded request payload.
|
/// Create a new future to decode a URL encoded request payload.
|
||||||
pub fn new(req: &HttpRequest, payload: &mut Payload) -> Self {
|
pub fn new(req: &HttpRequest, payload: &mut Payload) -> Self {
|
||||||
// check content type
|
// check content type
|
||||||
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {
|
let encoding_error = req
|
||||||
|
.content_type()
|
||||||
|
.map(|ct| !ct.eq_ignore_ascii_case("application/x-www-form-urlencoded"))
|
||||||
|
.unwrap_or(true);
|
||||||
|
if encoding_error {
|
||||||
return Self::err(UrlencodedError::ContentType);
|
return Self::err(UrlencodedError::ContentType);
|
||||||
}
|
}
|
||||||
let encoding = match req.encoding() {
|
let encoding = match req.encoding() {
|
||||||
Ok(enc) => enc,
|
Ok(enc) => enc,
|
||||||
Err(_) => return Self::err(UrlencodedError::ContentType),
|
Err(_) => return Self::err(UrlencodedError::ContentType),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut len = None;
|
let mut len = None;
|
||||||
if let Some(l) = req.headers().get(&CONTENT_LENGTH) {
|
if let Some(l) = req.headers().get(&CONTENT_LENGTH) {
|
||||||
if let Ok(s) = l.to_str() {
|
if let Ok(s) = l.to_str() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue