vaynedu / nginx-1.16.0

学习nginx架构设计与实现,翻译nginx的源码,写nginx的测试代码, 在issue中记录nginx的精妙设计及其常见问题https://github.com/vaynedu/nginx-1.16.0/issues 。 myexercise内存池、哈希表、链表、md5、crc测试代码,mymodule中有hello自定义模块代码。通过nginx将自己整个知识体系连接起来
https://github.com/vaynedu/nginx-1.16.0/issues
BSD 2-Clause "Simplified" License
12 stars 2 forks source link

ngin支持多range请求? #36

Closed vaynedu closed 5 years ago

vaynedu commented 5 years ago

1. 多range请求返回结果

root@100.115.138.131:~#curl "123.206.25.239" -v  -H'Range: bytes=0-50, 100-150'
* About to connect() to 123.206.25.239 port 80 (#0)
*   Trying 123.206.25.239...
* Connected to 123.206.25.239 (123.206.25.239) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 123.206.25.239
> Accept: */*
> Range: bytes=0-50, 100-150
> 
< HTTP/1.1 206 Partial Content
< Server: nginx/1.8.0
< Date: Tue, 24 Sep 2019 13:11:04 GMT
< Content-Type: multipart/byteranges; boundary=00000000000000000020
< Content-Length: 303
< Last-Modified: Mon, 28 Aug 2017 03:17:03 GMT
< Connection: keep-alive
< ETag: "59a38b2f-1197"
< 

--00000000000000000020
Content-Type: text/html
Content-Range: bytes 0-50/4503

<!doctype html>
<html>
<head>
<meta charset="utf
--00000000000000000020
Content-Type: text/html
Content-Range: bytes 100-150/4503

shortcut icon" href="images/logo.ico" type="image/x
--00000000000000000020--
* Connection #0 to host 123.206.25.239 left intact

2. 多range请求实现

源码位置:src/http/modules/ngx_http_range_filter_module.c 实现也特别简单,多range无非就通过特定的分割串标识一下就行,按照约定的格式,填充响应头和包体即可,没有难的地方。