Skip to content

Commit

Permalink
bugfix: When performing a test fetch for an index page, don't perform…
Browse files Browse the repository at this point in the history
… bucket name prepend for path-style requests
  • Loading branch information
4141done committed Apr 19, 2024
1 parent 7f3064b commit 6183560
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions common/etc/nginx/include/s3gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,30 +278,42 @@ function s3BaseUri(r) {
* Returns the s3 path given the incoming request
*
* @param r {NginxHTTPRequest} HTTP request
* @param opts {Object} Additional options for assembling the s3 URI
* @param opts.preserveBasePath {boolean} If set, modifications to the base path such as the addition of the bucket name will not be performed.
* @returns {string} uri for s3 request
*/
function s3uri(r) {
let uriPath = r.variables.uri_path;
const basePath = s3BaseUri(r);
function s3uri(r, opts) {
if (!opts) {
opts = { preserveBasePath: false };
}

let basePath;
let path;
let uriPath = r.variables.uri_path;

if (opts.preserveBasePath) {
basePath = '';
} else {
basePath = s3BaseUri(r);
}

// Create query parameters only if directory listing is enabled.
if (ALLOW_LISTING && !utils.parseBoolean(r.variables.forIndexPage)) {
const queryParams = _s3DirQueryParams(uriPath, r.method);
if (queryParams.length > 0) {
path = basePath + '?' + queryParams;
path = `${basePath}?${queryParams}`;
} else {
path = _escapeURIPath(basePath + uriPath);
path = _escapeURIPath(`${basePath}${uriPath}`);
}
} else {
// This is a path that will resolve to an index page
if (PROVIDE_INDEX_PAGE && _isDirectory(uriPath) ) {
uriPath += INDEX_PAGE;
}
path = _escapeURIPath(basePath + uriPath);
path = _escapeURIPath(`${basePath}${uriPath}`);
}

utils.debug_log(r, 'S3 Request URI: ' + r.method + ' ' + path);
utils.debug_log(r, `S3 Request URI: ${r.method} ${path}`);
return path;
}

Expand Down Expand Up @@ -397,7 +409,12 @@ async function loadContent(r) {
r.internalRedirect("@s3Directory");
return;
}
const uri = s3uri(r);
// For the index page check, don't add the bucket name
// in the case of a path-style uri because the subrequest will
// add it after the redirect. Adding it here would result in the
// bucket name being added twice.
const uri = s3uri(r, { preserveBasePath: true });

let reply = await ngx.fetch(
`http://127.0.0.1:80${uri}`
);
Expand Down

0 comments on commit 6183560

Please sign in to comment.