Skip to content

Commit 9159ea0

Browse files
committed
Error rather than sending a blank content-type header
1 parent b07bc3b commit 9159ea0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### v0.28.4
4+
* Prevent RecognizeStream from sending a blank content-type header - now emits an error if content-type is unset and unable to be automatically determined.
5+
36
### v0.28.3
47
* Made SpeakerStream put keywords_result and word_alternatives on the correct result
58

speech-to-text/recognize-stream.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ RecognizeStream.prototype._read = function(/* size*/) {
295295
// so, the best we can do here is a no-op
296296
};
297297

298+
RecognizeStream.ERROR_UNRECOGNIZED_FORMAT = 'UNRECOGNIZED_FORMAT';
299+
298300
RecognizeStream.prototype._write = function(chunk, encoding, callback) {
299301
var self = this;
300302
if (self.finished) {
@@ -307,7 +309,16 @@ RecognizeStream.prototype._write = function(chunk, encoding, callback) {
307309
} else {
308310
if (!this.initialized) {
309311
if (!this.options['content-type']) {
310-
this.options['content-type'] = RecognizeStream.getContentType(chunk);
312+
var ct = RecognizeStream.getContentType(chunk);
313+
if (ct) {
314+
this.options['content-type'] = ct;
315+
} else {
316+
var err = new Error('Unable to determine content-type from file header, please specify manually.');
317+
err.name = RecognizeStream.ERROR_UNRECOGNIZED_FORMAT;
318+
this.emit('error', err);
319+
this.push(null);
320+
return;
321+
}
311322
}
312323
this.initialize();
313324
}

0 commit comments

Comments
 (0)