Is it a good idea to send a checksum with the content of the response? And if so, what is the most common way to calculate the checksum?
Example:
HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json
22
{test:1}
A checksum is a value that represents the number of bits in a transmission message and is used by IT professionals to detect high-level errors within data transmissions. Prior to transmission, every piece of data or file can be assigned a checksum value after running a cryptographic hash function.
Sending REST API calls from JSP tags? We can use JSTL tags to do external api calls. The tags are reusable and do not require you to litter code inside jsp. The response from the api call is added to var attribute which can be access later in the jsp file.
The underlying protocol for HTTP is TCP which already has a checksum mechanism, so I think it would be useless.
If you still need this kind of thing you could calculate a SHA1 signature of the body content and include it as a custom header in your response, something like
HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json
X-Checksum: 40325305549f7a09edb51ff8df9528ffd8434ac6
You could always use the Content-MD5
header (see RFCs 2616 & 1864).
For what? Basically TCP pretty much handles that for you (since it's supposed to be a reliable protocol), so a checksum is less necessary and arguably redundant.
However, if you were to insist on it, I'd simply add an X-Checksum HTTP header of some kind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With