OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 for (String str : strs) { | 111 for (String str : strs) { |
112 int index = str.indexOf('-'); | 112 int index = str.indexOf('-'); |
113 | 113 |
114 try { | 114 try { |
115 if (index == 0) { | 115 if (index == 0) { |
116 result.add(new int[] {0, Integer.parseInt(str.substring(1))}); | 116 result.add(new int[] {0, Integer.parseInt(str.substring(1))}); |
117 } else if (index == str.length() - 1) { | 117 } else if (index == str.length() - 1) { |
118 result.add(new int[] {Integer.parseInt(str.substring(0, index)),
-1}); | 118 result.add(new int[] {Integer.parseInt(str.substring(0, index)),
-1}); |
119 } else if (index != -1) { | 119 } else if (index != -1) { |
120 result.add( | 120 result.add(new int[] { |
121 new int[] { | 121 Integer.parseInt(str.substring(0, index)), |
122 Integer.parseInt(str.substring(0, index)), | 122 Integer.parseInt(str.substring(index + 1))}); |
123 Integer.parseInt(str.substring(index + 1))}); | |
124 } | 123 } |
125 } catch (NumberFormatException nfe) { | 124 } catch (NumberFormatException nfe) { |
126 | 125 |
127 } | 126 } |
128 } | 127 } |
129 | 128 |
130 return result; | 129 return result; |
131 } | 130 } |
132 } | 131 } |
133 | 132 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 225 |
227 private static byte[] AGENT_CONTENT; | 226 private static byte[] AGENT_CONTENT; |
228 | 227 |
229 /** | 228 /** |
230 * Special resources to serve - i.e. non-workspace resources. | 229 * Special resources to serve - i.e. non-workspace resources. |
231 */ | 230 */ |
232 private static final String[][] embeddedResources = new String[][] { | 231 private static final String[][] embeddedResources = new String[][] { |
233 {"/favicon.ico", TYPE_GIF, "/resources/favicon.ico"}, | 232 {"/favicon.ico", TYPE_GIF, "/resources/favicon.ico"}, |
234 {"/dart_16_16.gif", TYPE_GIF, "/resources/dart_16_16.gif"}, | 233 {"/dart_16_16.gif", TYPE_GIF, "/resources/dart_16_16.gif"}, |
235 {"/dart_32_32.gif", TYPE_GIF, "/resources/dart_32_32.gif"}, | 234 {"/dart_32_32.gif", TYPE_GIF, "/resources/dart_32_32.gif"}, |
236 {"/agent.html", TYPE_HTML, "agent.html"}, {"/agent.js", TYPE_JS, "agent.js
"}, { | 235 {"/agent.html", TYPE_HTML, "agent.html"}, |
237 "/apple-touch-icon-precomposed.png", TYPE_PNG, | 236 {"/agent.js", TYPE_JS, "agent.js"}, |
238 "/resources/apple-touch-icon-precomposed.png"}}; | 237 {"/apple-touch-icon-precomposed.png", TYPE_PNG, "/resources/apple-touch-ic
on-precomposed.png"}}; |
239 | 238 |
240 @SuppressWarnings("unused") | 239 @SuppressWarnings("unused") |
241 private static byte[] getJSAgentContent() { | 240 private static byte[] getJSAgentContent() { |
242 if (AGENT_CONTENT == null) { | 241 if (AGENT_CONTENT == null) { |
243 try { | 242 try { |
244 AGENT_CONTENT = ByteStreams.toByteArray( | 243 AGENT_CONTENT = ByteStreams.toByteArray(ResourceServer.class.getResource
AsStream("agent.js")); |
245 ResourceServer.class.getResourceAsStream("agent.js")); | |
246 } catch (IOException e) { | 244 } catch (IOException e) { |
247 DartDebugCorePlugin.logError(e); | 245 DartDebugCorePlugin.logError(e); |
248 | 246 |
249 AGENT_CONTENT = new byte[0]; | 247 AGENT_CONTENT = new byte[0]; |
250 } | 248 } |
251 } | 249 } |
252 | 250 |
253 return AGENT_CONTENT; | 251 return AGENT_CONTENT; |
254 } | 252 } |
255 | 253 |
256 private static void setupExtraMappings() { | 254 private static void setupExtraMappings() { |
257 extraMappings = new HashMap<String, String>(); | 255 extraMappings = new HashMap<String, String>(); |
258 | 256 |
259 try { | 257 try { |
260 BufferedReader reader = new BufferedReader( | 258 BufferedReader reader = new BufferedReader(new InputStreamReader( |
261 new InputStreamReader(ResourceServerHandler.class.getResourceAsStream(
"mime.txt"))); | 259 ResourceServerHandler.class.getResourceAsStream("mime.txt"))); |
262 | 260 |
263 String line = reader.readLine(); | 261 String line = reader.readLine(); |
264 | 262 |
265 while (line != null) { | 263 while (line != null) { |
266 String[] strs = line.split(" "); | 264 String[] strs = line.split(" "); |
267 | 265 |
268 extraMappings.put(strs[0], strs[1]); | 266 extraMappings.put(strs[0], strs[1]); |
269 | 267 |
270 line = reader.readLine(); | 268 line = reader.readLine(); |
271 } | 269 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 byte[] rangeData = readRangeData(javaFile, ranges); | 459 byte[] rangeData = readRangeData(javaFile, ranges); |
462 | 460 |
463 response.responseBodyStream = new ByteArrayInputStream(rangeData); | 461 response.responseBodyStream = new ByteArrayInputStream(rangeData); |
464 | 462 |
465 response.responseCode = HttpResponse.PARTIAL_CONTENT; | 463 response.responseCode = HttpResponse.PARTIAL_CONTENT; |
466 response.responseText = "Partial Content"; | 464 response.responseText = "Partial Content"; |
467 | 465 |
468 response.headers.put(CONTENT_LENGTH, Long.toString(rangeData.length)); | 466 response.headers.put(CONTENT_LENGTH, Long.toString(rangeData.length)); |
469 // Content-Range: bytes X-Y/Z | 467 // Content-Range: bytes X-Y/Z |
470 int[] range = ranges.get(0); | 468 int[] range = ranges.get(0); |
471 response.headers.put( | 469 response.headers.put(CONTENT_RANGE, "bytes " + range[0] + "-" + range[1]
+ "/" |
472 CONTENT_RANGE, | 470 + rangeData.length); |
473 "bytes " + range[0] + "-" + range[1] + "/" + rangeData.length); | |
474 } else { | 471 } else { |
475 response.responseBodyStream = new FileInputStream(javaFile); | 472 response.responseBodyStream = new FileInputStream(javaFile); |
476 } | 473 } |
477 | 474 |
478 // Indicate that we support requesting a subset of the document. | 475 // Indicate that we support requesting a subset of the document. |
479 response.headers.put(ACCEPT_RANGES, "bytes"); | 476 response.headers.put(ACCEPT_RANGES, "bytes"); |
480 // } | 477 // } |
481 } | 478 } |
482 | 479 |
483 addStandardResponseHeaders(response); | 480 addStandardResponseHeaders(response); |
484 | 481 |
485 return response; | 482 return response; |
486 } | 483 } |
487 | 484 |
488 private HttpResponse createNotAllowedResponse() { | 485 private HttpResponse createNotAllowedResponse() { |
489 HttpResponse response = new HttpResponse(); | 486 HttpResponse response = new HttpResponse(); |
490 | 487 |
491 response.responseCode = HttpResponse.UNAUTHORIZED; | 488 response.responseCode = HttpResponse.UNAUTHORIZED; |
492 response.responseText = "Unauthorized"; | 489 response.responseText = "Unauthorized"; |
493 | 490 |
494 response.headers.put(CONTENT_TYPE, "text/html"); | 491 response.headers.put(CONTENT_TYPE, "text/html"); |
495 response.responseBodyText = "<html><head><title>401 Unauthorized</title></he
ad><body>User agent not allowed.</body></html>"; | 492 response.responseBodyText = "<html><head><title>401 Unauthorized</title></he
ad><body>User agent not allowed.</body></html>"; |
496 response.headers.put(CONTENT_LENGTH, Integer.toString(response.responseBodyT
ext.length())); | 493 response.headers.put(CONTENT_LENGTH, Integer.toString(response.responseBodyT
ext.length())); |
497 | 494 |
498 addStandardResponseHeaders(response); | 495 addStandardResponseHeaders(response); |
499 | 496 |
500 return response; | 497 return response; |
501 } | 498 } |
502 | 499 |
503 private HttpResponse createPOSTResponse(HttpHeader header, DataInputStream in) | 500 private HttpResponse createPOSTResponse(HttpHeader header, DataInputStream in)
throws IOException { |
504 throws IOException { | |
505 // This 200000 value matches Jetty's setting. | 501 // This 200000 value matches Jetty's setting. |
506 final int MAX_POST = 200000 + 100; | 502 final int MAX_POST = 200000 + 100; |
507 | 503 |
508 String file = header.file; | 504 String file = header.file; |
509 | 505 |
510 int length = header.getContentLength(); | 506 int length = header.getContentLength(); |
511 | 507 |
512 if (length > MAX_POST) { | 508 if (length > MAX_POST) { |
513 return createErrorResponse("Invalid POST length"); | 509 return createErrorResponse("Invalid POST length"); |
514 } | 510 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 InetAddress remoteAddress = connection.getInetAddress(); | 664 InetAddress remoteAddress = connection.getInetAddress(); |
669 | 665 |
670 if (isLocalAddress(remoteAddress)) { | 666 if (isLocalAddress(remoteAddress)) { |
671 return true; | 667 return true; |
672 } | 668 } |
673 | 669 |
674 // User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536
.8 (KHTML, like Gecko) Chrome/20.0.1110.0 (Dart) Safari/536.8 | 670 // User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536
.8 (KHTML, like Gecko) Chrome/20.0.1110.0 (Dart) Safari/536.8 |
675 if (DartDebugCorePlugin.getPlugin().getUserAgentManager() != null) { | 671 if (DartDebugCorePlugin.getPlugin().getUserAgentManager() != null) { |
676 String userAgent = header.headers.get(USER_AGENT); | 672 String userAgent = header.headers.get(USER_AGENT); |
677 | 673 |
678 boolean allowed = DartDebugCorePlugin.getPlugin() | 674 boolean allowed = DartDebugCorePlugin.getPlugin().getUserAgentManager().al
lowUserAgent( |
679 .getUserAgentManager().allowUserAgent(remoteAddress, userAgent); | 675 remoteAddress, |
| 676 userAgent); |
680 | 677 |
681 if (allowed) { | 678 if (allowed) { |
682 resourceServer.loadingContentFrom(remoteAddress.getHostAddress(), userAg
ent); | 679 resourceServer.loadingContentFrom(remoteAddress.getHostAddress(), userAg
ent); |
683 } | 680 } |
684 | 681 |
685 return allowed; | 682 return allowed; |
686 } | 683 } |
687 | 684 |
688 return false; | 685 return false; |
689 } | 686 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 return null; | 748 return null; |
752 } | 749 } |
753 | 750 |
754 IPath childPath = path.removeFirstSegments(1); | 751 IPath childPath = path.removeFirstSegments(1); |
755 | 752 |
756 File file = new File(projectLocation.toFile(), childPath.toOSString()); | 753 File file = new File(projectLocation.toFile(), childPath.toOSString()); |
757 | 754 |
758 if (!file.exists() && childPath.toString().contains(DartCore.PACKAGES_DIRECT
ORY_PATH)) { | 755 if (!file.exists() && childPath.toString().contains(DartCore.PACKAGES_DIRECT
ORY_PATH)) { |
759 | 756 |
760 int packagesIndex = childPath.toString().indexOf(DartCore.PACKAGES_DIRECTO
RY_PATH); | 757 int packagesIndex = childPath.toString().indexOf(DartCore.PACKAGES_DIRECTO
RY_PATH); |
761 String pathString = childPath.toString() | 758 String pathString = childPath.toString().substring( |
762 .substring(packagesIndex + DartCore.PACKAGES_DIRECTORY_PATH.length()); | 759 packagesIndex + DartCore.PACKAGES_DIRECTORY_PATH.length()); |
763 IFileInfo fileInfo = DartCore.getProjectManager() | 760 IFileInfo fileInfo = DartCore.getProjectManager().resolveUriToFileInfo( |
764 .resolveUriToFileInfo(project, DartCore.PACKAGE_SCHEME_SPEC + pathStri
ng); | 761 project, |
| 762 DartCore.PACKAGE_SCHEME_SPEC + pathString); |
765 if (fileInfo != null) { | 763 if (fileInfo != null) { |
766 file = fileInfo.getFile(); | 764 file = fileInfo.getFile(); |
767 } | 765 } |
768 } | 766 } |
769 | 767 |
770 return file.exists() ? file : null; | 768 return file.exists() ? file : null; |
771 } | 769 } |
772 | 770 |
773 private IResource locateMappedFile(File file) { | 771 private IResource locateMappedFile(File file) { |
774 IResource resource = ResourcesPlugin.getWorkspace() | 772 IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLoca
tion( |
775 .getRoot().getFileForLocation(Path.fromOSString(file.getAbsolutePath()))
; | 773 Path.fromOSString(file.getAbsolutePath())); |
776 | 774 |
777 if (resource instanceof IFile) { | 775 if (resource instanceof IFile) { |
778 IFile resourceFile = (IFile) resource; | 776 IFile resourceFile = (IFile) resource; |
779 | 777 |
780 String mappingPath = DartCore.getResourceRemapping(resourceFile); | 778 String mappingPath = DartCore.getResourceRemapping(resourceFile); |
781 | 779 |
782 if (mappingPath != null) { | 780 if (mappingPath != null) { |
783 IResource mappedResource = ResourcesPlugin.getWorkspace() | 781 IResource mappedResource = ResourcesPlugin.getWorkspace().getRoot().find
Member( |
784 .getRoot().findMember(Path.fromPortableString(mappingPath)); | 782 Path.fromPortableString(mappingPath)); |
785 | 783 |
786 if (mappedResource != null && mappedResource.exists()) { | 784 if (mappedResource != null && mappedResource.exists()) { |
787 return mappedResource; | 785 return mappedResource; |
788 } | 786 } |
789 } | 787 } |
790 } | 788 } |
791 | 789 |
792 return null; | 790 return null; |
793 } | 791 } |
794 | 792 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 // TODO(devoncarew): better handling of escaped values in the string ('\') | 958 // TODO(devoncarew): better handling of escaped values in the string ('\') |
961 str = str.replaceAll("\\\\\"", "\""); | 959 str = str.replaceAll("\\\\\"", "\""); |
962 | 960 |
963 return str; | 961 return str; |
964 } else { | 962 } else { |
965 return str; | 963 return str; |
966 } | 964 } |
967 } | 965 } |
968 | 966 |
969 } | 967 } |
OLD | NEW |