-
Notifications
You must be signed in to change notification settings - Fork 384
Added cache control for http request within BrowserClient #1706
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
base: master
Are you sure you want to change the base?
Changes from 21 commits
9ba5471
ee01325
3a26def
3ba65df
f5c9c11
52ff2c5
7f70434
ae7be97
1ca0c3a
7a5c30d
85daade
7ece5aa
4bca978
dad889c
2889cb2
3d17957
a1f47db
cab59fc
5831578
2fd11c1
53dc82f
1adce3e
7d50328
410d227
83672f8
40609bc
ff7f7e8
a63d6ce
7e1bc9f
0eabc8d
c144307
34a87fb
5294e96
d12c0a4
3c53220
b485213
f65dd4f
42251ea
4c7471f
4896114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | ||
seifibrahim32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
@TestOn('browser') | ||
library; | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:http/browser_client.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:http/src/exception.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'utils.dart'; | ||
|
||
void main() { | ||
test('#send a StreamedRequest with default type', () async { | ||
seifibrahim32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var client = BrowserClient(cacheMode: CacheMode.defaultType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are only doing a single request here so I'm not sure how this is testing the caching behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, it is two GET requests, when it is set to default type it is cached once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, I need to drain the request so, I can see the difference. |
||
var request = http.StreamedRequest('POST', echoUrl); | ||
var responseFuture = client.send(request); | ||
request.sink.add('{"hello": "world"}'.codeUnits); | ||
unawaited(request.sink.close()); | ||
|
||
var response = await responseFuture; | ||
|
||
client.close(); | ||
|
||
expect(response.statusCode, 200); | ||
expect(response.reasonPhrase, 'OK'); | ||
}, skip: 'Need to fix server tests for browser'); | ||
|
||
test('#send a StreamedRequest with reload type', () async { | ||
var client = BrowserClient(cacheMode: CacheMode.reload); | ||
var request = http.StreamedRequest('POST', echoUrl); | ||
|
||
var responseFuture = client.send(request); | ||
request.sink.add('{"hello": "world"}'.codeUnits); | ||
unawaited(request.sink.close()); | ||
var response = await responseFuture; | ||
var bytesString = await response.stream.bytesToString(); | ||
|
||
client.close(); | ||
|
||
expect(bytesString, contains('no-cache')); | ||
}, skip: 'Need to fix server tests for browser'); | ||
|
||
test('#send a StreamedRequest with no-cache type', () async { | ||
var client = BrowserClient(cacheMode: CacheMode.noCache); | ||
var request = http.StreamedRequest('POST', echoUrl); | ||
|
||
var responseFuture = client.send(request); | ||
request.sink.add('{"hello": "world"}'.codeUnits); | ||
unawaited(request.sink.close()); | ||
var response = await responseFuture; | ||
var bytesString = await response.stream.bytesToString(); | ||
|
||
client.close(); | ||
expect(bytesString, contains('max-age=0')); | ||
}, skip: 'Need to fix server tests for browser'); | ||
|
||
test('#send a StreamedRequest with only-if-cached type', () { | ||
var client = BrowserClient(cacheMode: CacheMode.onlyIfCached); | ||
var request = http.StreamedRequest('POST', echoUrl); | ||
|
||
expectLater(client.send(request), throwsA(isA<ClientException>())); | ||
request.sink.add('{"hello": "world"}'.codeUnits); | ||
unawaited(request.sink.close()); | ||
|
||
client.close(); | ||
}, skip: 'Need to fix server tests for browser'); | ||
|
||
test('#send with an invalid URL', () { | ||
var client = BrowserClient(cacheMode: CacheMode.onlyIfCached); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this testing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test that the client ensures of smooth request with invalid url successfully. |
||
var url = Uri.http('http.invalid', ''); | ||
var request = http.StreamedRequest('POST', url); | ||
|
||
expect(client.send(request), throwsClientException()); | ||
|
||
request.sink.add('{"hello": "world"}'.codeUnits); | ||
request.sink.close(); | ||
}, skip: 'Need to fix server tests for browser'); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.