-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for invalid range in blob download request
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BaseRequestPolicy, WebResource } from "@azure/storage-blob"; | ||
|
||
// Create a policy factory with create() method provided | ||
// In TypeScript, following factory class needs to implement Azure.RequestPolicyFactory type | ||
export default class RangePolicyFactory { | ||
// Constructor to accept parameters | ||
private range: string; | ||
|
||
constructor(range: any) { | ||
this.range = range; | ||
} | ||
|
||
// create() method needs to create a new RequestIDPolicy object | ||
create(nextPolicy: any, options: any) { | ||
return new RangePolicy(nextPolicy, options, this.range); | ||
} | ||
} | ||
|
||
// Create a policy by extending from Azure.BaseRequestPolicy | ||
class RangePolicy extends BaseRequestPolicy { | ||
private range: string; | ||
|
||
constructor(nextPolicy: any, options: any, range: any) { | ||
super(nextPolicy, options); | ||
this.range = range; | ||
} | ||
|
||
// Customize HTTP requests and responses by overriding sendRequest | ||
// Parameter request is Azure.WebResource type | ||
async sendRequest(request: WebResource) { | ||
request.headers.set("Range", `${this.range}`); | ||
|
||
return await this._nextPolicy.sendRequest(request); | ||
} | ||
} |
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