我需要解析标头以从http请求中提取绝对URL。 我只关心的方法只有GET,POST和HEAD。我想确认以下简单的逻辑/伪代码将是足以覆盖大多数情况下,C:HTTP标头解析
1 url = extract the url from the first request line;
2 if (url[0] == '/') {
3 //relative url, keep reading until HOST or end of the header
4 while (nextline != "\r\n\r\n") {
5 if (nextline starts with HOST) {
6 host = extract the host value;
7 return (host+url);
8 } else {
9 continue;
10 }
11
12 }
13 return bad_req;
14 } else {
15 //absolute url, return directly, ignore HOST
16 return url;
17 }
1)是否有任何情况下离开了?
2)第2行足以说明它是相对URL还是绝对URL?
3)编码问题?
4)其他可能的故障?
顺便说一句,性能是一个非常重要的因素,我需要考虑。
你可以做这个算法更常见,例如[here](https://sourceforge.net/projects/ccgilib/)是我的CGI库。 –