Ensure correct ordering on stream operations (#176)
This commit is contained in:
parent
1da43a09c4
commit
c075df65d7
@ -42,9 +42,10 @@ instance bodyString :: Body String where
|
||||
Aff.makeAff \done -> do
|
||||
let
|
||||
stream = HTTP.responseAsStream response
|
||||
_ <- Stream.writeString stream Encoding.UTF8 body $ pure unit
|
||||
_ <- Stream.end stream $ pure unit
|
||||
done $ Either.Right unit
|
||||
void $ Stream.writeString stream Encoding.UTF8 body
|
||||
$ Stream.end stream
|
||||
$ done
|
||||
$ Either.Right unit
|
||||
pure Aff.nonCanceler
|
||||
|
||||
-- | The instance for `Buffer` is trivial--we add a `Content-Length` header
|
||||
@ -56,9 +57,10 @@ instance bodyBuffer :: Body Buffer.Buffer where
|
||||
Aff.makeAff \done -> do
|
||||
let
|
||||
stream = HTTP.responseAsStream response
|
||||
_ <- Stream.write stream body $ pure unit
|
||||
_ <- Stream.end stream $ pure unit
|
||||
done $ Either.Right unit
|
||||
void $ Stream.write stream body
|
||||
$ Stream.end stream
|
||||
$ done
|
||||
$ Either.Right unit
|
||||
pure Aff.nonCanceler
|
||||
|
||||
-- | This instance can be used to send chunked data. Here, we add a
|
||||
@ -72,7 +74,7 @@ instance bodyChunked ::
|
||||
Aff.makeAff \done -> do
|
||||
let
|
||||
stream = TypeEquals.to body
|
||||
_ <- Stream.pipe stream $ HTTP.responseAsStream response
|
||||
void $ Stream.pipe stream $ HTTP.responseAsStream response
|
||||
Stream.onEnd stream $ done $ Either.Right unit
|
||||
pure Aff.nonCanceler
|
||||
|
||||
|
@ -45,9 +45,11 @@ sendSpec =
|
||||
\response ->
|
||||
Aff.makeAff \done -> do
|
||||
stream <- pure $ HTTP.responseAsStream response
|
||||
_ <- Stream.writeString stream Encoding.UTF8 "test" $ pure unit
|
||||
_ <- Stream.end stream $ pure unit
|
||||
done $ Either.Right unit
|
||||
void
|
||||
$ Stream.writeString stream Encoding.UTF8 "test"
|
||||
$ Stream.end stream
|
||||
$ done
|
||||
$ Either.Right unit
|
||||
pure Aff.nonCanceler
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,19 @@ exports.mockResponse = function() {
|
||||
body: "",
|
||||
headers: {},
|
||||
|
||||
write: function(str) {
|
||||
write: function(str, encoding, callback) {
|
||||
this.body = this.body + str;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
|
||||
end: function(str, encoding, callback) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
|
||||
end: function() { },
|
||||
on: function() { },
|
||||
once: function() { },
|
||||
emit: function() { },
|
||||
|
@ -47,8 +47,10 @@ request secure port method headers path body =
|
||||
req <- HTTPClient.request options $ Either.Right >>> done
|
||||
let
|
||||
stream = HTTPClient.requestAsStream req
|
||||
_ <- Stream.writeString stream Encoding.UTF8 body $ pure unit
|
||||
Stream.end stream $ pure unit
|
||||
void
|
||||
$ Stream.writeString stream Encoding.UTF8 body
|
||||
$ Stream.end stream
|
||||
$ pure unit
|
||||
pure Aff.nonCanceler
|
||||
where
|
||||
options =
|
||||
|
Loading…
Reference in New Issue
Block a user