unused protocol encoding
This commit is contained in:
parent
dbc01b3d56
commit
f0611a980c
1 changed files with 0 additions and 44 deletions
|
|
@ -38,10 +38,6 @@ import UVClient from '../client/index.js';
|
|||
import BareClient from '@tomphttp/bare-client';
|
||||
import EventEmitter from 'events';
|
||||
|
||||
const valid_chars =
|
||||
"!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~";
|
||||
const reserved_chars = '%';
|
||||
|
||||
class Ultraviolet {
|
||||
constructor(options = {}) {
|
||||
this.prefix = options.prefix || '/service/';
|
||||
|
|
@ -133,46 +129,6 @@ class Ultraviolet {
|
|||
decodeUrl(str) {
|
||||
return decodeURIComponent(str);
|
||||
}
|
||||
encodeProtocol(protocol) {
|
||||
protocol = protocol.toString();
|
||||
|
||||
let result = '';
|
||||
|
||||
for (let i = 0; i < protocol.length; i++) {
|
||||
const char = protocol[i];
|
||||
|
||||
if (valid_chars.includes(char) && !reserved_chars.includes(char)) {
|
||||
result += char;
|
||||
} else {
|
||||
const code = char.charCodeAt();
|
||||
result += '%' + code.toString(16).padStart(2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
decodeProtocol(protocol) {
|
||||
if (typeof protocol != 'string')
|
||||
throw new TypeError('protocol must be a string');
|
||||
|
||||
let result = '';
|
||||
|
||||
for (let i = 0; i < protocol.length; i++) {
|
||||
const char = protocol[i];
|
||||
|
||||
if (char == '%') {
|
||||
const code = parseInt(protocol.slice(i + 1, i + 3), 16);
|
||||
const decoded = String.fromCharCode(code);
|
||||
|
||||
result += decoded;
|
||||
i += 2;
|
||||
} else {
|
||||
result += char;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
implementUVMiddleware() {
|
||||
// HTML
|
||||
attributes(this);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue