-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow modifying the default response headers
- Loading branch information
Showing
4 changed files
with
112 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
library test.jaguar.headers.modified; | ||
|
||
import 'package:http/io_client.dart' as http; | ||
import 'package:http/http.dart' as http; | ||
import 'package:jaguar_resty/expect/expect.dart'; | ||
import 'package:jaguar_resty/jaguar_resty.dart' as resty; | ||
import 'package:test/test.dart'; | ||
import 'package:jaguar/jaguar.dart'; | ||
|
||
void main() { | ||
resty.globalClient = http.IOClient(); | ||
|
||
group('headers modified', () { | ||
Jaguar server; | ||
setUpAll(() async { | ||
server = Jaguar( | ||
port: 10000, | ||
defaultResponseHeaders: (h) { | ||
h.removeAll('x-frame-options'); | ||
h.add('x-custom', 'value'); | ||
}, | ||
); | ||
server..get('/empty', (ctx) {}); | ||
await server.serve(); | ||
}); | ||
|
||
tearDownAll(() async { | ||
await server.close(); | ||
}); | ||
|
||
test('added header', () async { | ||
await resty | ||
.get('http://localhost:10000/empty') | ||
.exact(statusCode: 200, headers: { | ||
'content-type': 'text/plain; charset=utf-8', | ||
'x-xss-protection': '1; mode=block', | ||
'x-content-type-options': 'nosniff', | ||
'x-custom': 'value', | ||
'content-length': '0', | ||
}); | ||
}); | ||
|
||
test('removed header', () async { | ||
await resty.get('http://localhost:10000/empty').expect([ | ||
(r) { | ||
if (r.headers.containsKey('x-frame-options')) { | ||
return <Mismatch>[ | ||
new MapHasMismatch( | ||
'x-frame-options', | ||
customMessage: (m) => 'Illegal header ${m.key}!', | ||
) | ||
]; | ||
} | ||
return <Mismatch>[]; | ||
} | ||
]); | ||
}); | ||
}); | ||
} |
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,36 @@ | ||
library test.jaguar.headers.unmodified; | ||
|
||
import 'package:http/io_client.dart' as http; | ||
import 'package:http/http.dart' as http; | ||
import 'package:jaguar_resty/jaguar_resty.dart' as resty; | ||
import 'package:test/test.dart'; | ||
import 'package:jaguar/jaguar.dart'; | ||
|
||
void main() { | ||
resty.globalClient = http.IOClient(); | ||
|
||
group('headers unmodified', () { | ||
Jaguar server; | ||
setUpAll(() async { | ||
server = Jaguar(port: 10000); | ||
server..get('/empty', (ctx) {}); | ||
await server.serve(); | ||
}); | ||
|
||
tearDownAll(() async { | ||
await server.close(); | ||
}); | ||
|
||
test('default', () async { | ||
await resty | ||
.get('http://localhost:10000/empty') | ||
.exact(statusCode: 200, headers: { | ||
'x-frame-options': 'SAMEORIGIN', | ||
'content-type': 'text/plain; charset=utf-8', | ||
'x-xss-protection': '1; mode=block', | ||
'x-content-type-options': 'nosniff', | ||
'content-length': '0', | ||
}); | ||
}); | ||
}); | ||
} |
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