我已經用Java構建了一個文件服務器,並且在理解何時應該開始提供文件數據方面遇到困難。正如你在下面看到的是兩個不同的客戶端請求。有些提供了兩個請求,我不知道什麼時候應該開始提供數據,什麼時候我應該「忽略」。Http服務器,我什麼時候發送數據?
客戶端#1:
06-15 08:06:21.290: VERBOSE/HttpSession(9425): SESSION 1: STARTED
06-15 08:06:21.290: INFO/HttpSession(9425): CLIENT:
06-15 08:06:21.290: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:21.290: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:21.290: INFO/HttpSession(9425): User-Agent: (Linux)
06-15 08:06:21.290: INFO/HttpSession(9425): SERVER:
06-15 08:06:21.290: INFO/HttpSession(9425): HTTP/1.1 200 OK
06-15 08:06:21.290: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:21 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:21.290: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:21.290: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:21.290: INFO/HttpSession(9425): Content-Type: audio/mpeg
06-15 08:06:21.290: INFO/HttpSession(9425):
06-15 08:06:26.720: VERBOSE/HttpSession(9425): SESSION 2: STARTED
06-15 08:06:26.730: INFO/HttpSession(9425): CLIENT:
06-15 08:06:26.730: INFO/HttpSession(9425): GET /stream HTTP/1.1
06-15 08:06:26.730: INFO/HttpSession(9425): Host: 127.0.0.1:37914
06-15 08:06:26.730: INFO/HttpSession(9425): Accept: */*
06-15 08:06:26.730: INFO/HttpSession(9425): SERVER:
06-15 08:06:26.730: INFO/HttpSession(9425): HTTP/1.1 200 OK
06-15 08:06:26.730: INFO/HttpSession(9425): Date: Wed, 15 Jun 2011 12:06:26 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Server: HTTP Server
06-15 08:06:26.730: INFO/HttpSession(9425): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 08:06:26.730: INFO/HttpSession(9425): Accept-Ranges: none
06-15 08:06:26.730: INFO/HttpSession(9425): Content-Type: audio/mpeg
06-15 08:06:26.730: INFO/HttpSession(9425):
06-15 08:06:26.730: VERBOSE/HttpSession(9425): SESSION 2: ENDED
客戶#2:
06-15 05:03:58.079 I/HttpSession(18335): CLIENT:
06-15 05:03:58.079 I/HttpSession(18335): GET /stream HTTP/1.1
06-15 05:03:58.079 I/HttpSession(18335): Host: 127.0.0.1
06-15 05:03:58.079 I/HttpSession(18335): Accept: */*
06-15 05:03:58.079 I/HttpSession(18335): Icy-MetaData:1
06-15 05:03:58.079 I/HttpSession(18335): User-Agent: QuickTime;NvMM HTTP Client v0.1
06-15 05:03:58.089 I/HttpSession(18335): SERVER:
06-15 05:03:58.089 I/HttpSession(18335): HTTP/1.1 200 OK
06-15 05:03:58.089 I/HttpSession(18335): Date: Wed, 15 Jun 2011 09:03:58 GMT
06-15 05:03:58.089 I/HttpSession(18335): Server: HTTP Server
06-15 05:03:58.089 I/HttpSession(18335): Last-Modified: Mon, 06 Aug 2009 01:02:23 GMT
06-15 05:03:58.089 I/HttpSession(18335): Accept-Ranges: bytes
06-15 05:03:58.089 I/HttpSession(18335): Content-Type: audio/mpeg
您也可以在客戶端記錄標題(curl -v)。客戶行爲似乎有點奇怪,因爲通常客戶端在每個請求上都發送User-Agent和Accept。 – heiko 2011-06-15 12:50:08
我沒有訪問http客戶端的內部:(這是一個Android設備 – Jona 2011-06-15 12:56:19
)「接受:\ */\ *」大致的意思是「給我發送任何你喜歡的內容類型」w3c說:如果不存在Accept頭字段,則假定客戶端接受所有媒體類型,如果存在Accept頭字段,並且服務器無法根據組合的Accept字段值發送可接受的響應,那麼服務器應該(SHOULD)發送一個406(不可接受)的響應 – heiko 2011-06-15 12:57:48