Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion links/gql_http_link/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HttpLinkResponseContext extends ContextEntry {
/// [http.Client] to the constructor.
class HttpLink extends Link {
/// Endpoint of the GraphQL service
final Uri uri;
Uri uri;

/// Default HTTP headers
final Map<String, String> defaultHeaders;
Expand Down Expand Up @@ -167,6 +167,12 @@ class HttpLink extends Link {
final httpRequest = _prepareRequest(request);
try {
final response = await _httpClient!.send(httpRequest);
if (response.statusCode == 301 || response.statusCode == 302) {
// `location` header will never be null on statusCode 301 or 302.
// More info. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302
uri = Uri.parse(response.headers["location"]!);
return _executeRequest(request);
}
return http.Response.fromStream(response);
} catch (e) {
throw ServerException(
Expand Down Expand Up @@ -220,10 +226,12 @@ class HttpLink extends Link {
return http.MultipartRequest("POST", uri)
..body = httpBody
..addAllFiles(fileMap)
..followRedirects = true
..headers.addAll(headers);
}
return http.Request("POST", uri)
..body = httpBody
..followRedirects = true
..headers.addAll(headers);
}

Expand Down