-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting Ask Class into Request/Response Classes
- Loading branch information
Universal Web
committed
Sep 15, 2023
1 parent
f5cda4c
commit 4dc0557
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
promise, assign, omit, eachArray, stringify, get, isBuffer, isPlainObject, isArray, isMap, construct, each, hasLength, hasValue, UniqID | ||
} from '@universalweb/acid'; | ||
import { decode, encode } from 'msgpackr'; | ||
import { | ||
failed, info, msgReceived, msgSent | ||
} from '#logs'; | ||
import { Base } from './base.js'; | ||
import { request } from '#udsp/requestMethods/request'; | ||
export class Ask extends Base { | ||
constructor(method = 'get', path, parameters, data, head, options = {}, source) { | ||
super(options, source); | ||
const { | ||
requestQueue, | ||
streamIdGenerator, | ||
} = source; | ||
console.log('Ask', data); | ||
const methodSanitized = method.toLowerCase(); | ||
this.request.method = methodSanitized; | ||
this.method = methodSanitized; | ||
if (path) { | ||
this.request.path = path; | ||
this.path = path; | ||
} | ||
if (parameters) { | ||
this.request.parameters = parameters; | ||
this.parameters = parameters; | ||
} | ||
if (data) { | ||
this.request.data = data; | ||
} | ||
if (head) { | ||
this.request.head = head; | ||
} | ||
} | ||
completeReceived() { | ||
console.log('Ask complete', this); | ||
if (this.state === 3) { | ||
this.state = 4; | ||
} | ||
this.readyState = 4; | ||
this.flush(); | ||
this.accept(this); | ||
} | ||
isRequest = true; | ||
type = 'request'; | ||
request = {}; | ||
} | ||
export async function ask(source) { | ||
return construct(Ask, omit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class UWResponse { | ||
constructor(headers, data) { | ||
} | ||
isResponse = true; | ||
type = 'response'; | ||
} |