Skip to content

Commit

Permalink
fix SVG <use> tag is broken when the parent page has file:// url (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
LavrovArtem committed Feb 28, 2017
1 parent 4495b43 commit 08aa826
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/request-pipeline/file-request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import mime from 'mime';
import { EventEmitter } from 'events';
import { parse } from 'url';

Expand All @@ -16,13 +17,20 @@ export default class FileRequest extends EventEmitter {
this.stream = fs.createReadStream(path);
this.headers = {};
this.trailers = {};
this.path = path;

this.stream.on('open', () => this._onOpen());
this.stream.on('error', err => this._onOpen(err));
}

_onOpen (err) {
this.statusCode = err ? 404 : 200;
if (!err) {
this.statusCode = 200;
this.headers['content-type'] = mime.lookup(this.path);
}
else
this.statusCode = 404;

this.emit('response', this);
}

Expand Down
10 changes: 10 additions & 0 deletions test/server/data/images/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/server/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,22 @@ describe('Proxy', function () {
done();
});
});

it('Should set the correct content-type header', function (done) {
session.id = 'sessionId';

var options = {
url: proxy.openSession('file:///' + getFileProtocolUrl('./data/images/icons.svg'), session),
headers: {
accept: 'image/webp,image/*,*/*;q=0.8'
}
};

request(options, function (err, res) {
expect(res.headers['content-type']).eql('image/svg+xml');
done();
});
});
});

describe('Regression', function () {
Expand Down

0 comments on commit 08aa826

Please sign in to comment.