Fix node-spdy createServer signature (#20022)

* Fix spdy createServer signature

* Fix spdy lint errors
This commit is contained in:
Tony Trinh
2017-09-26 11:12:33 -07:00
committed by Mohamed Hegazy
parent 8725002bd4
commit 0c69a915cc
3 changed files with 87 additions and 78 deletions
+50 -50
View File
@@ -1,7 +1,8 @@
// Type definitions for node-spdy v3.4.3
// Type definitions for node-spdy 3.4
// Project: https://github.com/indutny/node-spdy
// Definitions by: Anthony Trinh <https://github.com/tony19>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="node" />
@@ -11,12 +12,12 @@ import * as https from 'https';
declare module "spdy" {
// lib/spdy/agent.js
namespace agent {
export class Agent extends https.Agent {}
export class PlainAgent extends http.Agent {}
export function create(base: any, options: AgentOptions): Agent | PlainAgent;
class Agent extends https.Agent {}
class PlainAgent extends http.Agent {}
function create(base: any, options: AgentOptions): Agent | PlainAgent;
export interface AgentOptions extends https.AgentOptions {
port?: number,
interface AgentOptions extends https.AgentOptions {
port?: number;
spdy?: {
plain?: boolean,
ssl?: boolean,
@@ -28,10 +29,10 @@ declare module "spdy" {
}
// lib/spdy/handle.js
export interface Handle {
create(options: Object, stream: any, socket: Socket): Handle;
getStream(callback?: Function): any;
assignSocket(socket: Socket, options: Object): void;
interface Handle {
create(options: object, stream: any, socket: Socket): Handle;
getStream(callback?: (stream: any) => void): any;
assignSocket(socket: Socket, options: object): void;
assignClientRequest(req: any): void;
assignRequest(req: any): void;
assignResponse(res: any): void;
@@ -41,32 +42,32 @@ declare module "spdy" {
// lib/spdy/request.js
namespace request {
export function onNewListener(type: string): void;
function onNewListener(type: string): void;
}
// lib/spdy/response.js
namespace response {
export function writeHead(statusCode: number, reason: string, obj: Object): void;
export function writeHead(statusCode: number, obj: Object): void;
export function end(data: any, encoding: string, callback: Function): void;
function writeHead(statusCode: number, reason: string, obj: object): void;
function writeHead(statusCode: number, obj: object): void;
function end(data: any, encoding: string, callback: () => void): void;
}
// lib/spdy/server.js
namespace server {
export interface Server extends https.Server {}
export interface PlainServer extends http.Server {}
export interface IncomingMessage extends http.IncomingMessage {}
export interface ServerResponse extends http.ServerResponse {
type Server = https.Server;
type PlainServer = http.Server;
type IncomingMessage = http.IncomingMessage;
interface ServerResponse extends http.ServerResponse {
push(filename: string, options: PushOptions): any;
}
export function create(base: any,
function create(base: any,
options: https.ServerOptions,
handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
export function create(options: https.ServerOptions,
handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
export function create(handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
handler: (request: IncomingMessage, response: ServerResponse | http.ServerResponse) => void): Server;
function create(options: https.ServerOptions,
handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;
function create(handler: (request: IncomingMessage, response: ServerResponse | http.ServerResponse) => void): Server;
export type Protocol =
type Protocol =
'h2'
| 'spdy/3.1'
| 'spdy/3'
@@ -74,14 +75,14 @@ declare module "spdy" {
| 'http/1.1'
| 'http/1.0';
export interface PushOptions {
status?: number,
method?: string,
request?: any,
response?: any
interface PushOptions {
status?: number;
method?: string;
request?: any;
response?: any;
}
export interface ServerOptions extends https.ServerOptions {
interface ServerOptions extends https.ServerOptions {
spdy?: {
protocols?: Protocol[],
plain?: boolean,
@@ -96,28 +97,27 @@ declare module "spdy" {
// lib/spdy/socket.js
namespace socket {
export interface Socket {
// net.Socket
}
// tslint:disable-next-line no-empty-interface
interface Socket {} // net.Socket
}
// lib/spdy.js
export type Agent = agent.Agent;
export type PlainAgent = agent.PlainAgent;
export type AgentOptions = agent.AgentOptions;
export type Socket = socket.Socket;
export type Server = server.Server;
export type IncomingMessage = server.IncomingMessage;
export type ServerRequest = server.IncomingMessage;
export type ServerResponse = server.ServerResponse;
export type PlainServer = server.PlainServer;
export type ServerOptions = server.ServerOptions;
export function createAgent(base: any, options: AgentOptions): Agent | PlainAgent;
export function createAgent(options: AgentOptions): Agent | PlainAgent;
export function createServer(base: any,
type Agent = agent.Agent;
type PlainAgent = agent.PlainAgent;
type AgentOptions = agent.AgentOptions;
type Socket = socket.Socket;
type Server = server.Server;
type IncomingMessage = server.IncomingMessage;
type ServerRequest = server.IncomingMessage;
type ServerResponse = server.ServerResponse;
type PlainServer = server.PlainServer;
type ServerOptions = server.ServerOptions;
function createAgent(base: any, options: AgentOptions): Agent | PlainAgent;
function createAgent(options: AgentOptions): Agent | PlainAgent;
function createServer(base: any,
options: ServerOptions,
handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
export function createServer(options: ServerOptions,
handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
export function createServer(handler: (request: IncomingMessage, response: ServerResponse) => void): Server;
handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;
function createServer(options: ServerOptions,
handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;
function createServer(handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;
}
+34 -28
View File
@@ -2,18 +2,18 @@
import * as spdy from 'spdy';
let describe: any;
let it: any;
let fixtures: any;
let http: any;
let https: any;
let util: any;
let assert: any;
let afterEach: any;
let beforeEach: any;
let net: any;
let tls: any;
let transport: any;
declare var describe: any;
declare var it: any;
declare var fixtures: any;
declare var http: any;
declare var https: any;
declare var util: any;
declare var assert: any;
declare var afterEach: any;
declare var beforeEach: any;
declare var net: any;
declare var tls: any;
declare var transport: any;
describe('SPDY Client', () => {
describe('regular', () => {
@@ -27,7 +27,7 @@ describe('SPDY Client', () => {
const options = util._extend({
spdy: {
plain: plain
plain
}
}, fixtures.keys);
server = spdy.createServer(options, (req: any, res: any) => {
@@ -58,9 +58,9 @@ describe('SPDY Client', () => {
server.listen(fixtures.port, () => {
agent = spdy.createAgent({
rejectUnauthorized: false,
port: <number>fixtures.port,
port: <number> fixtures.port,
spdy: {
plain: plain,
plain,
protocol: plain ? npn : null,
protocols: [ npn ]
}
@@ -83,7 +83,7 @@ describe('SPDY Client', () => {
it('should send GET request', (done: any) => {
const req = hmodule.request({
agent: agent,
agent,
method: 'GET',
path: '/get',
@@ -101,7 +101,7 @@ describe('SPDY Client', () => {
it('should send POST request', (done: any) => {
const req = hmodule.request({
agent: agent,
agent,
method: 'POST',
path: '/post',
@@ -124,7 +124,7 @@ describe('SPDY Client', () => {
it('should receive PUSH_PROMISE', (done: any) => {
const req = hmodule.request({
agent: agent,
agent,
method: 'GET',
path: '/get'
@@ -144,8 +144,8 @@ describe('SPDY Client', () => {
});
it('should receive trailing headers', (done: any) => {
var req = hmodule.request({
agent: agent,
const req = hmodule.request({
agent,
method: 'GET',
path: '/get'
@@ -173,7 +173,7 @@ describe('SPDY Client', () => {
const options = util._extend({
spdy: {
plain: plain,
plain,
'x-forwarded-for': true
}
}, fixtures.keys);
@@ -188,7 +188,7 @@ describe('SPDY Client', () => {
port: fixtures.port,
spdy: {
'x-forwarded-for': '1.2.3.4',
plain: plain,
plain,
protocol: plain ? npn : null,
protocols: [ npn ]
}
@@ -210,8 +210,8 @@ describe('SPDY Client', () => {
});
it('should send x-forwarded-for', (done: any) => {
var req = hmodule.request({
agent: agent,
const req = hmodule.request({
agent,
method: 'GET',
path: '/get'
@@ -237,7 +237,7 @@ describe('SPDY Server', () => {
server = spdy.createServer(util._extend({
spdy: {
'x-forwarded-for': true,
plain: plain
plain
}
}, fixtures.keys));
@@ -248,7 +248,7 @@ describe('SPDY Server', () => {
NPNProtocols: [ npn ]
}, () => {
client = transport.connection.create(socket, {
protocol: protocol,
protocol,
isServer: false
});
client.start(version);
@@ -287,7 +287,7 @@ describe('SPDY Server', () => {
assert.equal(req.spdyVersion, res.spdyVersion);
assert(req.isSpdy);
if (!plain) {
const socket = <any>req.socket;
const socket = req.socket;
assert(socket.encrypted);
assert(socket.getPeerCertificate());
}
@@ -643,7 +643,7 @@ describe('SPDY Server', () => {
});
it('should support custom base', (done: any) => {
function Pseuver(options: spdy.ServerOptions, listener: Function) {
function Pseuver(options: spdy.ServerOptions, listener: () => void) {
https.Server.call(this, options, listener);
}
util.inherits(Pseuver, https.Server);
@@ -677,4 +677,10 @@ describe('SPDY Server', () => {
req.end();
});
});
it('should accept express app', () => {
const express = require('express');
const app = express();
spdy.createServer({}, app);
});
});
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}