Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions lib/sproxyd.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class SproxydClient {
});
return callback(null, newKey);
});

const startPayloadStreaming = () => {
// Once we start piping the stream, it starts being consumed and
// we can't replay it (in the current implementation)
Expand Down Expand Up @@ -463,13 +463,14 @@ class SproxydClient {
}

/**
* This sends a HEAD request to sproxyd.
* This sends a HEAD request to sproxyd and returns only the x-scal-usermd header.
* @param {String} key - The key to get from datastore
* @param {String} reqUids - The serialized request id
* @param {SproxydClient~getCallback} callback - callback
* @param {SproxydClient~getCallback} callback - callback(err, usermd)
* where usermd is the x-scal-usermd header value (base64 string)
* @returns {undefined}
*/
getHEAD(key, reqUids, callback) {
getUserMetadata(key, reqUids, callback) {
assert.strictEqual(typeof key, 'string');
assert.strictEqual(key.length, 40);
const log = this.createLogger(reqUids);
Expand All @@ -484,6 +485,34 @@ class SproxydClient {
});
}

/**
* This sends a HEAD request to sproxyd and returns all HTTP headers.
* @param {String} key - The key to get from datastore
* @param {String} reqUids - The serialized request id
* @param {SproxydClient~headCallback} callback - callback(err, headers)
* where headers is an object containing all HTTP response headers:
* {
* 'content-length': '6715',
* 'x-scal-usermd': 'c29tZW1ldGFkYXRhCg==',
* 'x-scal-size': '6715',
* 'content-type': 'application/octet-stream',
* ... etc
* }
* @returns {undefined}
*/
head(key, reqUids, callback) {
assert.strictEqual(typeof key, 'string');
assert.strictEqual(key.length, 40);
const log = this.createLogger(reqUids);
this._failover('HEAD', null, 0, key, 0, log, (err, res) => {
if (err) {
return callback(err);
}
// Return full headers object so caller can access content-length, etc.
return callback(null, res.headers);
});
}


/**
* This sends a DELETE request to sproxyd.
Expand Down Expand Up @@ -559,6 +588,12 @@ class SproxydClient {
* @param {stream.Readable} stream - The stream of values fetched
*/

/**
* @callback SproxydClient~headCallback
* @param {Error} - The encountered error
* @param {Object} headers - HTTP response headers object
*/

/**
* @callback SproxydClient~deleteCallback
* @param {Error} - The encountered error
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=20"
},
"version": "8.1.1",
"version": "8.2.0",
"description": "sproxyd client",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/sproxyd.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ const clientImmutableWithFailover = new Sproxy({
});

it('Should get the md of the object', done => {
client.getHEAD(savedKey, reqUid, (err, data) => {
client.getUserMetadata(savedKey, reqUid, (err, data) => {
assert.strictEqual(err, null);
assert.strictEqual(data, mdHex);
done();
});
});

it('Get HEAD should return an error', done => {
client.getHEAD(generateKey(), reqUid, err => {
client.getUserMetadata(generateKey(), reqUid, err => {
assert.notStrictEqual(err, null);
assert.notStrictEqual(err, undefined);
assert.strictEqual(err.code, 404);
Expand Down