Skip to content

Commit

Permalink
codegen: GetObject range returns 206 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine authored Dec 9, 2023
1 parent 9824baf commit 0176e45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
38 changes: 23 additions & 15 deletions codegen/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,27 @@ fn codegen_header_value(ops: &Operations, rust_types: &RustTypes) {
}
}

fn codegen_op_http_ser_unit(op: &Operation) {
g!("pub fn serialize_http() -> http::Response {{");

if op.http_code == 200 {
g!("http::Response::default()");
} else {
g!("let mut res = http::Response::default();");
g!("res.status = http::StatusCode::{};", status_code_name(op.http_code));
g!("res");
}

g!("}}");
}

fn codegen_op_http_ser(op: &Operation, rust_types: &RustTypes) {
let output = op.output.as_str();
let rust_type = &rust_types[output];
match rust_type {
rust::Type::Provided(ty) => {
assert_eq!(ty.name, "Unit");
g!("pub fn serialize_http() -> http::Response {{");

if op.http_code == 200 {
g!("http::Response::default()");
} else {
g!("let mut res = http::Response::default();");

let code_name = status_code_name(op.http_code);
g!("res.status = http::StatusCode::{code_name};");

g!("res");
}

g!("}}");
codegen_op_http_ser_unit(op);
}
rust::Type::Struct(ty) => {
if ty.fields.is_empty() {
Expand All @@ -255,7 +256,14 @@ fn codegen_op_http_ser(op: &Operation, rust_types: &RustTypes) {
assert!(["header", "metadata", "xml", "payload"].contains(&field.position.as_str()),);
}

{
if op.name == "GetObject" {
assert_eq!(op.http_code, 200);
g!("let mut res = http::Response::default();");
// https://github.com/Nugine/s3s/issues/118
g!("if x.content_range.is_some() {{");
g!(" res.status = http::StatusCode::PARTIAL_CONTENT;");
g!("}}");
} else {
let code_name = status_code_name(op.http_code);
g!("let mut res = http::Response::with_status(http::StatusCode::{code_name});");
}
Expand Down
5 changes: 4 additions & 1 deletion crates/s3s/src/ops/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,10 @@ impl GetObject {
}

pub fn serialize_http(x: GetObjectOutput) -> S3Result<http::Response> {
let mut res = http::Response::with_status(http::StatusCode::OK);
let mut res = http::Response::default();
if x.content_range.is_some() {
res.status = http::StatusCode::PARTIAL_CONTENT;
}
if let Some(val) = x.body {
http::set_stream_body(&mut res, val);
}
Expand Down

0 comments on commit 0176e45

Please sign in to comment.