Comparing version 0.0.13 to 0.0.14
@@ -19,3 +19,3 @@ 'use strict'; | ||
// Requests | ||
HTTP2_HEADER_USER_AGENT, HTTP2_HEADER_ACCEPT, HTTP2_HEADER_COOKIE, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_LENGTH, | ||
HTTP2_HEADER_USER_AGENT, HTTP2_HEADER_ACCEPT, HTTP2_HEADER_COOKIE, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_LENGTH, HTTP2_HEADER_ACCEPT_ENCODING, | ||
// Responses | ||
@@ -66,2 +66,3 @@ HTTP2_HEADER_STATUS, HTTP2_HEADER_LOCATION, HTTP2_HEADER_SET_COOKIE, | ||
[HTTP2_HEADER_USER_AGENT]: session.userAgent(), | ||
[HTTP2_HEADER_ACCEPT_ENCODING]: 'gzip;q=1.0, deflate;q=0.5', | ||
}; | ||
@@ -68,0 +69,0 @@ if (cookies.length > 0) |
@@ -1,1 +0,1 @@ | ||
export declare const version = "0.0.13"; | ||
export declare const version = "0.0.14"; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = '0.0.13'; | ||
exports.version = '0.0.14'; | ||
//# sourceMappingURL=version.js.map |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const http2_1 = require("http2"); | ||
const { HTTP2_HEADER_LOCATION, HTTP2_HEADER_STATUS, HTTP2_HEADER_CONTENT_TYPE, } = http2_1.constants; | ||
const zlib_1 = require("zlib"); | ||
const { HTTP2_HEADER_LOCATION, HTTP2_HEADER_STATUS, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_CONTENT_ENCODING, } = http2_1.constants; | ||
const headers_1 = require("./headers"); | ||
@@ -98,9 +99,24 @@ const body_1 = require("./body"); | ||
} | ||
function makeExtra(url, stream, headers, redirected) { | ||
function makeExtra(url, headers, redirected) { | ||
const type = 'basic'; // TODO: Implement CORS | ||
return { redirected, type, url }; | ||
} | ||
function handleEncoding(stream, headers) { | ||
const contentEncoding = headers[HTTP2_HEADER_CONTENT_ENCODING]; | ||
if (!contentEncoding) | ||
return stream; | ||
const decoders = { | ||
gzip: (stream) => stream.pipe(zlib_1.createGunzip()), | ||
deflate: (stream) => stream.pipe(zlib_1.createInflate()), | ||
}; | ||
const decoder = decoders[contentEncoding]; | ||
if (!decoder) | ||
// We haven't asked for this encoding, and we can't handle it. | ||
// Pushing raw encoded stream through... | ||
return stream; | ||
return decoder(stream); | ||
} | ||
class H2StreamResponse extends Response { | ||
constructor(url, stream, headers, redirected) { | ||
super(stream, makeInit(headers), makeExtra(url, stream, headers, redirected)); | ||
super(handleEncoding(stream, headers), makeInit(headers), makeExtra(url, headers, redirected)); | ||
} | ||
@@ -107,0 +123,0 @@ } |
@@ -39,2 +39,3 @@ 'use strict' | ||
HTTP2_HEADER_CONTENT_LENGTH, | ||
HTTP2_HEADER_ACCEPT_ENCODING, | ||
@@ -125,2 +126,3 @@ // Responses | ||
[ HTTP2_HEADER_USER_AGENT ]: session.userAgent( ), | ||
[ HTTP2_HEADER_ACCEPT_ENCODING ]: 'gzip;q=1.0, deflate;q=0.5', | ||
}; | ||
@@ -127,0 +129,0 @@ |
'use strict' | ||
export const version = '0.0.13'; | ||
export const version = '0.0.14'; |
@@ -9,2 +9,7 @@ 'use strict' | ||
import { | ||
createGunzip, | ||
createInflate, | ||
} from 'zlib' | ||
const { | ||
@@ -14,2 +19,3 @@ HTTP2_HEADER_LOCATION, | ||
HTTP2_HEADER_CONTENT_TYPE, | ||
HTTP2_HEADER_CONTENT_ENCODING, | ||
} = h2constants; | ||
@@ -172,3 +178,2 @@ | ||
url: string, | ||
stream: ClientHttp2Stream, | ||
headers: IncomingHttpHeaders, | ||
@@ -184,2 +189,30 @@ redirected: boolean | ||
function handleEncoding( | ||
stream: NodeJS.ReadableStream, | ||
headers: IncomingHttpHeaders | ||
) | ||
: NodeJS.ReadableStream | ||
{ | ||
const contentEncoding = headers[ HTTP2_HEADER_CONTENT_ENCODING ] as string; | ||
if ( !contentEncoding ) | ||
return stream; | ||
const decoders = { | ||
gzip: ( stream: NodeJS.ReadableStream ) => | ||
stream.pipe( createGunzip( ) ), | ||
deflate: ( stream: NodeJS.ReadableStream ) => | ||
stream.pipe( createInflate( ) ), | ||
}; | ||
const decoder = decoders[ contentEncoding ]; | ||
if ( !decoder ) | ||
// We haven't asked for this encoding, and we can't handle it. | ||
// Pushing raw encoded stream through... | ||
return stream; | ||
return decoder( stream ); | ||
} | ||
export class H2StreamResponse extends Response | ||
@@ -195,7 +228,7 @@ { | ||
super( | ||
< NodeJS.ReadableStream >stream, | ||
handleEncoding( < NodeJS.ReadableStream >stream, headers ), | ||
makeInit( headers ), | ||
makeExtra( url, stream, headers, redirected ) | ||
makeExtra( url, headers, redirected ) | ||
); | ||
} | ||
} |
{ | ||
"name": "fetch-h2", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "HTTP/2-only Fetch API client for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Gustaf Räntilä", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
531919
3363