开发者

(Ab?)using http custom headers to return metadata about an entity

开发者 https://www.devze.com 2023-04-12 05:11 出处:网络
If, in addition to binary image data, I want to also return a data structure in the same http response message. That data structure would describe the image further so the receiving application could

If, in addition to binary image data, I want to also return a data structure in the same http response message. That data structure would describe the image further so the receiving application could use that information to process the image if it wanted to, what would be the way to do it?

When transmitting just that data structure without the image data, I'd probably just return it as JSON.

  1. Like any other image, with an image/... Content-Type, but adding custom http response headers containing the extra data
  2. Using application/json (or xml or ...) containing the json data structure and a field containing the encoded binary image data
  3. As Metadata in the image binary itself, although that would be specific to the type of image used (png different than gif etc.)

1) would be the easiest for me to implement both server-side and client-side, I just wond开发者_如何学Pythoner, if that's not abusing http headers, otoh. maybe this would be similar to some of the standard http headers like ETags.

2) and 3) aren't as easy to use both client- and server-side, and 2) would also not be as efficient (CPU, bandwidth) as 1) and 3).

The nice thing about 1) and 3) would be that clients unaware of the metadata (JS client?) could at least display the image.

Any objections to 1) from the HTTP police? Any other option I missed?


4) Content-Type = multipart/mixed. But if you're using a browser, see here.


If you're making up your own protocol (client and server), you can do pretty much anything you want.

However, I'd recommend not to reinvent the wheel; for instance consider the Link header field using a link relation such as "describedby".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号