mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
add client.py comments
This commit is contained in:
parent
2e790dfcc6
commit
009874125e
@ -1,7 +1,9 @@
|
|||||||
|
# This script could be used for actix-web multipart example test
|
||||||
|
# just start server and run client.py
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
||||||
async def req1():
|
async def req1():
|
||||||
with aiohttp.MultipartWriter() as writer:
|
with aiohttp.MultipartWriter() as writer:
|
||||||
writer.append('test')
|
writer.append('test')
|
||||||
|
@ -13,11 +13,10 @@ fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
|
|||||||
{
|
{
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
|
|
||||||
// get multipart stream and iterate over multipart items
|
|
||||||
Box::new(
|
Box::new(
|
||||||
req.multipart() // <- get multipart stream for current request
|
req.multipart() // <- get multipart stream for current request
|
||||||
.map_err(Error::from)
|
.map_err(Error::from) // <- convert multipart errors
|
||||||
.and_then(|item| { // <- iterate over multipart items
|
.and_then(|item| { // <- iterate over multipart items
|
||||||
match item {
|
match item {
|
||||||
// Handle multipart Field
|
// Handle multipart Field
|
||||||
multipart::MultipartItem::Field(field) => {
|
multipart::MultipartItem::Field(field) => {
|
||||||
@ -50,8 +49,7 @@ fn main() {
|
|||||||
|
|
||||||
HttpServer::new(
|
HttpServer::new(
|
||||||
|| Application::new()
|
|| Application::new()
|
||||||
// enable logger
|
.middleware(middlewares::Logger::default()) // <- logger
|
||||||
.middleware(middlewares::Logger::default())
|
|
||||||
.resource("/multipart", |r| r.method(Method::POST).a(index)))
|
.resource("/multipart", |r| r.method(Method::POST).a(index)))
|
||||||
.bind("127.0.0.1:8080").unwrap()
|
.bind("127.0.0.1:8080").unwrap()
|
||||||
.start();
|
.start();
|
||||||
|
Loading…
Reference in New Issue
Block a user