-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added httpStatusCode & httpStatusText.
- Loading branch information
Showing
1 changed file
with
8 additions
and
3 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
| | | ||
| HttpTransport for TypeScript. | | ||
| | | ||
| LastModified: Mar 11, 2019 | | ||
| LastModified: May 4, 2019 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -20,6 +20,8 @@ import { ClientContext, Context, getCookie, setCookie, TimeoutError, Client, Tra | |
import { ByteStream } from '@hprose/io'; | ||
|
||
export interface HttpClientContext extends ClientContext { | ||
httpStatusCode?: number; | ||
httpStatusText?: string; | ||
httpRequestHeaders?: http.OutgoingHttpHeaders; | ||
httpResponseHeaders?: http.IncomingHttpHeaders; | ||
} | ||
|
@@ -68,8 +70,9 @@ export class HttpTransport implements Transport { | |
(options as any)[key] = (this.options as any)[key]; | ||
} | ||
} | ||
const httpContext = context as HttpClientContext; | ||
options.method = 'POST'; | ||
options.headers = this.getRequestHeader((context as HttpClientContext).httpRequestHeaders); | ||
options.headers = this.getRequestHeader(httpContext.httpRequestHeaders); | ||
options.headers['Content-Length'] = request.length; | ||
const cookie = getCookie(options.host, options.path, secure); | ||
if (cookie) { | ||
|
@@ -85,9 +88,11 @@ export class HttpTransport implements Transport { | |
}); | ||
res.on('end', () => { | ||
delete this.requests[index]; | ||
httpContext.httpStatusCode = res.statusCode; | ||
httpContext.httpStatusText = res.statusMessage; | ||
if (res.statusCode) { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
(context as HttpClientContext).httpResponseHeaders = res.headers; | ||
httpContext.httpResponseHeaders = res.headers; | ||
setCookie(res.headers, options.host); | ||
resolve(instream.takeBytes()); | ||
} else { | ||
|