Removed HttpHeaders in ResponseContext

This commit is contained in:
Tobe O 2018-02-07 00:22:15 -05:00
parent 9b7bf84acf
commit 25dc29e126
2 changed files with 33 additions and 35 deletions

View file

@ -2,11 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="7b89ff1e-1260-4dcf-9c3d-345de0471ea1" name="Default" comment=""> <list default="true" id="7b89ff1e-1260-4dcf-9c3d-345de0471ea1" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/src/http/http_response_context.dart" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/angel_http.dart" afterPath="$PROJECT_DIR$/lib/src/http/angel_http.dart" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/response_context.dart" afterPath="$PROJECT_DIR$/lib/src/http/response_context.dart" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/response_context.dart" afterPath="$PROJECT_DIR$/lib/src/http/response_context.dart" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/src/http/server.dart" afterPath="$PROJECT_DIR$/lib/src/http/server.dart" />
</list> </list>
<ignored path="$PROJECT_DIR$/.tmp/" /> <ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" /> <ignored path="$PROJECT_DIR$/temp/" />
@ -34,8 +31,8 @@
<file leaf-file-name="response_context.dart" pinned="false" current-in-tab="true"> <file leaf-file-name="response_context.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/src/http/response_context.dart"> <entry file="file://$PROJECT_DIR$/lib/src/http/response_context.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402"> <state relative-caret-position="231">
<caret line="151" column="5" lean-forward="true" selection-start-line="151" selection-start-column="5" selection-end-line="151" selection-end-column="5" /> <caret line="26" column="28" lean-forward="true" selection-start-line="26" selection-start-column="28" selection-end-line="26" selection-end-column="28" />
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -83,7 +80,6 @@
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>dispos</find>
<find>xhr</find> <find>xhr</find>
<find>accepts</find> <find>accepts</find>
<find>cacheKey</find> <find>cacheKey</find>
@ -113,6 +109,7 @@
<find>isOpen</find> <find>isOpen</find>
<find>_useStream</find> <find>_useStream</find>
<find>isClosed</find> <find>isClosed</find>
<find>HttpHeaders.</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>_isClosed</replace> <replace>_isClosed</replace>
@ -140,6 +137,7 @@
<replace>useStream</replace> <replace>useStream</replace>
<replace>streaming</replace> <replace>streaming</replace>
<replace>!isOpen</replace> <replace>!isOpen</replace>
<replace>'server'</replace>
</replaceStrings> </replaceStrings>
<dirStrings> <dirStrings>
<dir>C:\Users\thosa\Source\Angel\framework\lib</dir> <dir>C:\Users\thosa\Source\Angel\framework\lib</dir>
@ -215,8 +213,8 @@
<option value="$PROJECT_DIR$/lib/src/http/http_request_context.dart" /> <option value="$PROJECT_DIR$/lib/src/http/http_request_context.dart" />
<option value="$PROJECT_DIR$/lib/src/http/angel_http.dart" /> <option value="$PROJECT_DIR$/lib/src/http/angel_http.dart" />
<option value="$PROJECT_DIR$/lib/src/http/server.dart" /> <option value="$PROJECT_DIR$/lib/src/http/server.dart" />
<option value="$PROJECT_DIR$/lib/src/http/response_context.dart" />
<option value="$PROJECT_DIR$/lib/src/http/http_response_context.dart" /> <option value="$PROJECT_DIR$/lib/src/http/http_response_context.dart" />
<option value="$PROJECT_DIR$/lib/src/http/response_context.dart" />
</list> </list>
</option> </option>
</component> </component>
@ -630,14 +628,7 @@
<workItem from="1513103483207" duration="18000" /> <workItem from="1513103483207" duration="18000" />
<workItem from="1513103506825" duration="139000" /> <workItem from="1513103506825" duration="139000" />
<workItem from="1517332581856" duration="858000" /> <workItem from="1517332581856" duration="858000" />
<workItem from="1517973177718" duration="7635000" /> <workItem from="1517973177718" duration="7703000" />
</task>
<task id="LOCAL-00015" summary="+1">
<created>1497200256280</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1497200256280</updated>
</task> </task>
<task id="LOCAL-00016" summary="1.0.4"> <task id="LOCAL-00016" summary="1.0.4">
<created>1497837231709</created> <created>1497837231709</created>
@ -975,7 +966,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1517979599468</updated> <updated>1517979599468</updated>
</task> </task>
<option name="localTasksCounter" value="64" /> <task id="LOCAL-00064" summary="Deprecated `ResponseContext.io`, added HTTP equivalent">
<created>1517980874143</created>
<option name="number" value="00064" />
<option name="presentableId" value="LOCAL-00064" />
<option name="project" value="LOCAL" />
<updated>1517980874143</updated>
</task>
<option name="localTasksCounter" value="65" />
<servers /> <servers />
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
@ -1011,7 +1009,7 @@
</history-entry> </history-entry>
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="125671000" /> <option name="totallyTimeSpent" value="125739000" />
</component> </component>
<component name="TodoView"> <component name="TodoView">
<todo-panel id="selected-file"> <todo-panel id="selected-file">
@ -1070,7 +1068,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value="+6" />
<MESSAGE value="autoIdAndDateFields in MapService" /> <MESSAGE value="autoIdAndDateFields in MapService" />
<MESSAGE value="+8" /> <MESSAGE value="+8" />
<MESSAGE value="+9" /> <MESSAGE value="+9" />
@ -1095,7 +1092,8 @@
<MESSAGE value="Added example/main.dart" /> <MESSAGE value="Added example/main.dart" />
<MESSAGE value="Create HttpRequestContextImpl" /> <MESSAGE value="Create HttpRequestContextImpl" />
<MESSAGE value="Change return type of `AngelHttp.createRequestContext`" /> <MESSAGE value="Change return type of `AngelHttp.createRequestContext`" />
<option name="LAST_COMMIT_MESSAGE" value="Change return type of `AngelHttp.createRequestContext`" /> <MESSAGE value="Deprecated `ResponseContext.io`, added HTTP equivalent" />
<option name="LAST_COMMIT_MESSAGE" value="Deprecated `ResponseContext.io`, added HTTP equivalent" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -1521,8 +1519,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/src/http/response_context.dart"> <entry file="file://$PROJECT_DIR$/lib/src/http/response_context.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="402"> <state relative-caret-position="231">
<caret line="151" column="5" lean-forward="true" selection-start-line="151" selection-start-column="5" selection-end-line="151" selection-end-column="5" /> <caret line="26" column="28" lean-forward="true" selection-start-line="26" selection-start-column="28" selection-end-line="26" selection-end-column="28" />
<folding /> <folding />
</state> </state>
</provider> </provider>

View file

@ -26,7 +26,7 @@ typedef String ResponseSerializer(data);
abstract class ResponseContext implements StreamSink<List<int>>, StringSink { abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
final Map properties = {}; final Map properties = {};
final BytesBuilder _buffer = new _LockableBytesBuilder(); final BytesBuilder _buffer = new _LockableBytesBuilder();
final Map<String, String> _headers = {HttpHeaders.SERVER: 'angel'}; final Map<String, String> _headers = {'server': 'angel'};
Completer _done; Completer _done;
int _statusCode = 200; int _statusCode = 200;
@ -98,9 +98,9 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
/// Gets the Content-Type header. /// Gets the Content-Type header.
ContentType get contentType { ContentType get contentType {
if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) return null; if (!headers.containsKey('content-type')) return null;
var header = headers[HttpHeaders.CONTENT_TYPE]; var header = headers['content-type'];
var match = _contentType.firstMatch(header); var match = _contentType.firstMatch(header);
if (match == null) if (match == null)
@ -114,7 +114,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
/// Sets the Content-Type header. /// Sets the Content-Type header.
void set contentType(ContentType contentType) { void set contentType(ContentType contentType) {
headers[HttpHeaders.CONTENT_TYPE] = contentType.toString(); headers['content-type'] = contentType.toString();
} }
/// Set this to true if you will manually close the response. /// Set this to true if you will manually close the response.
@ -130,8 +130,8 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
headers["Content-Disposition"] = headers["Content-Disposition"] =
'attachment; filename="${filename ?? file.path}"'; 'attachment; filename="${filename ?? file.path}"';
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path); headers['content-type'] = lookupMimeType(file.path);
headers[HttpHeaders.CONTENT_LENGTH] = file.lengthSync().toString(); headers['content-length'] = file.lengthSync().toString();
if (streaming) { if (streaming) {
await file.openRead().pipe(this); await file.openRead().pipe(this);
@ -188,9 +188,9 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
if (contentType is ContentType) if (contentType is ContentType)
this.contentType = contentType; this.contentType = contentType;
else else
headers[HttpHeaders.CONTENT_TYPE] = contentType.toString(); headers['content-type'] = contentType.toString();
} else } else
headers[HttpHeaders.CONTENT_TYPE] = 'application/javascript'; headers['content-type'] = 'application/javascript';
end(); end();
} }
@ -199,7 +199,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
Future render(String view, [Map data]) async { Future render(String view, [Map data]) async {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
write(await app.viewGenerator(view, data)); write(await app.viewGenerator(view, data));
headers[HttpHeaders.CONTENT_TYPE] = ContentType.HTML.toString(); headers['content-type'] = ContentType.HTML.toString();
end(); end();
} }
@ -213,8 +213,8 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
void redirect(url, {bool absolute: true, int code: 302}) { void redirect(url, {bool absolute: true, int code: 302}) {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
headers headers
..[HttpHeaders.CONTENT_TYPE] = ContentType.HTML.toString() ..['content-type'] = ContentType.HTML.toString()
..[HttpHeaders.LOCATION] = ..['location'] =
url is String ? url : app.navigate(url, absolute: absolute); url is String ? url : app.navigate(url, absolute: absolute);
statusCode = code ?? 302; statusCode = code ?? 302;
write(''' write('''
@ -295,7 +295,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
Future sendFile(File file) async { Future sendFile(File file) async {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path); headers['content-type'] = lookupMimeType(file.path);
buffer.add(await file.readAsBytes()); buffer.add(await file.readAsBytes());
end(); end();
} }
@ -312,7 +312,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
return; return;
if (contentType is String) if (contentType is String)
headers[HttpHeaders.CONTENT_TYPE] = contentType; headers['content-type'] = contentType;
else if (contentType is ContentType) this.contentType = contentType; else if (contentType is ContentType) this.contentType = contentType;
write(text); write(text);
@ -326,7 +326,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
Future streamFile(File file) { Future streamFile(File file) {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path); headers['content-type'] = lookupMimeType(file.path);
return file.openRead().pipe(this); return file.openRead().pipe(this);
} }