-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
94 changed files
with
1,751 additions
and
1,374 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 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
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,31 +1,31 @@ | ||
import 'package:http_interop/http_interop.dart'; | ||
import 'package:json_api/http.dart'; | ||
|
||
class CorsHandler implements HttpHandler { | ||
class CorsHandler implements Handler { | ||
CorsHandler(this._inner); | ||
|
||
final HttpHandler _inner; | ||
final Handler _inner; | ||
|
||
@override | ||
Future<HttpResponse> handle(HttpRequest request) async { | ||
Future<Response> handle(Request request) async { | ||
final headers = { | ||
'Access-Control-Allow-Origin': request.headers['origin'] ?? '*', | ||
'Access-Control-Expose-Headers': 'Location', | ||
'Access-Control-Allow-Origin': [request.headers.last('origin') ?? '*'], | ||
'Access-Control-Expose-Headers': ['Location'], | ||
}; | ||
|
||
if (request.isOptions) { | ||
if (request.method.equals('OPTIONS')) { | ||
const methods = ['POST', 'GET', 'DELETE', 'PATCH', 'OPTIONS']; | ||
return HttpResponse(204) | ||
..headers.addAll({ | ||
...headers, | ||
'Access-Control-Allow-Methods': | ||
// TODO: Make it work for all browsers. Why is toUpperCase() needed? | ||
request.headers['Access-Control-Request-Method']?.toUpperCase() ?? | ||
methods.join(', '), | ||
'Access-Control-Allow-Headers': | ||
request.headers['Access-Control-Request-Headers'] ?? '*', | ||
}); | ||
return Response( | ||
204, | ||
Body.empty(), | ||
Headers({ | ||
...headers, | ||
'Access-Control-Allow-Methods': | ||
request.headers['Access-Control-Request-Method'] ?? methods, | ||
'Access-Control-Allow-Headers': | ||
request.headers['Access-Control-Request-Headers'] ?? ['*'], | ||
})); | ||
} | ||
return await _inner.handle(request) | ||
..headers.addAll(headers); | ||
return await _inner.handle(request..headers.addAll(headers)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.