Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaiyang committed Dec 15, 2019
1 parent 5a516e9 commit 9cc8404
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Q.dart - A service framework written by dart
### 开发中

## TODO
+ `http request options method`

## How to use
```cli
--application.environment=dev --application.resourceDir=/example/resources/
Expand Down
1 change: 1 addition & 0 deletions lib/src/annotation/Annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'package:Q/src/annotation/Controller.dart';
export 'package:Q/src/annotation/CookieValue.dart';
export 'package:Q/src/annotation/Model.dart';
export 'package:Q/src/annotation/PathVariable.dart';
export 'package:Q/src/annotation/RawBody.dart';
export 'package:Q/src/annotation/RequestHeader.dart';
export 'package:Q/src/annotation/RequestParam.dart';
export 'package:Q/src/annotation/SessionValue.dart';
Expand Down
5 changes: 5 additions & 0 deletions lib/src/annotation/RawBody.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@pragma('vm:entry-point')
class RawBody {
@pragma('vm:entry-point')
const RawBody();
}
2 changes: 2 additions & 0 deletions lib/src/handler/OKHandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class OKHandler implements HandlerAdapter {
httpResponse.headers.contentType = context?.router?.produceType != null
? context.router.produceType
: Application.getApplicationContext().configuration.httpResponseConfigure.defaultProducedType;
httpResponse.headers.add('Access-Control-Allow-Origin', '*');
httpResponse.headers.add('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
httpResponse.write(context.response.responseEntry.convertedResult);
return context;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/helpers/AnnotationHelpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ List<Type> SUPPORTED_ROUTER_HANDLER_PARAMETER_ANNOTATIONS = [
UrlParam,
SessionValue,
Config,
Body
Body,
RawBody,
];

List<ClassMirror> SUPPORTED_ROUTER_HANDLER_PARAMETER_ANNOTATION_CLASSES =
Expand Down
6 changes: 6 additions & 0 deletions lib/src/helpers/RouterHelper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:mirrors';

import 'package:Q/Q.dart';
import 'package:Q/src/Application.dart';
import 'package:Q/src/Redirect.dart';
import 'package:Q/src/Router.dart';
Expand All @@ -21,6 +22,7 @@ import 'package:Q/src/helpers/reflect/BodyReflectHelper.dart';
import 'package:Q/src/helpers/reflect/ConfigValueHelper.dart';
import 'package:Q/src/helpers/reflect/CookieValueHelper.dart';
import 'package:Q/src/helpers/reflect/PathVariableHelper.dart';
import 'package:Q/src/helpers/reflect/RawBodyHelper.dart';
import 'package:Q/src/helpers/reflect/RequestHeaderHelper.dart';
import 'package:Q/src/helpers/reflect/RequestParamHelper.dart';
import 'package:Q/src/helpers/reflect/SessionValueHelper.dart';
Expand Down Expand Up @@ -125,6 +127,10 @@ class RouterHelper {
futures.add(Function.apply(BodyReflectHelper.reflectBody, params));
break;
}
if (type == reflectClass(RawBody)) {
futures.add(Function.apply(RawBodyHelper.reflect, params));
break;
}
}
}
});
Expand Down
1 change: 0 additions & 1 deletion lib/src/helpers/reflect/BodyReflectHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:Q/src/Router.dart';
import 'package:Q/src/helpers/reflect/ClassTransformer.dart';

class BodyReflectHelper {
// 通过反射获取使用RequestParam注解的参数
static Future<dynamic> reflectBody(Router router, ParameterMirror parameterMirror, InstanceMirror annotationMirror) async {
if (annotationMirror != null) {
Map data = router?.context?.request?.data;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/helpers/reflect/RawBodyHelper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:mirrors';

import 'package:Q/src/Router.dart';

class RawBodyHelper {
static Future<dynamic> reflect(Router router, ParameterMirror parameterMirror, InstanceMirror annotationMirror) async {
if (annotationMirror != null) {
return router?.context?.request?.data;
}
}
}

0 comments on commit 9cc8404

Please # to comment.