Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added a.out
Binary file not shown.
Binary file added addon.o
Binary file not shown.
Binary file added bsd.o
Binary file not shown.
Binary file added context.o
Binary file not shown.
76 changes: 76 additions & 0 deletions dist/uws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Authored by Alex Hultman, 2018-2026.
* Intellectual property of third-party.

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = (() => {
try {
return require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node');
} catch (e) {
throw new Error('This version of uWS.js (v20.67.0) supports only Node.js versions 22, 24 and 26 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).\n\n' + e.toString());
}
})();

const MAX_U8 = Math.pow(2, 8) - 1;
const MAX_U16 = Math.pow(2, 16) - 1;
const textEncoder = new TextEncoder();

/**
* @param {RecognizedString|undefined} value
* @return {Uint8Array<ArrayBuffer>}
*/
const toUint8Array = (value) => {
if (value === undefined) return new Uint8Array(0);
else if (typeof value === 'string') return textEncoder.encode(value);
else if (value instanceof ArrayBuffer) return new Uint8Array(value);
else if (value instanceof SharedArrayBuffer) return new Uint8Array(value);
else return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
};

module.exports.DeclarativeResponse = class DeclarativeResponse {
constructor() {
this.instructions = [];
}

// Append instruction and 1-byte length values
_appendInstruction(opcode, ...values) {
this.instructions.push(opcode);
values.forEach(value => {
const uint8Array = toUint8Array(value);
if (uint8Array.byteLength > MAX_U8) throw new RangeError('Data length exceeds '+ MAX_U8);
this.instructions.push(uint8Array.byteLength, ...uint8Array);
});
}

// Append instruction and 2-byte length value
_appendInstructionWithLength(opcode, value) {
const uint8Array = toUint8Array(value);
if (uint8Array.byteLength > MAX_U16) throw new RangeError('Data length exceeds '+ MAX_U16);
this.instructions.push(opcode, uint8Array.byteLength & 0xff, (uint8Array.byteLength >> 8) & 0xff, ...uint8Array);
}

writeHeader(key, value) { return this._appendInstruction(1, key, value), this; }
writeBody() { return this.instructions.push(2), this; }
writeQueryValue(key) { return this._appendInstruction(3, key), this; }
writeHeaderValue(key) { return this._appendInstruction(4, key), this; }
write(value) { return this._appendInstructionWithLength(5, value), this; }
writeParameterValue(key) { return this._appendInstruction(6, key), this; }
writeStatus(status) { return this._appendInstruction(7, status), this; }

end(value) {
this._appendInstructionWithLength(0, value);
return new Uint8Array(this.instructions).buffer;
}
}
Binary file added dist/uws_linux_x64_127.node
Binary file not shown.
Binary file added dist/uws_linux_x64_137.node
Binary file not shown.
Binary file added dist/uws_linux_x64_147.node
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export interface HttpResponse {
writeHeader(key: RecognizedString, value: RecognizedString) : HttpResponse;
/** Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. Returns true if no backpressure was added. */
write(chunk: RecognizedString) : boolean;
/** Begins chunked encoding mode and flushes headers immediately. */
beginWrite() : HttpResponse;
/** Ends this response by copying the contents of body. */
end(body?: RecognizedString, closeConnection?: boolean) : HttpResponse;
/** Ends this response without a body. */
Expand Down
Binary file added epoll_kqueue.o
Binary file not shown.
Binary file added gcd.o
Binary file not shown.
Binary file added libuv.o
Binary file not shown.
Binary file added loop.o
Binary file not shown.
Binary file added node-v22.0.0-headers.tar.gz
Binary file not shown.
Binary file added node-v24.0.0-headers.tar.gz
Binary file not shown.
Binary file added node-v26.0.0-headers.tar.gz
Binary file not shown.
Binary file added openssl.o
Binary file not shown.
Binary file added quic.o
Binary file not shown.
Binary file added sni_tree.o
Binary file not shown.
Binary file added socket.o
Binary file not shown.
13 changes: 13 additions & 0 deletions src/HttpResponseWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ struct HttpResponseWrapper {
}
}

/* Takes nothing, returns this */
template <int SSL>
static void res_beginWrite(const FunctionCallbackInfo<Value> &args) {
auto *res = getHttpResponse<SSL>(args);
if (res) {
assumeCorked();
res->beginWrite();

args.GetReturnValue().Set(args.This());
}
}

/* Takes key, value. Returns this */
template <int PROTOCOL>
static void res_writeHeader(const FunctionCallbackInfo<Value> &args) {
Expand Down Expand Up @@ -600,6 +612,7 @@ struct HttpResponseWrapper {
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onDataV2", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_onDataV2<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "collectBody", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_collectBody<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getWriteOffset", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getWriteOffset<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "beginWrite", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_beginWrite<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddress<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "collect", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));
Expand Down
Loading
Loading