A better Rust ATProto crate

blob mimeType is hardcoded to be */* #17

closed
opened by nekomimi.pet edited

for some reason I can't make a fork to issue a fix

issue:

uploadBlob would ignore a set MimeType and set it as */* when sent to the PDS

repro:

let blob = agent.upload_blob(
        base64_bytes,
        MimeType::new_static("application/octet-stream"),
    ).await?;

output of this code:

json: {
  "blob": {
    "$type": "blob",
    "mimeType": "*/*",
    "ref": {
      "$link": "bafkreiayayykxokf4ml44crf3ez62xyjurt4mashy74bravrgrl52yphvu"
    },
    "size": 46828
  }
}

fix:

in jacquard/crates/jacquard-common/src/xrpc.rs

       551
       552 +      // Check if extra_headers already contains Content-Type
       553 +      let has_content_type = opts.extra_headers.iter().any(|(name, _)| name == CONTENT_TYPE);
       554 +
       555        if let XrpcMethod::Procedure(encoding) = <R as XrpcRequest>::METHOD {
       556 -          builder = builder.header(Header::ContentType, encoding);
       556 +          // Only set default Content-Type if not provided in extra_headers
       557 +          if !has_content_type {
       558 +              builder = builder.header(Header::ContentType, encoding);
       559 +          }

theres probably a better way of doing this, i did this at 1am tired.

Did it definitely set the wrong header on upload or did the blobref itself come back with the wrong mime type? Because the PDS itself does inference on mime types and has in fact returned a blob ref with a different mime type than i asserted on upload before (not with jacquard, this was when i was doing stuff in Kotlin).

In general, I agree with your fix, i'll make the change, it's reasonable. Just FYI that it might not actually be the cause of the apparent problem.

I base64 encode gzipped files to get around mime type sniffing from the PDS (been running into issues where svgs in html files cause the PDS to abort the request) and jacquard was forcing / on the request to the PDS

hehe yep i know that bug lol. fix will be in the next version, i'm cleaning up and doing release pre presently, there's a bunch of new stuff in alongside some bug fixes.

sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:ttdrpj45ibqunmfhdsb4zdwq/sh.tangled.repo.issue/3m4myowshah22