forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 0
Create a new pull request by comparing changes across two branches #245
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0bf4608
docs: add typescript example for custom instance (#7288)
AKASHDHARDUBEY d7e6065
fix(http2): Use port 443 for HTTPS connections by default. (#7256)
Subhan030 21df8ed
chore(sponsor): update sponsor block (#7308)
github-actions[bot] 9af8691
Add "API clients" section to Ecosystem (#7312)
mrlubos 2544692
chore(deps): bump peter-evans/create-pull-request (#7303)
dependabot[bot] 53aa420
chore(deps): bump the production_dependencies group across 1 director…
dependabot[bot] bf3f632
docs: fix typo in multipart/form-data README section (#7311)
josephfrazier 38be3b2
docs: add abort controller example (#7287)
AKASHDHARDUBEY 3141c31
chore: remove unnecessary eslint-disable directive (#7283)
Archis009 d6bbb3d
docs: add async/await timeout handling example (#7250)
rohitmiryala 46db331
doc: update deprecated var usage in documentation examples (#7246)
mrsandy1965 f869434
docs: refresh CDN URLs and example JSON headers (#7236)
techcodie 8d1271b
fix(types): add handlers to AxiosInterceptorManager interface (#5551)
tiborpilz 7373fbf
fix: main field in package.json should correspond to cjs artifacts (#…
thebanjomatic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,132 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>axios - abort controller example</title> | ||
| <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/> | ||
| <style> | ||
| .status { margin-top: 10px; } | ||
| </style> | ||
| </head> | ||
| <body class="container"> | ||
| <h1>axios.AbortController</h1> | ||
|
|
||
| <div class="row" style="margin-top: 20px;"> | ||
| <div class="col-md-12"> | ||
| <h3>1. Single Request Cancellation</h3> | ||
| <p>Click "Start Request" to begin a 3-second request. Click "Cancel Request" to abort it.</p> | ||
| <button id="startBtn" class="btn btn-primary">Start Request</button> | ||
| <button id="cancelBtn" class="btn btn-danger" disabled>Cancel Request</button> | ||
| <div id="singleStatus" class="status"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <hr/> | ||
|
|
||
| <div class="row" style="margin-top: 20px;"> | ||
| <div class="col-md-12"> | ||
| <h3>2. Search-as-you-type (Race Condition Handling)</h3> | ||
| <p>Type quickly. Previous pending requests will be cancelled automatically.</p> | ||
| <div class="form-group"> | ||
| <input type="text" id="searchInput" class="form-control" placeholder="Type to search..."> | ||
| </div> | ||
| <div id="searchStatus" class="status"></div> | ||
| <ul id="searchLog" class="list-group" style="margin-top: 10px; max-height: 200px; overflow-y: auto;"></ul> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src="/axios.min.js"></script> | ||
| <script> | ||
| // ----------------------------------------------------------------------- | ||
| // 1. Single Request Cancellation | ||
| // ----------------------------------------------------------------------- | ||
| const startBtn = document.getElementById('startBtn'); | ||
| const cancelBtn = document.getElementById('cancelBtn'); | ||
| const singleStatus = document.getElementById('singleStatus'); | ||
|
|
||
| let controller; | ||
|
|
||
| startBtn.onclick = function() { | ||
| // Create a new AbortController instance for this request | ||
| controller = new AbortController(); | ||
|
|
||
| startBtn.disabled = true; | ||
| cancelBtn.disabled = false; | ||
| singleStatus.innerHTML = '<span class="text-info">Request pending... (3s delay)</span>'; | ||
|
|
||
| axios.get('/abort-controller/server?delay=3000', { | ||
| signal: controller.signal | ||
| }) | ||
| .then(function (response) { | ||
| singleStatus.innerHTML = '<span class="text-success">' + response.data.message + '</span>'; | ||
| }) | ||
| .catch(function (err) { | ||
| if (axios.isCancel(err)) { | ||
| singleStatus.innerHTML = '<span class="text-warning">Request canceled: ' + err.message + '</span>'; | ||
| } else { | ||
| singleStatus.innerHTML = '<span class="text-danger">Error: ' + err.message + '</span>'; | ||
| } | ||
| }) | ||
| .finally(function () { | ||
| startBtn.disabled = false; | ||
| cancelBtn.disabled = true; | ||
| controller = null; | ||
| }); | ||
| }; | ||
|
|
||
| cancelBtn.onclick = function() { | ||
| if (controller) { | ||
| // Abort the request | ||
| controller.abort(); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| // ----------------------------------------------------------------------- | ||
| // 2. Search-as-you-type | ||
| // ----------------------------------------------------------------------- | ||
| const searchInput = document.getElementById('searchInput'); | ||
| const searchStatus = document.getElementById('searchStatus'); | ||
| const searchLog = document.getElementById('searchLog'); | ||
|
|
||
| let searchController; | ||
|
|
||
| searchInput.addEventListener('input', function(e) { | ||
| const query = e.target.value; | ||
|
|
||
| if (searchController) { | ||
| // Cancel the previous request | ||
| searchController.abort(); | ||
| } | ||
|
|
||
| // Create a new controller for the new request | ||
| searchController = new AbortController(); | ||
|
|
||
| log('New search for: "' + query + '"'); | ||
| searchStatus.innerHTML = '<span class="text-info">Searching...</span>'; | ||
|
|
||
| axios.get('/abort-controller/server?delay=1000', { | ||
| signal: searchController.signal | ||
| }) | ||
| .then(function (response) { | ||
| searchStatus.innerHTML = '<span class="text-success">Result for "' + query + '": ' + response.data.message + '</span>'; | ||
| log('Success: ' + query); | ||
| }) | ||
| .catch(function (err) { | ||
| if (axios.isCancel(err)) { | ||
| log('Cancelled: ' + query); | ||
| } else { | ||
| searchStatus.innerHTML = '<span class="text-danger">Error: ' + err.message + '</span>'; | ||
| log('Error: ' + query); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| function log(msg) { | ||
| const li = document.createElement('li'); | ||
| li.className = 'list-group-item py-1'; | ||
| li.textContent = new Date().toLocaleTimeString() + ' - ' + msg; | ||
| searchLog.prepend(li); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
This file contains hidden or 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,16 @@ | ||
| import url from 'url'; | ||
|
|
||
| export default function (req, res) { | ||
| const parsedUrl = url.parse(req.url, true); | ||
| const delay = parsedUrl.query.delay || 3000; | ||
|
|
||
| setTimeout(() => { | ||
| res.writeHead(200, { | ||
| 'Content-Type': 'text/json' | ||
| }); | ||
| res.write(JSON.stringify({ | ||
| message: 'Response completed successfully after ' + delay + 'ms' | ||
| })); | ||
| res.end(); | ||
| }, delay); | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
DOM text reinterpreted as HTML High