Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 14595008: Fix digest authentication to use the correct URI (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/http_auth_digest_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpIncoming extends Stream<List<int>> { 7 class _HttpIncoming extends Stream<List<int>> {
8 final int _transferLength; 8 final int _transferLength;
9 final Completer _dataCompleter = new Completer(); 9 final Completer _dataCompleter = new Completer();
10 Stream<List<int>> _stream; 10 Stream<List<int>> _stream;
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 (v) => _responseCompleter.complete(v), 907 (v) => _responseCompleter.complete(v),
908 onError: (e) { 908 onError: (e) {
909 _responseCompleter.completeError(e); 909 _responseCompleter.completeError(e);
910 }); 910 });
911 } 911 }
912 912
913 void _onError(error) { 913 void _onError(error) {
914 _responseCompleter.completeError(error); 914 _responseCompleter.completeError(error);
915 } 915 }
916 916
917 // Generate the request URI based on the method and proxy.
918 String _requestUri() {
919 // Generate the request URI starting from the path component.
920 String uriStartingFromPath() {
921 String result = uri.path;
922 if (result.length == 0) result = "/";
923 if (uri.query != "") {
924 if (uri.fragment != "") {
925 result = "${result}?${uri.query}#${uri.fragment}";
926 } else {
927 result = "${result}?${uri.query}";
928 }
929 }
930 return result;
931 }
932
933 if (_proxy.isDirect) {
934 return uriStartingFromPath();
935 } else {
936 if (method == "CONNECT") {
937 // For the connect method the request URI is the host:port of
938 // the requested destination of the tunnel (see RFC 2817
939 // section 5.2)
940 return "${uri.domain}:${uri.port}";
941 } else {
942 if (_httpClientConnection._proxyTunnel) {
943 return uriStartingFromPath();
944 } else {
945 return uri.toString();
946 }
947 }
948 }
949 }
950
917 void _writeHeader() { 951 void _writeHeader() {
918 var buffer = new _BufferList(); 952 var buffer = new _BufferList();
919 953
920 writeSP() => buffer.add(const [_CharCode.SP]); 954 writeSP() => buffer.add(const [_CharCode.SP]);
921 955
922 writeCRLF() => buffer.add(const [_CharCode.CR, _CharCode.LF]); 956 writeCRLF() => buffer.add(const [_CharCode.CR, _CharCode.LF]);
923 957
924 void writePath() {
925 String path = uri.path;
926 if (path.length == 0) path = "/";
927 if (uri.query != "") {
928 if (uri.fragment != "") {
929 path = "${path}?${uri.query}#${uri.fragment}";
930 } else {
931 path = "${path}?${uri.query}";
932 }
933 }
934 buffer.add(path.codeUnits);
935 }
936
937 // Write the request method. 958 // Write the request method.
938 buffer.add(method.codeUnits); 959 buffer.add(method.codeUnits);
939 writeSP(); 960 writeSP();
940 // Write the request URI. 961 // Write the request URI.
941 if (_proxy.isDirect) { 962 buffer.add(_requestUri().codeUnits);
942 writePath();
943 } else {
944 if (method == "CONNECT") {
945 // For the connect method the request URI is the host:port of
946 // the requested destination of the tunnel (see RFC 2817
947 // section 5.2)
948 buffer.add(uri.domain.codeUnits);
949 buffer.add(const [_CharCode.COLON]);
950 buffer.add(uri.port.toString().codeUnits);
951 } else {
952 if (_httpClientConnection._proxyTunnel) {
953 writePath();
954 } else {
955 buffer.add(uri.toString().codeUnits);
956 }
957 }
958 }
959 writeSP(); 963 writeSP();
964 // Write HTTP/1.1.
960 buffer.add(_Const.HTTP11); 965 buffer.add(_Const.HTTP11);
961 writeCRLF(); 966 writeCRLF();
962 967
963 // Add the cookies to the headers. 968 // Add the cookies to the headers.
964 if (!cookies.isEmpty) { 969 if (!cookies.isEmpty) {
965 StringBuffer sb = new StringBuffer(); 970 StringBuffer sb = new StringBuffer();
966 for (int i = 0; i < cookies.length; i++) { 971 for (int i = 0; i < cookies.length; i++) {
967 if (i > 0) sb.write("; "); 972 if (i > 0) sb.write("; ");
968 sb.write(cookies[i].name); 973 sb.write(cookies[i].name);
969 sb.write("="); 974 sb.write("=");
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 2132
2128 class _HttpClientDigestCredentials 2133 class _HttpClientDigestCredentials
2129 extends _HttpClientCredentials 2134 extends _HttpClientCredentials
2130 implements HttpClientDigestCredentials { 2135 implements HttpClientDigestCredentials {
2131 _HttpClientDigestCredentials(this.username, 2136 _HttpClientDigestCredentials(this.username,
2132 this.password); 2137 this.password);
2133 2138
2134 _AuthenticationScheme get scheme => _AuthenticationScheme.DIGEST; 2139 _AuthenticationScheme get scheme => _AuthenticationScheme.DIGEST;
2135 2140
2136 String authorization(_Credentials credentials, HttpClientRequest request) { 2141 String authorization(_Credentials credentials, HttpClientRequest request) {
2142 String requestUri = request._requestUri();
2137 MD5 hasher = new MD5(); 2143 MD5 hasher = new MD5();
2138 hasher.add(request.method.codeUnits); 2144 hasher.add(request.method.codeUnits);
2139 hasher.add([_CharCode.COLON]); 2145 hasher.add([_CharCode.COLON]);
2140 hasher.add(request.uri.path.codeUnits); 2146 hasher.add(requestUri.codeUnits);
2141 var ha2 = CryptoUtils.bytesToHex(hasher.close()); 2147 var ha2 = CryptoUtils.bytesToHex(hasher.close());
2142 2148
2143 String qop; 2149 String qop;
2144 String cnonce; 2150 String cnonce;
2145 String nc; 2151 String nc;
2146 var x; 2152 var x;
2147 hasher = new MD5(); 2153 hasher = new MD5();
2148 hasher.add(credentials.ha1.codeUnits); 2154 hasher.add(credentials.ha1.codeUnits);
2149 hasher.add([_CharCode.COLON]); 2155 hasher.add([_CharCode.COLON]);
2150 if (credentials.qop == "auth") { 2156 if (credentials.qop == "auth") {
(...skipping 16 matching lines...) Expand all
2167 hasher.add([_CharCode.COLON]); 2173 hasher.add([_CharCode.COLON]);
2168 hasher.add(ha2.codeUnits); 2174 hasher.add(ha2.codeUnits);
2169 } 2175 }
2170 var response = CryptoUtils.bytesToHex(hasher.close()); 2176 var response = CryptoUtils.bytesToHex(hasher.close());
2171 2177
2172 StringBuffer buffer = new StringBuffer(); 2178 StringBuffer buffer = new StringBuffer();
2173 buffer.write('Digest '); 2179 buffer.write('Digest ');
2174 buffer.write('username="$username"'); 2180 buffer.write('username="$username"');
2175 buffer.write(', realm="${credentials.realm}"'); 2181 buffer.write(', realm="${credentials.realm}"');
2176 buffer.write(', nonce="${credentials.nonce}"'); 2182 buffer.write(', nonce="${credentials.nonce}"');
2177 buffer.write(', uri="${request.uri.path}"'); 2183 buffer.write(', uri="$requestUri"');
2178 buffer.write(', algorithm="${credentials.algorithm}"'); 2184 buffer.write(', algorithm="${credentials.algorithm}"');
2179 if (qop == "auth") { 2185 if (qop == "auth") {
2180 buffer.write(', qop="$qop"'); 2186 buffer.write(', qop="$qop"');
2181 buffer.write(', cnonce="$cnonce"'); 2187 buffer.write(', cnonce="$cnonce"');
2182 buffer.write(', nc="$nc"'); 2188 buffer.write(', nc="$nc"');
2183 } 2189 }
2184 buffer.write(', response="$response"'); 2190 buffer.write(', response="$response"');
2185 return buffer.toString(); 2191 return buffer.toString();
2186 } 2192 }
2187 2193
(...skipping 13 matching lines...) Expand all
2201 2207
2202 2208
2203 class _RedirectInfo implements RedirectInfo { 2209 class _RedirectInfo implements RedirectInfo {
2204 const _RedirectInfo(int this.statusCode, 2210 const _RedirectInfo(int this.statusCode,
2205 String this.method, 2211 String this.method,
2206 Uri this.location); 2212 Uri this.location);
2207 final int statusCode; 2213 final int statusCode;
2208 final String method; 2214 final String method;
2209 final Uri location; 2215 final Uri location;
2210 } 2216 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_auth_digest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698