1 //! Simple HTTP implementation which supports both async and traditional execution environments
2 //! with minimal dependencies. This is used as the basis for REST and RPC clients.
7 use std::convert::TryFrom;
8 #[cfg(not(feature = "tokio"))]
10 use std::net::ToSocketAddrs;
11 use std::time::Duration;
13 #[cfg(feature = "tokio")]
14 use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt};
15 #[cfg(feature = "tokio")]
16 use tokio::net::TcpStream;
18 #[cfg(not(feature = "tokio"))]
21 #[cfg(not(feature = "tokio"))]
22 use std::net::TcpStream;
24 /// Timeout for operations on TCP streams.
25 const TCP_STREAM_TIMEOUT: Duration = Duration::from_secs(5);
27 /// Maximum HTTP message header size in bytes.
28 const MAX_HTTP_MESSAGE_HEADER_SIZE: usize = 8192;
30 /// Maximum HTTP message body size in bytes. Enough for a hex-encoded block in JSON format and any
31 /// overhead for HTTP chunked transfer encoding.
32 const MAX_HTTP_MESSAGE_BODY_SIZE: usize = 2 * 4_000_000 + 32_000;
34 /// Endpoint for interacting with an HTTP-based API.
36 pub struct HttpEndpoint {
43 /// Creates an endpoint for the given host and default HTTP port.
44 pub fn for_host(host: String) -> Self {
48 path: String::from("/"),
52 /// Specifies a port to use with the endpoint.
53 pub fn with_port(mut self, port: u16) -> Self {
54 self.port = Some(port);
58 /// Specifies a path to use with the endpoint.
59 pub fn with_path(mut self, path: String) -> Self {
64 /// Returns the endpoint host.
65 pub fn host(&self) -> &str {
69 /// Returns the endpoint port.
70 pub fn port(&self) -> u16 {
77 /// Returns the endpoint path.
78 pub fn path(&self) -> &str {
83 impl<'a> std::net::ToSocketAddrs for &'a HttpEndpoint {
84 type Iter = <(&'a str, u16) as std::net::ToSocketAddrs>::Iter;
86 fn to_socket_addrs(&self) -> std::io::Result<Self::Iter> {
87 (self.host(), self.port()).to_socket_addrs()
91 /// Client for making HTTP requests.
92 pub(crate) struct HttpClient {
97 /// Opens a connection to an HTTP endpoint.
98 pub fn connect<E: ToSocketAddrs>(endpoint: E) -> std::io::Result<Self> {
99 let address = match endpoint.to_socket_addrs()?.next() {
101 return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "could not resolve to any addresses"));
103 Some(address) => address,
105 let stream = std::net::TcpStream::connect_timeout(&address, TCP_STREAM_TIMEOUT)?;
106 stream.set_read_timeout(Some(TCP_STREAM_TIMEOUT))?;
107 stream.set_write_timeout(Some(TCP_STREAM_TIMEOUT))?;
109 #[cfg(feature = "tokio")]
111 stream.set_nonblocking(true)?;
112 TcpStream::from_std(stream)?
118 /// Sends a `GET` request for a resource identified by `uri` at the `host`.
120 /// Returns the response body in `F` format.
122 pub async fn get<F>(&mut self, uri: &str, host: &str) -> std::io::Result<F>
123 where F: TryFrom<Vec<u8>, Error = std::io::Error> {
124 let request = format!(
125 "GET {} HTTP/1.1\r\n\
127 Connection: keep-alive\r\n\
129 let response_body = self.send_request_with_retry(&request).await?;
130 F::try_from(response_body)
133 /// Sends a `POST` request for a resource identified by `uri` at the `host` using the given HTTP
134 /// authentication credentials.
136 /// The request body consists of the provided JSON `content`. Returns the response body in `F`
139 pub async fn post<F>(&mut self, uri: &str, host: &str, auth: &str, content: serde_json::Value) -> std::io::Result<F>
140 where F: TryFrom<Vec<u8>, Error = std::io::Error> {
141 let content = content.to_string();
142 let request = format!(
143 "POST {} HTTP/1.1\r\n\
145 Authorization: {}\r\n\
146 Connection: keep-alive\r\n\
147 Content-Type: application/json\r\n\
148 Content-Length: {}\r\n\
150 {}", uri, host, auth, content.len(), content);
151 let response_body = self.send_request_with_retry(&request).await?;
152 F::try_from(response_body)
155 /// Sends an HTTP request message and reads the response, returning its body. Attempts to
156 /// reconnect and retry if the connection has been closed.
157 async fn send_request_with_retry(&mut self, request: &str) -> std::io::Result<Vec<u8>> {
158 let endpoint = self.stream.peer_addr().unwrap();
159 match self.send_request(request).await {
160 Ok(bytes) => Ok(bytes),
161 Err(e) => match e.kind() {
162 std::io::ErrorKind::ConnectionReset |
163 std::io::ErrorKind::ConnectionAborted |
164 std::io::ErrorKind::UnexpectedEof => {
165 // Reconnect if the connection was closed. This may happen if the server's
166 // keep-alive limits are reached.
167 *self = Self::connect(endpoint)?;
168 self.send_request(request).await
175 /// Sends an HTTP request message and reads the response, returning its body.
176 async fn send_request(&mut self, request: &str) -> std::io::Result<Vec<u8>> {
177 self.write_request(request).await?;
178 self.read_response().await
181 /// Writes an HTTP request message.
182 async fn write_request(&mut self, request: &str) -> std::io::Result<()> {
183 #[cfg(feature = "tokio")]
185 self.stream.write_all(request.as_bytes()).await?;
186 self.stream.flush().await
188 #[cfg(not(feature = "tokio"))]
190 self.stream.write_all(request.as_bytes())?;
195 /// Reads an HTTP response message.
196 async fn read_response(&mut self) -> std::io::Result<Vec<u8>> {
197 #[cfg(feature = "tokio")]
198 let stream = self.stream.split().0;
199 #[cfg(not(feature = "tokio"))]
200 let stream = std::io::Read::by_ref(&mut self.stream);
202 let limited_stream = stream.take(MAX_HTTP_MESSAGE_HEADER_SIZE as u64);
204 #[cfg(feature = "tokio")]
205 let mut reader = tokio::io::BufReader::new(limited_stream);
206 #[cfg(not(feature = "tokio"))]
207 let mut reader = std::io::BufReader::new(limited_stream);
209 macro_rules! read_line { () => { {
210 let mut line = String::new();
211 #[cfg(feature = "tokio")]
212 let bytes_read = reader.read_line(&mut line).await?;
213 #[cfg(not(feature = "tokio"))]
214 let bytes_read = reader.read_line(&mut line)?;
219 // Remove trailing CRLF
220 if line.ends_with('\n') { line.pop(); if line.ends_with('\r') { line.pop(); } }
226 // Read and parse status line
227 let status_line = read_line!()
228 .ok_or(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "no status line"))?;
229 let status = HttpStatus::parse(&status_line)?;
231 // Read and parse relevant headers
232 let mut message_length = HttpMessageLength::Empty;
234 let line = read_line!()
235 .ok_or(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "no headers"))?;
236 if line.is_empty() { break; }
238 let header = HttpHeader::parse(&line)?;
239 if header.has_name("Content-Length") {
240 let length = header.value.parse()
241 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
242 if let HttpMessageLength::Empty = message_length {
243 message_length = HttpMessageLength::ContentLength(length);
248 if header.has_name("Transfer-Encoding") {
249 message_length = HttpMessageLength::TransferEncoding(header.value.into());
255 // TODO: Handle 3xx redirection responses.
256 return Err(std::io::Error::new(std::io::ErrorKind::NotFound, "not found"));
260 let read_limit = MAX_HTTP_MESSAGE_BODY_SIZE - reader.buffer().len();
261 reader.get_mut().set_limit(read_limit as u64);
262 match message_length {
263 HttpMessageLength::Empty => { Ok(Vec::new()) },
264 HttpMessageLength::ContentLength(length) => {
265 if length == 0 || length > MAX_HTTP_MESSAGE_BODY_SIZE {
266 Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "out of range"))
268 let mut content = vec![0; length];
269 #[cfg(feature = "tokio")]
270 reader.read_exact(&mut content[..]).await?;
271 #[cfg(not(feature = "tokio"))]
272 reader.read_exact(&mut content[..])?;
276 HttpMessageLength::TransferEncoding(coding) => {
277 if !coding.eq_ignore_ascii_case("chunked") {
278 Err(std::io::Error::new(
279 std::io::ErrorKind::InvalidInput, "unsupported transfer coding"))
281 let mut content = Vec::new();
282 #[cfg(feature = "tokio")]
284 // Since chunked_transfer doesn't have an async interface, only use it to
285 // determine the size of each chunk to read.
287 // TODO: Replace with an async interface when available.
288 // https://github.com/frewsxcv/rust-chunked-transfer/issues/7
290 // Read the chunk header which contains the chunk size.
291 let mut chunk_header = String::new();
292 reader.read_line(&mut chunk_header).await?;
293 if chunk_header == "0\r\n" {
294 // Read the terminator chunk since the decoder consumes the CRLF
295 // immediately when this chunk is encountered.
296 reader.read_line(&mut chunk_header).await?;
299 // Decode the chunk header to obtain the chunk size.
300 let mut buffer = Vec::new();
301 let mut decoder = chunked_transfer::Decoder::new(chunk_header.as_bytes());
302 decoder.read_to_end(&mut buffer)?;
304 // Read the chunk body.
305 let chunk_size = match decoder.remaining_chunks_size() {
307 Some(chunk_size) => chunk_size,
309 let chunk_offset = content.len();
310 content.resize(chunk_offset + chunk_size + "\r\n".len(), 0);
311 reader.read_exact(&mut content[chunk_offset..]).await?;
312 content.resize(chunk_offset + chunk_size, 0);
316 #[cfg(not(feature = "tokio"))]
318 let mut decoder = chunked_transfer::Decoder::new(reader);
319 decoder.read_to_end(&mut content)?;
328 /// HTTP response status code as defined by [RFC 7231].
330 /// [RFC 7231]: https://tools.ietf.org/html/rfc7231#section-6
331 struct HttpStatus<'a> {
335 impl<'a> HttpStatus<'a> {
336 /// Parses an HTTP status line as defined by [RFC 7230].
338 /// [RFC 7230]: https://tools.ietf.org/html/rfc7230#section-3.1.2
339 fn parse(line: &'a String) -> std::io::Result<HttpStatus<'a>> {
340 let mut tokens = line.splitn(3, ' ');
342 let http_version = tokens.next()
343 .ok_or(std::io::Error::new(std::io::ErrorKind::InvalidData, "no HTTP-Version"))?;
344 if !http_version.eq_ignore_ascii_case("HTTP/1.1") &&
345 !http_version.eq_ignore_ascii_case("HTTP/1.0") {
346 return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid HTTP-Version"));
349 let code = tokens.next()
350 .ok_or(std::io::Error::new(std::io::ErrorKind::InvalidData, "no Status-Code"))?;
351 if code.len() != 3 || !code.chars().all(|c| c.is_ascii_digit()) {
352 return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid Status-Code"));
355 let _reason = tokens.next()
356 .ok_or(std::io::Error::new(std::io::ErrorKind::InvalidData, "no Reason-Phrase"))?;
361 /// Returns whether the status is successful (i.e., 2xx status class).
362 fn is_ok(&self) -> bool {
363 self.code.starts_with('2')
367 /// HTTP response header as defined by [RFC 7231].
369 /// [RFC 7231]: https://tools.ietf.org/html/rfc7231#section-7
370 struct HttpHeader<'a> {
375 impl<'a> HttpHeader<'a> {
376 /// Parses an HTTP header field as defined by [RFC 7230].
378 /// [RFC 7230]: https://tools.ietf.org/html/rfc7230#section-3.2
379 fn parse(line: &'a String) -> std::io::Result<HttpHeader<'a>> {
380 let mut tokens = line.splitn(2, ':');
381 let name = tokens.next()
382 .ok_or(std::io::Error::new(std::io::ErrorKind::InvalidData, "no header name"))?;
383 let value = tokens.next()
384 .ok_or(std::io::Error::new(std::io::ErrorKind::InvalidData, "no header value"))?
386 Ok(Self { name, value })
389 /// Returns whether the header field has the given name.
390 fn has_name(&self, name: &str) -> bool {
391 self.name.eq_ignore_ascii_case(name)
395 /// HTTP message body length as defined by [RFC 7230].
397 /// [RFC 7230]: https://tools.ietf.org/html/rfc7230#section-3.3.3
398 enum HttpMessageLength {
400 ContentLength(usize),
401 TransferEncoding(String),
404 /// An HTTP response body in binary format.
405 pub struct BinaryResponse(pub Vec<u8>);
407 /// An HTTP response body in JSON format.
408 pub struct JsonResponse(pub serde_json::Value);
410 /// Interprets bytes from an HTTP response body as binary data.
411 impl TryFrom<Vec<u8>> for BinaryResponse {
412 type Error = std::io::Error;
414 fn try_from(bytes: Vec<u8>) -> std::io::Result<Self> {
415 Ok(BinaryResponse(bytes))
419 /// Interprets bytes from an HTTP response body as a JSON value.
420 impl TryFrom<Vec<u8>> for JsonResponse {
421 type Error = std::io::Error;
423 fn try_from(bytes: Vec<u8>) -> std::io::Result<Self> {
424 Ok(JsonResponse(serde_json::from_slice(&bytes)?))
430 use super::HttpEndpoint;
433 fn with_default_port() {
434 let endpoint = HttpEndpoint::for_host("foo.com".into());
435 assert_eq!(endpoint.host(), "foo.com");
436 assert_eq!(endpoint.port(), 80);
440 fn with_custom_port() {
441 let endpoint = HttpEndpoint::for_host("foo.com".into()).with_port(8080);
442 assert_eq!(endpoint.host(), "foo.com");
443 assert_eq!(endpoint.port(), 8080);
448 let endpoint = HttpEndpoint::for_host("foo.com".into()).with_path("/path".into());
449 assert_eq!(endpoint.host(), "foo.com");
450 assert_eq!(endpoint.path(), "/path");
454 fn without_uri_path() {
455 let endpoint = HttpEndpoint::for_host("foo.com".into());
456 assert_eq!(endpoint.host(), "foo.com");
457 assert_eq!(endpoint.path(), "/");
461 fn convert_to_socket_addrs() {
462 let endpoint = HttpEndpoint::for_host("foo.com".into());
463 let host = endpoint.host();
464 let port = endpoint.port();
466 use std::net::ToSocketAddrs;
467 match (&endpoint).to_socket_addrs() {
468 Err(e) => panic!("Unexpected error: {:?}", e),
469 Ok(mut socket_addrs) => {
470 match socket_addrs.next() {
471 None => panic!("Expected socket address"),
473 assert_eq!(addr, (host, port).to_socket_addrs().unwrap().next().unwrap());
474 assert!(socket_addrs.next().is_none());
483 pub(crate) mod client_tests {
485 use std::io::BufRead;
488 /// Server for handling HTTP client requests with a stock response.
489 pub struct HttpServer {
490 address: std::net::SocketAddr,
491 handler: std::thread::JoinHandle<()>,
492 shutdown: std::sync::Arc<std::sync::atomic::AtomicBool>,
495 /// Body of HTTP response messages.
496 pub enum MessageBody<T: ToString> {
503 pub fn responding_with_ok<T: ToString>(body: MessageBody<T>) -> Self {
504 let response = match body {
505 MessageBody::Empty => "HTTP/1.1 200 OK\r\n\r\n".to_string(),
506 MessageBody::Content(body) => {
507 let body = body.to_string();
509 "HTTP/1.1 200 OK\r\n\
510 Content-Length: {}\r\n\
512 {}", body.len(), body)
514 MessageBody::ChunkedContent(body) => {
515 let mut chuncked_body = Vec::new();
517 use chunked_transfer::Encoder;
518 let mut encoder = Encoder::with_chunks_size(&mut chuncked_body, 8);
519 encoder.write_all(body.to_string().as_bytes()).unwrap();
522 "HTTP/1.1 200 OK\r\n\
523 Transfer-Encoding: chunked\r\n\
525 {}", String::from_utf8(chuncked_body).unwrap())
528 HttpServer::responding_with(response)
531 pub fn responding_with_not_found() -> Self {
532 let response = "HTTP/1.1 404 Not Found\r\n\r\n".to_string();
533 HttpServer::responding_with(response)
536 fn responding_with(response: String) -> Self {
537 let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
538 let address = listener.local_addr().unwrap();
540 let shutdown = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
541 let shutdown_signaled = std::sync::Arc::clone(&shutdown);
542 let handler = std::thread::spawn(move || {
543 for stream in listener.incoming() {
544 let mut stream = stream.unwrap();
545 stream.set_write_timeout(Some(TCP_STREAM_TIMEOUT)).unwrap();
547 let lines_read = std::io::BufReader::new(&stream)
549 .take_while(|line| !line.as_ref().unwrap().is_empty())
551 if lines_read == 0 { continue; }
553 for chunk in response.as_bytes().chunks(16) {
554 if shutdown_signaled.load(std::sync::atomic::Ordering::SeqCst) {
557 if let Err(_) = stream.write(chunk) { break; }
558 if let Err(_) = stream.flush() { break; }
564 Self { address, handler, shutdown }
568 self.shutdown.store(true, std::sync::atomic::Ordering::SeqCst);
569 self.handler.join().unwrap();
572 pub fn endpoint(&self) -> HttpEndpoint {
573 HttpEndpoint::for_host(self.address.ip().to_string()).with_port(self.address.port())
578 fn connect_to_unresolvable_host() {
579 match HttpClient::connect(("example.invalid", 80)) {
580 Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::Other),
581 Ok(_) => panic!("Expected error"),
586 fn connect_with_no_socket_address() {
587 match HttpClient::connect(&vec![][..]) {
588 Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::InvalidInput),
589 Ok(_) => panic!("Expected error"),
594 fn connect_with_unknown_server() {
595 match HttpClient::connect(("::", 80)) {
596 #[cfg(target_os = "windows")]
597 Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::AddrNotAvailable),
598 #[cfg(not(target_os = "windows"))]
599 Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::ConnectionRefused),
600 Ok(_) => panic!("Expected error"),
605 async fn connect_with_valid_endpoint() {
606 let server = HttpServer::responding_with_ok::<String>(MessageBody::Empty);
608 match HttpClient::connect(&server.endpoint()) {
609 Err(e) => panic!("Unexpected error: {:?}", e),
615 async fn read_empty_message() {
616 let server = HttpServer::responding_with("".to_string());
618 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
619 match client.get::<BinaryResponse>("/foo", "foo.com").await {
621 assert_eq!(e.kind(), std::io::ErrorKind::UnexpectedEof);
622 assert_eq!(e.get_ref().unwrap().to_string(), "no status line");
624 Ok(_) => panic!("Expected error"),
629 async fn read_incomplete_message() {
630 let server = HttpServer::responding_with("HTTP/1.1 200 OK".to_string());
632 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
633 match client.get::<BinaryResponse>("/foo", "foo.com").await {
635 assert_eq!(e.kind(), std::io::ErrorKind::UnexpectedEof);
636 assert_eq!(e.get_ref().unwrap().to_string(), "no headers");
638 Ok(_) => panic!("Expected error"),
643 async fn read_too_large_message_headers() {
644 let response = format!(
645 "HTTP/1.1 302 Found\r\n\
647 \r\n", "Z".repeat(MAX_HTTP_MESSAGE_HEADER_SIZE));
648 let server = HttpServer::responding_with(response);
650 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
651 match client.get::<BinaryResponse>("/foo", "foo.com").await {
653 assert_eq!(e.kind(), std::io::ErrorKind::UnexpectedEof);
654 assert_eq!(e.get_ref().unwrap().to_string(), "no headers");
656 Ok(_) => panic!("Expected error"),
661 async fn read_too_large_message_body() {
662 let body = "Z".repeat(MAX_HTTP_MESSAGE_BODY_SIZE + 1);
663 let server = HttpServer::responding_with_ok::<String>(MessageBody::Content(body));
665 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
666 match client.get::<BinaryResponse>("/foo", "foo.com").await {
668 assert_eq!(e.kind(), std::io::ErrorKind::InvalidData);
669 assert_eq!(e.get_ref().unwrap().to_string(), "out of range");
671 Ok(_) => panic!("Expected error"),
677 async fn read_message_with_unsupported_transfer_coding() {
678 let response = String::from(
679 "HTTP/1.1 200 OK\r\n\
680 Transfer-Encoding: gzip\r\n\
683 let server = HttpServer::responding_with(response);
685 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
686 match client.get::<BinaryResponse>("/foo", "foo.com").await {
688 assert_eq!(e.kind(), std::io::ErrorKind::InvalidInput);
689 assert_eq!(e.get_ref().unwrap().to_string(), "unsupported transfer coding");
691 Ok(_) => panic!("Expected error"),
696 async fn read_empty_message_body() {
697 let server = HttpServer::responding_with_ok::<String>(MessageBody::Empty);
699 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
700 match client.get::<BinaryResponse>("/foo", "foo.com").await {
701 Err(e) => panic!("Unexpected error: {:?}", e),
702 Ok(bytes) => assert_eq!(bytes.0, Vec::<u8>::new()),
707 async fn read_message_body_with_length() {
708 let body = "foo bar baz qux".repeat(32);
709 let content = MessageBody::Content(body.clone());
710 let server = HttpServer::responding_with_ok::<String>(content);
712 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
713 match client.get::<BinaryResponse>("/foo", "foo.com").await {
714 Err(e) => panic!("Unexpected error: {:?}", e),
715 Ok(bytes) => assert_eq!(bytes.0, body.as_bytes()),
720 async fn read_chunked_message_body() {
721 let body = "foo bar baz qux".repeat(32);
722 let chunked_content = MessageBody::ChunkedContent(body.clone());
723 let server = HttpServer::responding_with_ok::<String>(chunked_content);
725 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
726 match client.get::<BinaryResponse>("/foo", "foo.com").await {
727 Err(e) => panic!("Unexpected error: {:?}", e),
728 Ok(bytes) => assert_eq!(bytes.0, body.as_bytes()),
733 async fn reconnect_closed_connection() {
734 let server = HttpServer::responding_with_ok::<String>(MessageBody::Empty);
736 let mut client = HttpClient::connect(&server.endpoint()).unwrap();
737 assert!(client.get::<BinaryResponse>("/foo", "foo.com").await.is_ok());
738 match client.get::<BinaryResponse>("/foo", "foo.com").await {
739 Err(e) => panic!("Unexpected error: {:?}", e),
740 Ok(bytes) => assert_eq!(bytes.0, Vec::<u8>::new()),
745 fn from_bytes_into_binary_response() {
747 match BinaryResponse::try_from(bytes.to_vec()) {
748 Err(e) => panic!("Unexpected error: {:?}", e),
749 Ok(response) => assert_eq!(&response.0, bytes),
754 fn from_invalid_bytes_into_json_response() {
755 let json = serde_json::json!({ "result": 42 });
756 match JsonResponse::try_from(json.to_string().as_bytes()[..5].to_vec()) {
758 Ok(_) => panic!("Expected error"),
763 fn from_valid_bytes_into_json_response() {
764 let json = serde_json::json!({ "result": 42 });
765 match JsonResponse::try_from(json.to_string().as_bytes().to_vec()) {
766 Err(e) => panic!("Unexpected error: {:?}", e),
767 Ok(response) => assert_eq!(response.0, json),