Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. public static void traiterRequete(BufferedReader br, DataOutputStream dos)
  2. throws IOException {
  3.  
  4. int position = 0;
  5. String nomFichier;
  6. String ligne = lireLigne("", br);
  7.  
  8. if (ligne.startsWith("GET")) {
  9. try {
  10. position = ligne.indexOf("/");
  11. nomFichier = ligne.substring(position,ligne.indexOf("", position));
  12. if("text/html".equals(contentType(nomFichier))){
  13. contentTypeLine=contentType(nomFichier);
  14. retourFichier(nomFichier, dos);
  15. while(ligne!=null || ligne!="\n\r"){
  16. ligne = lireLigne("", br);
  17. }
  18. }
  19. else{
  20. //on ne sait pas
  21. }
  22.  
  23. } catch (IndexOutOfBoundsException ex) {
  24. System.out.println(ex);
  25. }
  26. }
  27. else if (ligne.startsWith("POST")) {
  28. try{
  29. position = ligne.indexOf("/");
  30. nomFichier = ligne.substring(position,ligne.indexOf("", position));
  31. if("text/html".equals(contentType(nomFichier))){
  32. contentTypeLine=contentType(nomFichier);
  33. retourFichier(nomFichier, dos);
  34. while(ligne!=null || ligne!="\n\r"){
  35. ligne = lireLigne("", br);
  36. }
  37. }
  38. else{
  39. retourCGIPOST(nomFichier, br, dos);
  40. }
  41. }
  42. catch (IndexOutOfBoundsException ex) {
  43. System.out.println(ex);
  44. }
  45.  
  46. }
  47. else{
  48. ligne = lireLigne("", br);
  49. }
  50.  
  51. /*
  52. * Cette methode lit des lignes sur br (utiliser LireLigne) et recherche une ligne commencant par GET ou par POST.
  53. *
  54. * Si la ligne commence par GET: ok
  55. * ­ on extrait le nom de fichier demande dans la ligne et on appelle la methode retourFichier. ok( a tester si le nomFichier est bon)
  56. * ­ Si le suffixe du nom de fichier est .htm ou .html (utiliser la methode contentType) ok
  57. * ­ on lit ensuite toutes les lignes qui suivent jusqu'a en trouver une vide, nulle ou contenant juste "\n\r" ok
  58. *
  59. * Si la ligne commence par POST
  60. * ­ on extrait le nom de fichier demande dans la ligne et on appelle la methode retourFichier.
  61. * ­ Si le suffixe du nom de fichier est .htm ou .html, on fait la meme chose que ci dessus pour GET
  62. * ­ Si le suffixe est autre, on appelle la methode retourCGIPOST
  63. */
  64. } // traiterRequete
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement