Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexer: fix parsing POST request when using Map for headers #78

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warcio",
"version": "2.3.0",
"version": "2.3.1",
"keywords": [
"WARC",
"web archiving"
Expand Down
2 changes: 0 additions & 2 deletions src/lib/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ export class CDXIndexer extends Indexer {

if (postToGetUrl(request)) {
requestBody = request.requestBody;
record.method = method;
record.requestBody = requestBody;
url = request.url;
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,24 @@ export function postToGetUrl(request: Request) {
return false;
}

const requestMime = (headers.get("content-type") || "").split(";")[0];
const getContentType = (headers: Headers | Map<string, string>) : string => {
const ct = headers.get("content-type");
if (ct) {
return ct;
}
if (!(headers instanceof Headers)) {
for (const [key, value] of headers.entries()) {
if (key && key.toLowerCase() === "content-type") {
return value;
}
}
}
return "";
}

const contentType = getContentType(headers);

const requestMime = contentType.split(";")[0];

function decodeIfNeeded(
postData: Uint8Array | string | undefined | null,
Expand Down Expand Up @@ -93,13 +110,12 @@ export function postToGetUrl(request: Request) {
break;

case "multipart/form-data": {
const content_type = headers.get("content-type");
if (!content_type) {
if (!contentType) {
throw new Error(
"utils cannot call postToGetURL when missing content-type header",
);
}
query = mfdToQueryString(decodeIfNeeded(postData), content_type);
query = mfdToQueryString(decodeIfNeeded(postData), contentType);
break;
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib/warcrecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ export class WARCRecord extends BaseAsyncIterReader {
_offset: number | undefined = 0;
_length = 0;

method: string | undefined = "";
requestBody = "";
_urlkey = "";

constructor({
Expand Down
Loading