Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fixed HTTP 500 error when given incorrect Range header #19834

Merged
merged 1 commit into from Mar 11, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ghost/core/core/server/adapters/storage/LocalStorageBase.js
Expand Up @@ -149,6 +149,10 @@ class LocalStorageBase extends StorageBase {
return next(new errors.NoPermissionError({err: err}));
}

if (err.name === 'RangeNotSatisfiableError') {
return next(new errors.RangeNotSatisfiableError({err}));
}

return next(new errors.InternalServerError({err: err}));
}

Expand Down
@@ -1,7 +1,38 @@
const assert = require('assert/strict');
const path = require('path');
const http = require('http');
const express = require('express');
const should = require('should');
const LocalStorageBase = require('../../../../../core/server/adapters/storage/LocalStorageBase');

describe('Local Storage Base', function () {
describe('serve', function () {
it('returns a 416 RangeNotSatisfiableError if given an invalid range', function (done) {
const localStorageBase = new LocalStorageBase({
storagePath: path.resolve(__dirname, 'media-storage'),
staticFileURLPrefix: 'content/media',
siteUrl: 'http://example.com/blog/'
});

const req = new http.IncomingMessage();
const res = new http.ServerResponse(req);

Object.setPrototypeOf(req, express.request);
Object.setPrototypeOf(res, express.response);

req.method = 'GET';
req.url = '/content/media/image.jpg';
req.headers = {
range: 'bytes=1000-999'
};

localStorageBase.serve()(req, res, (err) => {
assert.equal(err.errorType, 'RangeNotSatisfiableError');
done();
});
});
});

describe('urlToPath', function () {
it('returns path from url', function () {
let localStorageBase = new LocalStorageBase({
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.