Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/per-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on: # rebuild any PRs and main branch changes
branches:
- master


permissions:
contents: read
actions: write
Expand Down
5 changes: 4 additions & 1 deletion crates/client/src/callback_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use anyhow::anyhow;
use bytes::{BufMut, BytesMut};
use futures_util::{future::BoxFuture, stream};
use http::{HeaderMap, Request, Response};
use http::{HeaderMap, HeaderValue, Request, Response};
use http_body_util::{BodyExt, StreamBody, combinators::BoxBody};
use hyper::body::{Bytes, Frame};
use std::{
Expand Down Expand Up @@ -104,9 +104,12 @@ impl Service<Request<tonic::body::Body>> for CallbackBasedGrpcService {
let mut body_prepend = BytesMut::with_capacity(5);
body_prepend.put_u8(0); // 0 means no compression
body_prepend.put_u32(success.proto.len() as u32);
let mut trailers = HeaderMap::new();
trailers.insert("grpc-status", HeaderValue::from_static("0"));
let stream = stream::iter(vec![
Ok::<_, Status>(Frame::data(Bytes::from(body_prepend))),
Ok::<_, Status>(Frame::data(Bytes::from(success.proto))),
Ok::<_, Status>(Frame::trailers(trailers)),
]);
let stream_body = StreamBody::new(stream);
let full_body = BoxBody::new(stream_body).boxed();
Expand Down
18 changes: 13 additions & 5 deletions crates/sdk-core/tests/integ_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ use crate::common::{
http_proxy::HttpProxy,
};
use assert_matches::assert_matches;
use futures_util::FutureExt;
use http_body_util::Full;
use futures_util::{FutureExt, stream};
use http_body_util::{BodyExt, StreamBody, combinators::BoxBody};
use hyper::{
body::{Bytes, Frame},
http::{HeaderMap, HeaderValue},
};
use prost::Message;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -452,14 +456,18 @@ where
.encode(&mut buf)
.expect("failed to encode response message");

// Props to o3-mini for giving me a cheap way to make a grpc response
let mut frame = Vec::with_capacity(5 + buf.len());
frame.push(0);
let len = buf.len() as u32;
frame.extend_from_slice(&len.to_be_bytes());
frame.extend_from_slice(&buf);
let full_body = Full::new(frame.into());
let body = Body::new(full_body);
let mut trailers = HeaderMap::new();
trailers.insert("grpc-status", HeaderValue::from_static("0"));
let stream = stream::iter(vec![
Ok::<_, Status>(Frame::data(Bytes::from(frame))),
Ok::<_, Status>(Frame::trailers(trailers)),
]);
let body = Body::new(BoxBody::new(StreamBody::new(stream)).boxed());

// Build the HTTP response with the required gRPC headers.
Response::builder()
Expand Down
Loading