You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is a bug or meant to be like this. I ran into this and it took me some time to figure out what I was doing wrong.
I'm using
base.on(.POST, "myupload", body: .stream) { req -> EventLoopFuture<HTTPResponseStatus> in
let requestPromise = req.eventLoop.makePromise(of: HTTPResponseStatus.self)
// [ ... handle body stream and complete requestPromise at the end ... ]
return requestPromise.futureResult
}
to handle a streaming request with a reasonably large image file (e.g. 1 MB). This works fine.
BUT: When I change my code to validate some headers beforehand, it will stall and the client request will not get a response when the header is missing.
base.on(.POST, "myupload", body: .stream) { req -> EventLoopFuture<HTTPResponseStatus> in
guard nil != req.headers["MyHeader"].first else {
return req.eventLoop.makeSucceededFuture(.badRequest)
}
let requestPromise = req.eventLoop.makePromise(of: HTTPResponseStatus.self)
// [ ... handle body stream and complete requestPromise at the end ... ]
return requestPromise.futureResult
}
When I add some simple code to collect the body stream, it works again:
base.on(.POST, "myupload", body: .stream) { req -> EventLoopFuture<HTTPResponseStatus> in
guard nil != req.headers["MyHeader"].first else {
_ = req.body.collect(max: 10)
return req.eventLoop.makeSucceededFuture(.badRequest)
}
let requestPromise = req.eventLoop.makePromise(of: HTTPResponseStatus.self)
// [ ... handle body stream and complete requestPromise at the end ... ]
return requestPromise.futureResult
}
Steps to reproduce
Setup a POST route with a streaming body and invoke it with httpie (http://httpie.org) from the command line to upload an image to this route:
http POST "http://localhost:8080/myupload" MyHeader:123 <yourImage.jpeg
This works.
http POST "http://localhost:8080/myupload" NotMyHeader:123 <yourImage.jpeg
This stalls in 4 out of 5 times and will eventually time out.
Expected behavior
Will not time event when the body stream is not collected / drained.
Actual behavior
It stalls in 4 out of 5 times.
Environment
Vapor Framework version: 4.5.0
Vapor Toolbox version: 3.1.0
OS version: macOS 10.15.4
The text was updated successfully, but these errors were encountered:
I'm not sure if this is a bug or meant to be like this. I ran into this and it took me some time to figure out what I was doing wrong.
I'm using
to handle a streaming request with a reasonably large image file (e.g. 1 MB). This works fine.
BUT: When I change my code to validate some headers beforehand, it will stall and the client request will not get a response when the header is missing.
When I add some simple code to collect the body stream, it works again:
Steps to reproduce
Setup a POST route with a streaming body and invoke it with httpie (http://httpie.org) from the command line to upload an image to this route:
This works.
This stalls in 4 out of 5 times and will eventually time out.
Expected behavior
Will not time event when the body stream is not collected / drained.
Actual behavior
It stalls in 4 out of 5 times.
Environment
The text was updated successfully, but these errors were encountered: