Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e3b9094f
Commit
e3b9094f
authored
Nov 16, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #104 Support for setting HTTP headers
parent
d5e71f76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
20 deletions
+36
-20
http_post.dart
examples/widgets/http_post.dart
+10
-5
http.dart
packages/flutter/lib/src/http/http.dart
+17
-14
mojo_client.dart
packages/flutter/lib/src/http/mojo_client.dart
+9
-1
No files found.
examples/widgets/http_post.dart
View file @
e3b9094f
...
...
@@ -2,6 +2,8 @@
// 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.
import
'dart:async'
;
import
'package:flutter/http.dart'
as
http
;
import
'package:flutter/material.dart'
;
...
...
@@ -30,14 +32,17 @@ class PostDemoState extends State<PostDemo> {
super
.
initState
();
}
void
_refresh
()
{
Future
_refresh
()
async
{
setState
(()
{
_response
=
null
;
});
http
.
post
(
"http://httpbin.org/post"
,
body:
"asdf=42"
).
then
((
http
.
Response
response
)
{
setState
(()
{
_response
=
response
.
body
;
});
http
.
Response
response
=
await
http
.
post
(
"http://httpbin.org/post"
,
body:
"asdf=42"
,
headers:
{
"foo"
:
"bar"
}
);
setState
(()
{
_response
=
response
.
body
;
});
}
...
...
packages/flutter/lib/src/http/http.dart
View file @
e3b9094f
...
...
@@ -29,15 +29,16 @@ Future<Response> head(url) =>
/// This automatically initializes a new [Client] and closes that client once
/// the request is complete. If you're planning on making multiple requests to
/// the same server, you should use a single [Client] for all of those requests.
Future
<
Response
>
get
(
url
)
=>
_withClient
((
client
)
=>
client
.
get
(
url
));
Future
<
Response
>
get
(
url
,
{
Map
<
String
,
String
>
headers
}
)
=>
_withClient
((
client
)
=>
client
.
get
(
url
,
headers:
headers
));
/// Sends an HTTP POST request with the given headers and body to the given URL,
/// which can be a [Uri] or a [String].
///
/// [body] sets the body of the request.
Future
<
Response
>
post
(
url
,
{
body
})
=>
_withClient
((
client
)
=>
client
.
post
(
url
,
body:
body
));
Future
<
Response
>
post
(
url
,
{
Map
<
String
,
String
>
headers
,
body
})
=>
_withClient
((
client
)
=>
client
.
post
(
url
,
headers:
headers
,
body:
body
));
/// Sends an HTTP PUT request with the given headers and body to the given URL,
/// which can be a [Uri] or a [String].
...
...
@@ -46,8 +47,9 @@ Future<Response> post(url, {body}) =>
/// a [Map<String, String>]. If it's a String, it's encoded using [encoding] and
/// used as the body of the request. The content-type of the request will
/// default to "text/plain".
Future
<
Response
>
put
(
url
,
{
String
body
})
=>
_withClient
((
client
)
=>
client
.
put
(
url
,
body:
body
));
Future
<
Response
>
put
(
url
,
{
Map
<
String
,
String
>
headers
,
body
})
=>
_withClient
((
client
)
=>
client
.
put
(
url
,
headers:
headers
,
body:
body
));
/// Sends an HTTP PATCH request with the given headers and body to the given
/// URL, which can be a [Uri] or a [String].
...
...
@@ -68,8 +70,9 @@ Future<Response> put(url, {String body}) =>
///
/// For more fine-grained control over the request, use [Request] or
/// [StreamedRequest] instead.
Future
<
Response
>
patch
(
url
,
{
body
})
=>
_withClient
((
client
)
=>
client
.
patch
(
url
,
body:
body
));
Future
<
Response
>
patch
(
url
,
{
Map
<
String
,
String
>
headers
,
body
})
=>
_withClient
((
client
)
=>
client
.
patch
(
url
,
headers:
headers
,
body:
body
));
/// Sends an HTTP DELETE request with the given headers to the given URL, which
/// can be a [Uri] or a [String].
...
...
@@ -79,8 +82,8 @@ Future<Response> patch(url, { body }) =>
/// the same server, you should use a single [Client] for all of those requests.
///
/// For more fine-grained control over the request, use [Request] instead.
Future
<
Response
>
delete
(
url
)
=>
_withClient
((
client
)
=>
client
.
delete
(
url
));
Future
<
Response
>
delete
(
url
,
{
Map
<
String
,
String
>
headers
}
)
=>
_withClient
((
client
)
=>
client
.
delete
(
url
,
headers:
headers
));
/// Sends an HTTP GET request with the given headers to the given URL, which can
/// be a [Uri] or a [String], and returns a Future that completes to the body of
...
...
@@ -95,8 +98,8 @@ Future<Response> delete(url) =>
///
/// For more fine-grained control over the request and response, use [Request]
/// instead.
Future
<
String
>
read
(
url
)
=>
_withClient
((
client
)
=>
client
.
read
(
url
));
Future
<
String
>
read
(
url
,
{
Map
<
String
,
String
>
headers
}
)
=>
_withClient
((
client
)
=>
client
.
read
(
url
,
headers:
headers
));
/// Sends an HTTP GET request with the given headers to the given URL, which can
/// be a [Uri] or a [String], and returns a Future that completes to the body of
...
...
@@ -111,8 +114,8 @@ Future<String> read(url) =>
///
/// For more fine-grained control over the request and response, use [Request]
/// instead.
Future
<
Uint8List
>
readBytes
(
url
)
=>
_withClient
((
client
)
=>
client
.
readBytes
(
url
));
Future
<
Uint8List
>
readBytes
(
url
,
{
Map
<
String
,
String
>
headers
}
)
=>
_withClient
((
client
)
=>
client
.
readBytes
(
url
,
headers:
headers
));
Future
_withClient
(
Future
fn
(
MojoClient
client
))
{
var
client
=
new
MojoClient
();
...
...
packages/flutter/lib/src/http/mojo_client.dart
View file @
e3b9094f
...
...
@@ -12,6 +12,7 @@ import 'package:mojo_services/mojo/url_loader.mojom.dart' as mojo;
import
'package:mojo/core.dart'
as
mojo
;
import
'package:mojo/mojo/url_request.mojom.dart'
as
mojo
;
import
'package:mojo/mojo/url_response.mojom.dart'
as
mojo
;
import
'package:mojo/mojo/http_header.mojom.dart'
as
mojo
;
import
'response.dart'
;
...
...
@@ -63,10 +64,17 @@ class MojoClient {
Future
<
Response
>
_send
(
String
method
,
url
,
Map
<
String
,
String
>
headers
,
[
body
,
Encoding
encoding
])
async
{
mojo
.
UrlLoaderProxy
loader
=
new
mojo
.
UrlLoaderProxy
.
unbound
();
List
<
mojo
.
HttpHeader
>
mojoHeaders
=
<
mojo
.
HttpHeader
>[];
headers
.
forEach
((
String
name
,
String
value
)
{
mojo
.
HttpHeader
header
=
new
mojo
.
HttpHeader
()
..
name
=
name
..
value
=
value
;
mojoHeaders
.
add
(
header
);
});
mojo
.
UrlRequest
request
=
new
mojo
.
UrlRequest
()
..
url
=
url
.
toString
()
..
headers
=
mojoHeaders
..
method
=
method
;
if
(
body
!=
null
)
{
mojo
.
MojoDataPipe
pipe
=
new
mojo
.
MojoDataPipe
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment