Skip to content

Commit

Permalink
Merge pull request #110 from melgish/feature/relative-batch-urls
Browse files Browse the repository at this point in the history
Feature/relative batch urls
  • Loading branch information
janhommes authored Jun 7, 2020
2 parents 70e40d7 + 58f13c3 commit 2fda0e0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Basic configuration is based on [RequestInit](https://developer.mozilla.org/en-U
"Content-Type": "multipart/mixed",
}),
useChangset: false,
useRelativeURLs: false,
},
credentials: "omit",
fragment: "value",
Expand Down
11 changes: 10 additions & 1 deletion src/OBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class OBatch {
"Content-Transfer-Encoding: binary",
`Content-ID: ${contentId}`,
"",
`${req.config.method} ${req.url.href} HTTP/1.1`,
`${req.config.method} ${this.getRequestURL(req)} HTTP/1.1`,
`${this.getHeaders(req)}`,
`${this.getBody(req)}`
].join(CRLF);
Expand Down Expand Up @@ -172,4 +172,13 @@ export class OBatch {
}
return mapped.join(CRLF);
}

private getRequestURL(req: ORequest): string {
let href = req.url.href;
if (this.batchConfig.batch.useRelativeURLs) {
// Strip away matching root from request.
href = href.replace(this.batchConfig.rootUrl.href, '');
}
return href;
}
}
4 changes: 4 additions & 0 deletions src/OdataConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export interface OdataBatchConfig {
boundaryPrefix?: string;
useChangset: boolean;
changsetBoundaryPrefix?: string;
/**
* When truthy, relative URL's will be used in batch elements
*/
useRelativeURLs: boolean;
}

export type OdataConfig = RequestInit & {
Expand Down
1 change: 1 addition & 0 deletions src/__snapshots__/o.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object {
},
},
"useChangset": false,
"useRelativeURLs": false,
},
"credentials": "omit",
"fragment": "value",
Expand Down
3 changes: 2 additions & 1 deletion src/o.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export function o(rootUrl: string | URL, config: OdataConfig | any = {}) {
headers: new Headers({
"Content-Type": "multipart/mixed"
}),
useChangset: false
useChangset: false,
useRelativeURLs: false
},
credentials: "omit",
fragment: "value",
Expand Down

0 comments on commit 2fda0e0

Please sign in to comment.