Skip to content

Commit

Permalink
Added httpStatusCode & httpStatusText.
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed May 4, 2019
1 parent e8654e9 commit abc9da2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/@hprose/rpc-node/src/HttpTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| |
| HttpTransport for TypeScript. |
| |
| LastModified: Mar 11, 2019 |
| LastModified: May 4, 2019 |
| Author: Ma Bingyao <[email protected]> |
| |
\*________________________________________________________*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit abc9da2

Please sign in to comment.