UNPKG

2.01 kBTypeScriptView Raw
1/*!
2 * Copyright 2021 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import * as http from 'http';
17export type RawHttpRequest = http.IncomingMessage & CloudLoggingHttpRequest;
18export interface CloudLoggingHttpRequest {
19 requestMethod?: string;
20 requestUrl?: string;
21 requestSize?: number;
22 status?: number;
23 responseSize?: number;
24 userAgent?: string;
25 remoteIp?: string;
26 serverIp?: string;
27 referer?: string;
28 latency?: {
29 seconds: number;
30 nanos: number;
31 };
32 cacheLookup?: boolean;
33 cacheHit?: boolean;
34 cacheValidatedWithOriginServer?: boolean;
35 cacheFillBytes?: number;
36 protocol?: string;
37}
38/**
39 * Abstraction of http.IncomingMessage used by middleware implementation.
40 */
41export interface ServerRequest extends http.IncomingMessage {
42 originalUrl: string;
43}
44/**
45 * makeHttpRequestData turns raw incoming HTTPRequests into structured
46 * HTTPRequest objects interpreted by Cloud Logging.
47 *
48 * @param req
49 * @param res
50 * @param latencyMilliseconds
51 */
52export declare function makeHttpRequestData(req: ServerRequest | http.IncomingMessage, res?: http.ServerResponse, latencyMilliseconds?: number): CloudLoggingHttpRequest;
53/**
54 * isRawHttpRequest detects whether a request object extends the
55 * http.IncomingMessage class. It should return true on HTTP compliant requests
56 * and all requests created by an http.Server.
57 *
58 * @param req
59 */
60export declare function isRawHttpRequest(req?: any): req is RawHttpRequest;