Difference between Content-Range and Range headers?

前端 未结 2 897
夕颜
夕颜 2020-11-28 04:21

What is the difference between HTTP headers Content-Range and Range? When should each be used?

I am trying to stream an audio file from a particular byte offset. Sho

2条回答
  •  心在旅途
    2020-11-28 04:42

    Actually, the accepted answer is not complete. Content-Range is not only used in responses. It is also legal in requests that provide an entity body.

    For example, an HTTP PUT provides an entity body, it might provide only a portion of an entity. Thus the PUT request can include a Content-Range header indicating to the server where the partial entity body should be merged into the entity.

    For example, let's first create and then append to a file using HTTP:

    Request 1:

    PUT /file HTTP/1.1
    Host: server
    Content-Length: 1
    
    a
    

    Request 2:

    PUT /file HTTP/1.1
    Host: server
    Content-Range: bytes 1-2/*
    Content-Length: 1
    
    a
    

    How, let's see the file's contents...

    Request 3:

    GET /file HTTP/1.1
    Host: server
    
    HTTP/1.1 200 OK
    Content-Length: 2
    
    aa
    

    This allows random file access, both READING and WRITING over HTTP. I just wanted to clarify, as I was researching the use of Content-Range in a WebDAV client I am developing, so perhaps this expanded information will prove useful to somebody else.

提交回复
热议问题