Skip to content

Commit

Permalink
Support parsing multipart/mixed mime type #232
Browse files Browse the repository at this point in the history
  • Loading branch information
Huachao committed Dec 1, 2018
1 parent bf0ccbe commit 3e64c18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/utils/httpRequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ export class HttpRequestParser implements IRequestParser {
headers = RequestParserUtil.parseRequestHeaders(headerLines.slice(index));

// get body range
let bodyStartLine = ArrayUtility.firstIndexOf(lines, value => value.trim() !== '', headerEndLine);
const bodyStartLine = ArrayUtility.firstIndexOf(lines, value => value.trim() !== '', headerEndLine);
if (bodyStartLine !== -1) {
let contentTypeHeader = getHeader(headers, 'content-type') || getHeader(this._restClientSettings.defaultHeaders, 'content-type');
const contentTypeHeader = getHeader(headers, 'content-type') || getHeader(this._restClientSettings.defaultHeaders, 'content-type');
firstEmptyLine = ArrayUtility.firstIndexOf(lines, value => value.trim() === '', bodyStartLine);
let bodyEndLine = MimeUtility.isMultiPartFormData(contentTypeHeader) || firstEmptyLine === -1 ? lines.length : firstEmptyLine;
const bodyEndLine =
MimeUtility.isMultiPartFormData(contentTypeHeader) || MimeUtility.isMultiPartMixed(contentTypeHeader) || firstEmptyLine === -1
? lines.length
: firstEmptyLine;
bodyLines = lines.slice(bodyStartLine, bodyEndLine);
}
} else {
// parse body, since no headers provided
let firstEmptyLine = ArrayUtility.firstIndexOf(lines, value => value.trim() === '', headerStartLine);
let bodyEndLine = firstEmptyLine === -1 ? lines.length : firstEmptyLine;
const firstEmptyLine = ArrayUtility.firstIndexOf(lines, value => value.trim() === '', headerStartLine);
const bodyEndLine = firstEmptyLine === -1 ? lines.length : firstEmptyLine;
bodyLines = lines.slice(headerStartLine, bodyEndLine);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/utils/mimeUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export class MimeUtility {
return MimeUtility.parse(contentTypeString).type === 'text/css';
}

public static isMultiPartMixed(contentTypeString: string): boolean {
if (!contentTypeString) {
return false;
}

return MimeUtility.parse(contentTypeString).type === 'multipart/mixed';
}

public static isMultiPartFormData(contentTypeString: string): boolean {
if (!contentTypeString) {
return false;
Expand Down

0 comments on commit 3e64c18

Please sign in to comment.