• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

panates / opra / 28585340608

02 Jul 2026 09:58AM UTC coverage: 82.799% (-0.3%) from 83.077%
28585340608

push

github

erayhanoglu
Feat: Added bundle support for HTTP protocol
Refactor: Renamed HttpIncoming to HttpRequest, HttpOutgoing to HttpResponse
Refactor: Refactored MultipartReader to support multipart/mixed

3763 of 4860 branches covered (77.43%)

Branch coverage included in aggregate %.

1755 of 1981 new or added lines in 54 files covered. (88.59%)

94 existing lines in 4 files now uncovered.

33673 of 40353 relevant lines covered (83.45%)

220.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.26
/packages/http/src/interfaces/http-request.interface.ts
1
import { isPlainObject } from '@jsopen/objects';
1✔
2
import { mergePrototype } from '@opra/common';
1✔
3
import type http from 'http';
1✔
4
import type {
1✔
5
  Options as RangeParserOptions,
1✔
6
  Ranges as RangeParserRanges,
1✔
7
  Result as RangeParserResult,
1✔
8
} from 'range-parser';
1✔
9
import { HttpRequestHost } from '../impl/http-request.host.js';
1✔
10
import { IncomingMessageHost } from '../impl/incoming-message-host.js';
1✔
11
import { isHttpIncomingMessage, isHttpRequest } from '../type-guards.js';
1✔
12
import { BodyReader } from '../utils/body-reader.js';
1✔
13
import type { HttpResponse } from './http-response.interface.js';
1✔
14

1✔
15
/**
1✔
16
 * HttpRequest represents an incoming HTTP request.
1✔
17
 * It extends NodeIncomingMessage with additional functionality for handling HTTP requests.
1✔
18
 */
1✔
19
export interface HttpRequest extends http.IncomingMessage {
1✔
20
  res: HttpResponse;
1✔
21

1✔
22
  baseUrl: string;
1✔
23

1✔
24
  originalUrl: string;
1✔
25

1✔
26
  /**
1✔
27
   * Return the protocol string "http" or "https"
1✔
28
   * When the "X-Forwarded-Proto" header field will be trusted
1✔
29
   * and used if present.
1✔
30
   */
1✔
31
  protocol: string;
1✔
32

1✔
33
  /**
1✔
34
   * Return the remote address from the trusted proxy.
1✔
35
   *
1✔
36
   * This is the remote address on the socket unless "trust proxy" is set.
1✔
37
   */
1✔
38
  ip: string;
1✔
39

1✔
40
  /**
1✔
41
   * When "trust proxy" is set, trusted proxy addresses + client.
1✔
42
   *
1✔
43
   * For example if the value were "client, proxy1, proxy2"
1✔
44
   * you would receive the array `["client", "proxy1", "proxy2"]`
1✔
45
   * where "proxy2" is the furthest down-stream and "proxy1" and
1✔
46
   * "proxy2" were trusted.
1✔
47
   */
1✔
48
  ips: string[];
1✔
49

1✔
50
  /**
1✔
51
   * Short-hand for:
1✔
52
   *    req.protocol === 'https'
1✔
53
   */
1✔
54
  secure: boolean;
1✔
55

1✔
56
  /**
1✔
57
   * Used for signed cookies
1✔
58
   */
1✔
59
  secret?: string;
1✔
60

1✔
61
  /**
1✔
62
   * Parse the "Host" header field to a hostname.
1✔
63
   *
1✔
64
   * When the "trust proxy" setting trusts the socket
1✔
65
   * address, the "X-Forwarded-Host" header field will
1✔
66
   * be trusted.
1✔
67
   */
1✔
68
  hostname?: string;
1✔
69

1✔
70
  /**
1✔
71
   * Check if the request is fresh, aka
1✔
72
   * Last-Modified and/or the ETag still match.
1✔
73
   */
1✔
74
  fresh: boolean;
1✔
75

1✔
76
  /**
1✔
77
   * Path parameter values
1✔
78
   */
1✔
79
  params: Record<string, any>;
1✔
80

1✔
81
  /**
1✔
82
   * Cookie parameter values
1✔
83
   */
1✔
84
  cookies?: Record<string, any>;
1✔
85

1✔
86
  /**
1✔
87
   * Return request header.
1✔
88
   *
1✔
89
   * The `Referrer` header field is special-cased,
1✔
90
   * both `Referrer` and `Referer` are interchangeable.
1✔
91
   *
1✔
92
   * @example
1✔
93
   *     req.get('Content-Type');
1✔
94
   *     // => "text/plain"
1✔
95
   *
1✔
96
   *     req.get('content-type');
1✔
97
   *     // => "text/plain"
1✔
98
   *
1✔
99
   *     req.get('Something');
1✔
100
   *     // => undefined
1✔
101
   *
1✔
102
   */
1✔
103
  header(name: 'set-cookie'): string[] | undefined;
1✔
104

1✔
105
  header(name: string): string | undefined;
1✔
106

1✔
107
  get(name: 'set-cookie'): string[] | undefined;
1✔
108

1✔
109
  get(name: string): string | undefined;
1✔
110

1✔
111
  /**
1✔
112
   * Check if the given `type(s)` is acceptable, returning
1✔
113
   * the best match when true, otherwise `undefined`, in which
1✔
114
   * case you should respond with 406 "Not Acceptable".
1✔
115
   *
1✔
116
   * The `type` value may be a single mime type string
1✔
117
   * such as "application/json", the extension name
1✔
118
   * such as "json", a comma-delimited list such as "json, html, text/plain",
1✔
119
   * or an array `["json", "html", "text/plain"]`. When a list
1✔
120
   * or array is given the _best_ match, if any is returned.
1✔
121
   *
1✔
122
   * @example
1✔
123
   *     // Accept: text/html
1✔
124
   *     req.accepts('html');
1✔
125
   *     // => "html"
1✔
126
   *
1✔
127
   *     // Accept: text/*, application/json
1✔
128
   *     req.accepts('html');
1✔
129
   *     // => "html"
1✔
130
   *     req.accepts('text/html');
1✔
131
   *     // => "text/html"
1✔
132
   *     req.accepts('json, text');
1✔
133
   *     // => "json"
1✔
134
   *     req.accepts('application/json');
1✔
135
   *     // => "application/json"
1✔
136
   *
1✔
137
   *     // Accept: text/*, application/json
1✔
138
   *     req.accepts('image/png');
1✔
139
   *     req.accepts('png');
1✔
140
   *     // => undefined
1✔
141
   *
1✔
142
   *     // Accept: text/*;q=.5, application/json
1✔
143
   *     req.accepts(['html', 'json']);
1✔
144
   *     req.accepts('html, json');
1✔
145
   *     // => "json"
1✔
146
   */
1✔
147
  accepts(): string[];
1✔
148

1✔
149
  accepts(type: string): string | false;
1✔
150

1✔
151
  accepts(type: string[]): string | false;
1✔
152

1✔
153
  accepts(...type: string[]): string | false;
1✔
154

1✔
155
  /**
1✔
156
   * Returns the first accepted charset of the specified character sets,
1✔
157
   * based on the request's Accept-Charset HTTP header field.
1✔
158
   * If none of the specified charsets is accepted, returns false.
1✔
159
   *
1✔
160
   * For more information, or if you have issues or concerns, see accepts.
1✔
161
   */
1✔
162
  acceptsCharsets(): string[];
1✔
163

1✔
164
  acceptsCharsets(charsets: string[]): string | false;
1✔
165

1✔
166
  acceptsCharsets(...charset: string[]): string | false;
1✔
167

1✔
168
  /**
1✔
169
   * Returns the first accepted encoding of the specified encodings,
1✔
170
   * based on the request's Accept-Encoding HTTP header field.
1✔
171
   * If none of the specified encodings is accepted, returns false.
1✔
172
   *
1✔
173
   * For more information, or if you have issues or concerns, see accepts.
1✔
174
   */
1✔
175
  acceptsEncodings(): string[];
1✔
176

1✔
177
  acceptsEncodings(encodings: string[]): string | false;
1✔
178

1✔
179
  acceptsEncodings(...encoding: string[]): string | false;
1✔
180

1✔
181
  /**
1✔
182
   * Returns the first accepted language of the specified languages,
1✔
183
   * based on the request's Accept-Language HTTP header field.
1✔
184
   * If none of the specified languages is accepted, returns false.
1✔
185
   *
1✔
186
   * For more information, or if you have issues or concerns, see accepts.
1✔
187
   */
1✔
188
  acceptsLanguages(): string[];
1✔
189

1✔
190
  acceptsLanguages(lang: string): string | false;
1✔
191

1✔
192
  acceptsLanguages(lang: string[]): string | false;
1✔
193

1✔
194
  acceptsLanguages(...lang: string[]): string | false;
1✔
195

1✔
196
  characterEncoding(): string | undefined;
1✔
197

1✔
198
  /**
1✔
199
   * Check if the incoming request contains the "Content-Type"
1✔
200
   * header field, and it contains the give mime `type`.
1✔
201
   *
1✔
202
   * @example
1✔
203
   *      // With Content-Type: text/html; charset=utf-8
1✔
204
   *      req.is('html');
1✔
205
   *      req.is('text/html');
1✔
206
   *      req.is('text/*');
1✔
207
   *      // => true
1✔
208
   *
1✔
209
   *      // When Content-Type is application/json
1✔
210
   *      req.is('json');
1✔
211
   *      req.is('application/json');
1✔
212
   *      req.is('application/*');
1✔
213
   *      // => true
1✔
214
   *
1✔
215
   *      req.is('html');
1✔
216
   *      // => false
1✔
217
   */
1✔
218
  is(type: string | string[]): string | false | null;
1✔
219

1✔
220
  is(...types: string[]): string | false | null;
1✔
221

1✔
222
  /**
1✔
223
   * Parse Range header field, capping to the given `size`.
1✔
224
   */
1✔
225
  range(
1✔
226
    size: number,
1✔
227
    options?: RangeParserOptions,
1✔
228
  ): RangeParserRanges | RangeParserResult | undefined;
1✔
229

1✔
230
  /**
1✔
231
   * Receives and parses the request body.
1✔
232
   *
1✔
233
   * @param options - Optional reader settings.
1✔
234
   * @returns A promise that resolves to the body content.
1✔
235
   */
1✔
236
  readBody(options?: BodyReader.Options): Promise<string | Buffer | undefined>;
1✔
237
}
1✔
238

1✔
239
export namespace HttpRequest {
1✔
240
  /**
1✔
241
   * Creates an HttpRequest instance from various sources.
1✔
242
   *
1✔
243
   * @param instance - The source instance.
1✔
244
   * @returns The HttpIncoming instance.
1✔
245
   */
1✔
246
  export function create(
1✔
247
    instance: http.IncomingMessage | IncomingMessageHost.Initiator,
562✔
248
  ): HttpRequest {
562✔
249
    if (isHttpRequest(instance)) return instance;
562✔
250
    if (!isHttpIncomingMessage(instance)) {
562✔
251
      if (isPlainObject(instance))
65✔
252
        instance = IncomingMessageHost.create(instance);
65!
NEW
253
      else throw new TypeError(`${instance} is not an http IncomingMessage`);
×
254
    }
65✔
255
    mergePrototype(instance, HttpRequestHost.prototype);
540✔
256
    const req = instance as HttpRequest;
540✔
257
    req.baseUrl = req.baseUrl || '';
562✔
258
    req.params = req.params || {};
562✔
259
    return req;
562✔
260
  }
562✔
261
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc