• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

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

98.45
/packages/http/src/interfaces/http-response.interface.ts
1
import { mergePrototype } from '@opra/common';
1✔
2
import http from 'http';
1✔
3
import { type StrictOmit } from 'ts-gems';
1✔
4
import { HttpResponseHost } from '../impl/http-response.host.js';
1✔
5
import type { ServerResponseHost } from '../impl/server-response-host.js';
1✔
6
import { isHttpOutgoingMessage, isHttpResponse } from '../type-guards.js';
1✔
7
import type { HttpRequest } from './http-request.interface.js';
1✔
8

1✔
9
/**
1✔
10
 * HttpOutgoing represents an outgoing HTTP response. (Express.Response)
1✔
11
 * It extends OutgoingMessage with additional functionality for handling HTTP responses.
1✔
12
 */
1✔
13
export interface HttpResponse extends StrictOmit<
1✔
14
  http.ServerResponse<HttpRequest>,
1✔
15
  'appendHeader' | 'setHeader'
1✔
16
> {
1✔
17
  statusCode: number;
1✔
18
  statusMessage: string;
1✔
19

1✔
20
  appendHeader(name: string, value: string | readonly string[]): this;
1✔
21

1✔
22
  getHeader(name: string): number | string | string[] | undefined;
1✔
23

1✔
24
  setHeader(name: string, value: number | string | readonly string[]): this;
1✔
25

1✔
26
  /**
1✔
27
   * Set _Content-Disposition_ header to _attachment_ with optional `filename`.
1✔
28
   */
1✔
29
  attachment(filename?: string): this;
1✔
30

1✔
31
  /* Clear cookie `name`. */
1✔
32
  clearCookie(name: string, options?: CookieOptions): this;
1✔
33

1✔
34
  /**
1✔
35
   * Set cookie `name` to `val`, with the given `options`.
1✔
36
   *
1✔
37
   * Options:
1✔
38
   *
1✔
39
   *    - `maxAge`   max-age in milliseconds, converted to `expires`
1✔
40
   *    - `signed`   sign the cookie
1✔
41
   *    - `path`     defaults to "/"
1✔
42
   *
1✔
43
   * Examples:
1✔
44
   *
1✔
45
   *    // "Remember Me" for 15 minutes
1✔
46
   *    res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
1✔
47
   *
1✔
48
   *    // save as above
1✔
49
   *    res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
1✔
50
   */
1✔
51
  cookie(name: string, val: string, options: CookieOptions): this;
1✔
52

1✔
53
  cookie(name: string, val: any, options: CookieOptions): this;
1✔
54

1✔
55
  cookie(name: string, val: any): this;
1✔
56

1✔
57
  /**
1✔
58
   * Set _Content-Type_ response header with `type` through `mime.lookup()`
1✔
59
   * when it does not contain "/", or set the Content-Type to `type` otherwise.
1✔
60
   *
1✔
61
   * @example
1✔
62
   *     res.type('.html');
1✔
63
   *     res.type('html');
1✔
64
   *     res.type('json');
1✔
65
   *     res.type('application/json');
1✔
66
   *     res.type('png');
1✔
67
   */
1✔
68
  contentType(type: string): this;
1✔
69

1✔
70
  /**
1✔
71
   * Set Link header field with the given `links`.
1✔
72
   *
1✔
73
   * Examples:
1✔
74
   *
1✔
75
   *    res.links({
1✔
76
   *      next: 'http://api.example.com/users?page=2',
1✔
77
   *      last: 'http://api.example.com/users?page=5'
1✔
78
   *    });
1✔
79
   */
1✔
80
  links(links: Record<string, string>): this;
1✔
81

1✔
82
  /**
1✔
83
   * Set the location header to `url`.
1✔
84
   *
1✔
85
   * The given `url` can also be the name of a mapped url, for
1✔
86
   * example by default express supports "back" which redirects
1✔
87
   * to the _Referrer_ or _Referer_ headers or "/".
1✔
88
   *
1✔
89
   * Examples:
1✔
90
   *
1✔
91
   *    res.location('/foo/bar').;
1✔
92
   *    res.location('http://example.com');
1✔
93
   *    res.location('../login'); // /blog/post/1 -> /blog/login
1✔
94
   *
1✔
95
   * Mounting:
1✔
96
   *
1✔
97
   *   When an application is mounted and `res.location()`
1✔
98
   *   is given a path that does _not_ lead with "/" it becomes
1✔
99
   *   relative to the mount-point. For example if the application
1✔
100
   *   is mounted at "/blog", the following would become "/blog/login".
1✔
101
   *
1✔
102
   *      res.location('login');
1✔
103
   *
1✔
104
   *   While the leading slash would result in a location of "/login":
1✔
105
   *
1✔
106
   *      res.location('/login');
1✔
107
   */
1✔
108
  location(url: string): this;
1✔
109

1✔
110
  /**
1✔
111
   * Redirect to the given `url` with optional response `status`
1✔
112
   * defaulting to 302.
1✔
113
   *
1✔
114
   * The resulting `url` is determined by `res.location()`, so
1✔
115
   * it will play nicely with mounted apps, relative paths,
1✔
116
   * `"back"` etc.
1✔
117
   *
1✔
118
   * Examples:
1✔
119
   *
1✔
120
   *    res.redirect('back');
1✔
121
   *    res.redirect('/foo/bar');
1✔
122
   *    res.redirect('http://example.com');
1✔
123
   *    res.redirect(301, 'http://example.com');
1✔
124
   *    res.redirect('http://example.com', 301);
1✔
125
   *    res.redirect('../login'); // /blog/post/1 -> /blog/login
1✔
126
   */
1✔
127
  redirect(url: string): void;
1✔
128

1✔
129
  redirect(status: number, url: string): void;
1✔
130

1✔
131
  /**
1✔
132
   * Set status `code`.
1✔
133
   */
1✔
134
  status(code: number): this;
1✔
135

1✔
136
  /**
1✔
137
   * Send the given HTTP status code.
1✔
138
   *
1✔
139
   * Sets the response status to `statusCode` and the body of the
1✔
140
   * response to the standard description from node's http.STATUS_CODES
1✔
141
   * or the statusCode number if no description.
1✔
142
   */
1✔
143
  sendStatus(statusCode: number): this;
1✔
144

1✔
145
  /**
1✔
146
   * Send a response.
1✔
147
   *
1✔
148
   * @example
1✔
149
   *     res.send(new Buffer('wahoo'));
1✔
150
   *     res.send({ some: 'json' });
1✔
151
   *     res.send('<p>some html</p>');
1✔
152
   *     res.status(404).send('Sorry, cant find that');
1✔
153
   */
1✔
154
  send(body?: any): this;
1✔
155
}
1✔
156

1✔
157
export interface CookieOptions {
1✔
158
  secret?: string;
1✔
159
  maxAge?: number;
1✔
160
  signed?: boolean;
1✔
161
  expires?: Date;
1✔
162
  httpOnly?: boolean;
1✔
163
  path?: string;
1✔
164
  domain?: string;
1✔
165
  secure?: boolean;
1✔
166
  encode?: (val: string) => string;
1✔
167
  sameSite?: boolean | 'lax' | 'strict' | 'none';
1✔
168
}
1✔
169

1✔
170
export namespace HttpResponse {
1✔
171
  /**
1✔
172
   * Creates an HttpOutgoing instance from various sources.
1✔
173
   *
1✔
174
   * @param instance - The source instance.
1✔
175
   * @returns The HttpOutgoing instance.
1✔
176
   */
1✔
177
  export function create(
1✔
178
    instance: http.OutgoingMessage | ServerResponseHost.Initiator,
563✔
179
  ): HttpResponse {
563✔
180
    if (isHttpResponse(instance)) return instance;
563✔
181
    if (!isHttpOutgoingMessage(instance)) {
563!
NEW
182
      throw new TypeError(`${instance} is not an http OutgoingMessage`);
×
NEW
183
    }
✔
184
    mergePrototype(instance, HttpResponseHost.prototype);
350✔
185
    return instance as HttpResponse;
350✔
186
  }
350✔
187
}
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