UNPKG

4.32 kBTypeScriptView Raw
1// Type definitions for node-spdy 3.4
2// Project: https://github.com/indutny/node-spdy
3// Definitions by: Anthony Trinh <https://github.com/tony19>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.2
6
7/// <reference types="node" />
8
9import * as http from 'http';
10import * as https from 'https';
11
12// lib/spdy/agent.js
13export namespace agent {
14 class Agent extends https.Agent {}
15 class PlainAgent extends http.Agent {}
16 function create(base: any, options: AgentOptions): Agent | PlainAgent;
17
18 interface AgentOptions extends https.AgentOptions {
19 port?: number;
20 spdy?: {
21 plain?: boolean,
22 ssl?: boolean,
23 'x-forwarded-for'?: string,
24 protocol?: string,
25 protocols?: string[]
26 };
27 }
28}
29
30// lib/spdy/handle.js
31export interface Handle {
32 create(options: object, stream: any, socket: Socket): Handle;
33 getStream(callback?: (stream: any) => void): any;
34 assignSocket(socket: Socket, options: object): void;
35 assignClientRequest(req: any): void;
36 assignRequest(req: any): void;
37 assignResponse(res: any): void;
38 emitRequest(): void;
39 emitResponse(status: any, headers: any): void;
40}
41
42// lib/spdy/request.js
43export namespace request {
44 function onNewListener(type: string): void;
45}
46
47// lib/spdy/response.js
48export namespace response {
49 function writeHead(statusCode: number, reason: string, obj: object): void;
50 function writeHead(statusCode: number, obj: object): void;
51 function end(data: any, encoding: string, callback: () => void): void;
52}
53
54// lib/spdy/server.js
55export namespace server {
56 type Server = https.Server;
57 type PlainServer = http.Server;
58 type IncomingMessage = http.IncomingMessage;
59 interface ServerResponse extends http.ServerResponse {
60 push(filename: string, options: PushOptions): any;
61 }
62 function create(base: any,
63 options: https.ServerOptions,
64 handler: (request: IncomingMessage, response: ServerResponse | http.ServerResponse) => void): Server;
65 function create(options: https.ServerOptions,
66 handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;
67 function create(handler: (request: IncomingMessage, response: ServerResponse | http.ServerResponse) => void): Server;
68
69 type Protocol =
70 'h2'
71 | 'spdy/3.1'
72 | 'spdy/3'
73 | 'spdy/2'
74 | 'http/1.1'
75 | 'http/1.0';
76
77 interface PushOptions {
78 status?: number;
79 method?: string;
80 request?: any;
81 response?: any;
82 }
83
84 interface ServerOptions extends https.ServerOptions {
85 spdy?: {
86 protocols?: Protocol[],
87 plain?: boolean,
88 'x-forwarded-for'?: boolean,
89 connection?: {
90 windowSize?: number,
91 autoSpdy31?: boolean,
92 },
93 };
94 }
95}
96
97// lib/spdy/socket.js
98export namespace socket {
99 // tslint:disable-next-line no-empty-interface
100 interface Socket {} // net.Socket
101}
102
103// lib/spdy.js
104export type Agent = agent.Agent;
105export type PlainAgent = agent.PlainAgent;
106export type AgentOptions = agent.AgentOptions;
107export type Socket = socket.Socket;
108export type Server = server.Server;
109export type IncomingMessage = server.IncomingMessage;
110export type ServerRequest = server.IncomingMessage;
111export type ServerResponse = server.ServerResponse;
112export type PlainServer = server.PlainServer;
113export type ServerOptions = server.ServerOptions;
114export function createAgent(base: any, options: AgentOptions): Agent | PlainAgent;
115export function createAgent(options: AgentOptions): Agent | PlainAgent;
116export function createServer(
117 base: any,
118 options: ServerOptions,
119 handler: (request: IncomingMessage, response: http.ServerResponse) => void,
120): Server;
121export function createServer(
122 options: ServerOptions,
123 handler: (request: IncomingMessage, response: http.ServerResponse) => void,
124): Server;
125export function createServer(handler: (request: IncomingMessage, response: http.ServerResponse) => void): Server;