Return type byte[] overriding AddHeader with application/octet-stream

Have the following code. Content Type should be image/gif but is returning application/octet-stream. Is there a way to override the application/octet-stream?

If I’m reading Service Return Types correctly, byte[] are not converted to a different content type?

Note: In another service it’ll need to return image/webp so also need to be not limited to only image/gif

public class MyService : Service
{
        // https://stackoverflow.com/questions/2570633/smallest-filesize-for-transparent-single-pixel-image
       private static readonly byte[] TransparentGif =
        {
            0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
            0x01, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02
        };

        [AddHeader(ContentType="image/gif")]
        public byte[] Any(TransGif request)
        {
            return TransparentGif;
        }
}

It wont override custom content-types from this commit, available from latest v5.4.1 on MyGet.

An alternative way to set the content type is by returning a HttpResult:

public object Any(TransGif request) => 
    new HttpResult(TransparentGif) { ContentType = MimeTypes.ImageGif };
1 Like

Sweet! Thanks! And thanks for the quick response & commit!