Computing2008. 8. 13. 19:02
다운로드를 위한 문서를 제공하는 웹 사이트를 구축할때 일반적으로 질문되는 것은 : "브라우져가 문서를 보여주는 방법을 어떻게 제어하는가" 이다. 예를들어, 만일 필자가 .doc 확장명을 가지는 MSWord 문서 파일에 대한 링크를 제공한다면, 파일로 저장하기 보다는 워드로 문서를 열도록 브라우져에게 어떻게 말할 것인가? 그리고, 만일 필자가 ASP를 이용해 동적으로 Tab-Delimited 포맷 문서를 만들었 다면, 이것을 자동으로 보여주기 위해서 엑셀이나 다른 스프레드 쉬트 응용프로그램으로 어떻게 구현 할 것인가?

  간단히 대답해서 여러분은 "할 수 없다" 이다. 브라우져나 클라이언트 응용프로그램이 웹서버로 부터 보낸 파일을 어떻게 다루는지 컨트롤 하는 것은 불가능하다. 여러분이 할 수 있는 것은 그것이 어떻게 다루어져야 하는 것을 제안하는 것이다. 여러분은 이것을 파일이 어떤 형태인지 브라우져에게 알려줌으로써 이것을 구현하고, 그리고 나서 브라우져와 사용자에게 그것으로 무엇을 할지 결정하도록 남긴다. 있다.


MIME-type과 Content type이란 무엇인가? 
  우리가 클라이언트 브라우져로 어떤 자원을 보낼때(어떤 형태의 파일이나 문서 등), 웹 서버는 일련의 HTTP 헤더로 파일이나 자원을 포함하는 바이트의 Stream을 앞에 보낸다. 이런 헤더는 클라이언트에게 웹 서버와 커뮤니케이션 세부사항을 묘사한다. 예를들어, 헤더는 사용되고 있는 웹 서버의 소프트웨어 의 타입, 서버의 날짜와 시간, HTTP 프로토콜, 사용중인 커넥션 타입 등을 지정한다. 헤더는 또한 클라이언트가 이런 가상 패스나 도메인에 대해서 저장해야 할 쿠키를 포함한다.

  이와 관련해서 가장 중요한 것은 헤더는 또한 보내지는 자원의 content 타입이 포함되는 것이다. 이것은 Content-Type 헤더에 의해 지정되는데, 이 값은 표준 MIME-Type의 하나이다. MIME-Type을 살펴봄으로써 브라우져는 데이터를 나타내는데 어떤 종류의 파일 Stream인지를 알고 있다. HTML 페이지에서, 표준MIME type은 "text/html" 이다. 그리고 텍스트 파일이나 텍스트 stream은 "text/text"이다. 이미지 파일은 "image/gif" 혹은 "image/jpeg" 와 같은 MIME-Type을 가진다. 일반적인 MIME-Type과 파일 확장명의 매칭 리스트는 아래 표에 나와있다.



일반적으로 사용되는 MIME-Type과 파일 확장명

MIME-Type Description File Extension
application/acad AutoCAD drawing files dwg
application/clariscad ClarisCAD files ccad
application/dxf DXF (AutoCAD) dxf
application/msaccess Microsoft Access file mdb
application/msword Microsoft Word file doc
application/octet-stream Uninterpreted binary bin
application/pdf PDF (Adobe Acrobat) pdf
application/postscript PostScript, encapsulated PostScript, ai, ps, eps
Adobe Illustrator
application/rtf Rich Text Format file rtf rtf
application/vnd.ms-excel Microsoft Excel file xls
application/vnd.ms-powerpoint Microsoft PowerPoint file ppt
application/x-cdf Channel Definition Format file cdf
application/x-csh C-shell script csh csh
application/x-dvi TeX dvi dvi dvi
application/x-javascript JavaScript source file js
application/x-latex LaTeX source file latex
application/x-mif FrameMaker MIF format mif
application/x-msexcel Microsoft Excel file xls
application/x-mspowerpoint Microsoft PowerPoint file ppt
application/x-tcl TCL script tcl
application/x-tex TeX source file tex
application/x-texinfo Texinfo (emacs) texinfo, texi 
application/x-troff troff file t, tr, roff t, tr, roff
application/x-troff-man troff with MAN macros man 
application/x-troff-me troff with ME macros me
application/x-troff-ms troff with MS macros ms
application/x-wais-source WAIS source file src
application/zip ZIP archive zip
audio/basic Basic audio (usually m-law) au, snd
audio/x-aiff AIFF audio aif, aiff, aifc
audio/x-wav Windows WAVE audio wav 
image/gif GIF image gif
image/ief Image Exchange Format file ief
image/jpeg JPEG image jpeg, jpg jpe 
image/tiff TIFF image tiff, tif
image/x-cmu-raster CMU Raster image ras
image/x-portable-anymap PBM Anymap image format pnm
image/x-portable-bitmap PBM Bitmap image format pbm
image/x-portable-graymap PBM Graymap image format pgm
image/x-portable-pixmap PBM Pixmap image format ppm
image/x-rgb RGB image format rgb
image/x-xbitmap X Bitmap image xbm
image/x-xpixmap X Pixmap image xpm
image/x-xwindowdump X Windows Dump (xwd)  xwd
multipart/x-gzip GNU ZIP archive gzip
multipart/x-zip PKZIP archive zip
text/css Cascading style sheet  css
text/html HTML file html, htm
text/plain Plain text txt 
text/richtext MIME Rich Text rtx
text/tab-separated- values Text with tab-separated values tsv
text/xml XML document xml
text/x-setext Struct-Enhanced text  etx
text/xsl XSL style sheet xsl
video/mpeg MPEG video mpeg, mpg, mpe 
video/quicktime QuickTime video qt, mov
video/x-msvideo Microsoft Windows video avi
video/x-sgi-movie SGI movie player format movie 


우리가 클라이언트에게 데이터의 Stream을 만들고 보내는데, ASP를 사용한다면, IIS는 이것을 동적으로 HTML 페이지를 만들어질 것이라고 가정한다. 그리고, 그것은 MIME-Type "text/html"로 되돌려 보내질 것이다. 그러나 우리는 ASP 페이지에서 Response.ContentType 속성을 세팅할때 다른 값으로 content type을 바꿀 수 있다. 그래서 우리가 사용할 수 있는 스프레드 쉬트 응용프로그램을 위해 tab-delimited 파일을 만든다고 가정하면, 우리는 content type을 "application/tab-separated-values"으로 대신 세팅할 수 있다:

                    Response.ContentType = "application/tab-separated-values"

  이것은 HTTP 헤더 값을 지정하기 때문에, 우리는 모든 페이지의 보이는 content를 사용자에게 보내기 전에 이것을 해야한다는 것을 명심하라. 일반적으로, 우리는 페이지의 제일 위쪽 근처에 이 문장을 놓게된다. 보통은 <% @ language= ... %>와 Response.buffer 문장 다음에 놓는다.

Posted by 버터백통