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
Copy file name to clipboardExpand all lines: README.md
+1-21Lines changed: 1 addition & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,26 +99,6 @@ let httpbin_address =
99
99
100
100
If the incoming response's body fits entirely in the client's buffer Shuttle_http will represent the body as a fixed sized string, otherwise the body is read as an asynchronous stream so the response can be processed without having to wait for the entire body to arrive over the write.
101
101
102
-
We'll write a utility function that will convert a streaming response body to a string:
103
-
104
-
```ocaml
105
-
let response_body_to_string response =
106
-
let stream_to_string stream =
107
-
let buffer = Buffer.create 128 in
108
-
let%map () =
109
-
Body.Stream.iter stream ~f:(fun chunk ->
110
-
Buffer.add_string buffer chunk;
111
-
Deferred.unit)
112
-
in
113
-
Buffer.contents buffer
114
-
in
115
-
match Response.body response with
116
-
| Body.Empty -> return ""
117
-
| Body.Fixed str -> return str
118
-
| Body.Stream stream -> stream_to_string stream
119
-
;;
120
-
```
121
-
122
102
Shuttle_http offers a few different flavors of HTTP clients. The first one we'll see is a OneShot client. OneShot clients open a new TCP
123
103
connection, send a HTTP Request, wait to receive a Response and then shut-down the TCP connection once the entire response has been consumed.
0 commit comments