-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve default headers with custom headers (#452)
Co-authored-by: Gábor Egyed <[email protected]>
- Loading branch information
Showing
11 changed files
with
97 additions
and
51 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
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
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
export default (req, res) => { | ||
const reqCookie = (new URLSearchParams(req.headers.cookie || '').get('mycookie') || '').split(';')[0].trim() | ||
res.end(reqCookie || '') | ||
} |
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,17 @@ | ||
export default async (req, res) => { | ||
const query = new URL(req.url, 'http://localhost:3000').query | ||
if (query && query.delay) { | ||
await sleep(query.delay) | ||
} | ||
|
||
res.end(JSON.stringify({ | ||
url: req.url, | ||
method: req.method | ||
})) | ||
} | ||
|
||
function sleep (ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms) | ||
}) | ||
} |
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
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
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 |
---|---|---|
@@ -1,33 +1,35 @@ | ||
<template> | ||
<div> | ||
there should be no loading bar left over: | ||
<button @click="test">Fake Request</button> | ||
<button @click="test"> | ||
Fake Request | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
methods: { | ||
test() { | ||
const source = this.$axios.CancelToken.source(); | ||
test () { | ||
const source = this.$axios.CancelToken.source() | ||
this.$axios | ||
.$post( | ||
"http://localhost:3000/test_api/foo/bar?delay=1000", | ||
{ data: "test" }, | ||
'http://localhost:3000/api/echo/foo/bar?delay=1000', | ||
{ data: 'test' }, | ||
{ | ||
cancelToken: source.token, | ||
cancelToken: source.token | ||
} | ||
) | ||
.catch((err) => { | ||
if (this.$axios.isCancel(err)) { | ||
console.log("request canceled"); | ||
console.log('request canceled') | ||
} | ||
}); | ||
}) | ||
setTimeout(function () { | ||
source.cancel(); | ||
}, 500); | ||
}, | ||
}, | ||
}; | ||
source.cancel() | ||
}, 500) | ||
} | ||
} | ||
} | ||
</script> |
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 @@ | ||
<template> | ||
<div> | ||
<pre style="display: none">_req:{{ reqCookie }}</pre> | ||
<p>Pass: {{ pass }}</p> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
async asyncData ({ app }) { | ||
const reqCookie = (await app.$axios.$get('/cookie', { | ||
headers: { Accept: 'application/json' } | ||
})) + '' | ||
return { | ||
reqCookie | ||
} | ||
}, | ||
data () { | ||
return { | ||
pass: '?' | ||
} | ||
}, | ||
async mounted () { | ||
const randomValue = Math.round(Math.random() * 1000) + '' | ||
document.cookie = `mycookie=${randomValue}; path=/` | ||
// Render page with server-side, expecting to be rendered with same new cookie | ||
const html = await this.$axios.$get(window.location.href) | ||
const m = html.match(/_req:(\w+)/) | ||
const profifiedSSRCookie = m && m[1] | ||
this.pass = randomValue === profifiedSSRCookie | ||
} | ||
} | ||
</script> |
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
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