Skip to content

Commit 8233011

Browse files
committedDec 24, 2012
Switched to Joyent HTTP Parser (better maintained derivative of the
former HTTP Parser)
1 parent b2529df commit 8233011

10 files changed

+3284
-883
lines changed
 

‎http-parser/AUTHORS

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Authors ordered by first contribution.
2+
Ryan Dahl <ry@tinyclouds.org>
3+
Jeremy Hinegardner <jeremy@hinegardner.org>
4+
Sergey Shepelev <temotor@gmail.com>
5+
Joe Damato <ice799@gmail.com>
6+
tomika <tomika_nospam@freemail.hu>
7+
Phoenix Sol <phoenix@burninglabs.com>
8+
Cliff Frey <cliff@meraki.com>
9+
Ewen Cheslack-Postava <ewencp@cs.stanford.edu>
10+
Santiago Gala <sgala@apache.org>
11+
Tim Becker <tim.becker@syngenio.de>
12+
Jeff Terrace <jterrace@gmail.com>
13+
Ben Noordhuis <info@bnoordhuis.nl>
14+
Nathan Rajlich <nathan@tootallnate.net>
15+
Mark Nottingham <mnot@mnot.net>
16+
Aman Gupta <aman@tmm1.net>
17+
Tim Becker <tim.becker@kuriositaet.de>
18+
Sean Cunningham <sean.cunningham@mandiant.com>
19+
Peter Griess <pg@std.in>
20+
Salman Haq <salman.haq@asti-usa.com>
21+
Cliff Frey <clifffrey@gmail.com>
22+
Jon Kolb <jon@b0g.us>
23+
Fouad Mardini <f.mardini@gmail.com>
24+
Paul Querna <pquerna@apache.org>
25+
Felix Geisendörfer <felix@debuggable.com>
26+
koichik <koichik@improvement.jp>
27+
Andre Caron <andre.l.caron@gmail.com>
28+
Ivo Raisr <ivosh@ivosh.net>
29+
James McLaughlin <jamie@lacewing-project.org>
30+
David Gwynne <loki@animata.net>
31+
LE ROUX Thomas <thomas@november-eleven.fr>
32+
Randy Rizun <rrizun@ortivawireless.com>
33+
Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
34+
Simon Zimmermann <simonz05@gmail.com>
35+
Erik Dubbelboer <erik@dubbelboer.com>
36+
Martell Malone <martellmalone@gmail.com>
37+
Bertrand Paquet <bpaquet@octo.com>
38+
BogDan Vatra <bogdan@kde.org>
39+
Peter Faiman <peter@thepicard.org>
40+
Corey Richardson <corey@octayn.net>

‎http-parser/LICENSE-MIT

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Copyright 2009,2010 Ryan Dahl <ry@tinyclouds.org>
1+
http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
2+
Igor Sysoev.
3+
4+
Additional changes are licensed under the same terms as NGINX and
5+
copyright Joyent, Inc. and other Node contributors. All rights reserved.
26

37
Permission is hereby granted, free of charge, to any person obtaining a copy
48
of this software and associated documentation files (the "Software"), to

‎http-parser/README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The parser extracts the following information from HTTP messages:
2424
* Response status code
2525
* Transfer-Encoding
2626
* HTTP version
27-
* Request path, query string, fragment
27+
* Request URL
2828
* Message body
2929

3030

@@ -36,7 +36,7 @@ using `http_parser_init()` and set the callbacks. That might look something
3636
like this for a request parser:
3737

3838
http_parser_settings settings;
39-
settings.on_path = my_path_callback;
39+
settings.on_url = my_url_callback;
4040
settings.on_header_field = my_header_field_callback;
4141
/* ... */
4242

@@ -126,7 +126,7 @@ There are two types of callbacks:
126126
* notification `typedef int (*http_cb) (http_parser*);`
127127
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
128128
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
129-
Callbacks: (requests only) on_path, on_query_string, on_uri, on_fragment,
129+
Callbacks: (requests only) on_uri,
130130
(common) on_header_field, on_header_value, on_body;
131131

132132
Callbacks must return 0 on success. Returning a non-zero value indicates
@@ -164,8 +164,15 @@ and apply following logic:
164164
------------------------ ------------ --------------------------------------------
165165

166166

167+
Parsing URLs
168+
------------
169+
170+
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
171+
Users of this library may wish to use it to parse URLs constructed from
172+
consecutive `on_url` callbacks.
173+
167174
See examples of reading in headers:
168175

169176
* [partial example](http://gist.github.com/155877) in C
170-
* [from http-parser tests](http://github.com/ry/http-parser/blob/37a0ff8928fb0d83cec0d0d8909c5a4abcd221af/test.c#L403) in C
171-
* [from Node library](http://github.com/ry/node/blob/842eaf446d2fdcb33b296c67c911c32a0dabc747/src/http.js#L284) in Javascript
177+
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
178+
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript

‎http-parser/http_parser.c

+1,210-638
Large diffs are not rendered by default.

‎http-parser/http_parser.gyp

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# This file is used with the GYP meta build system.
2+
# http://code.google.com/p/gyp/
3+
# To build try this:
4+
# svn co http://gyp.googlecode.com/svn/trunk gyp
5+
# ./gyp/gyp -f make --depth=`pwd` http_parser.gyp
6+
# ./out/Debug/test
7+
{
8+
'target_defaults': {
9+
'default_configuration': 'Debug',
10+
'configurations': {
11+
# TODO: hoist these out and put them somewhere common, because
12+
# RuntimeLibrary MUST MATCH across the entire project
13+
'Debug': {
14+
'defines': [ 'DEBUG', '_DEBUG' ],
15+
'cflags': [ '-Wall', '-Wextra', '-O0', '-g', '-ftrapv' ],
16+
'msvs_settings': {
17+
'VCCLCompilerTool': {
18+
'RuntimeLibrary': 1, # static debug
19+
},
20+
},
21+
},
22+
'Release': {
23+
'defines': [ 'NDEBUG' ],
24+
'cflags': [ '-Wall', '-Wextra', '-O3' ],
25+
'msvs_settings': {
26+
'VCCLCompilerTool': {
27+
'RuntimeLibrary': 0, # static release
28+
},
29+
},
30+
}
31+
},
32+
'msvs_settings': {
33+
'VCCLCompilerTool': {
34+
},
35+
'VCLibrarianTool': {
36+
},
37+
'VCLinkerTool': {
38+
'GenerateDebugInformation': 'true',
39+
},
40+
},
41+
'conditions': [
42+
['OS == "win"', {
43+
'defines': [
44+
'WIN32'
45+
],
46+
}]
47+
],
48+
},
49+
50+
'targets': [
51+
{
52+
'target_name': 'http_parser',
53+
'type': 'static_library',
54+
'include_dirs': [ '.' ],
55+
'direct_dependent_settings': {
56+
'defines': [ 'HTTP_PARSER_STRICT=0' ],
57+
'include_dirs': [ '.' ],
58+
},
59+
'defines': [ 'HTTP_PARSER_STRICT=0' ],
60+
'sources': [ './http_parser.c', ],
61+
'conditions': [
62+
['OS=="win"', {
63+
'msvs_settings': {
64+
'VCCLCompilerTool': {
65+
# Compile as C++. http_parser.c is actually C99, but C++ is
66+
# close enough in this case.
67+
'CompileAs': 2,
68+
},
69+
},
70+
}]
71+
],
72+
},
73+
74+
{
75+
'target_name': 'http_parser_strict',
76+
'type': 'static_library',
77+
'include_dirs': [ '.' ],
78+
'direct_dependent_settings': {
79+
'defines': [ 'HTTP_PARSER_STRICT=1' ],
80+
'include_dirs': [ '.' ],
81+
},
82+
'defines': [ 'HTTP_PARSER_STRICT=1' ],
83+
'sources': [ './http_parser.c', ],
84+
'conditions': [
85+
['OS=="win"', {
86+
'msvs_settings': {
87+
'VCCLCompilerTool': {
88+
# Compile as C++. http_parser.c is actually C99, but C++ is
89+
# close enough in this case.
90+
'CompileAs': 2,
91+
},
92+
},
93+
}]
94+
],
95+
},
96+
97+
{
98+
'target_name': 'test-nonstrict',
99+
'type': 'executable',
100+
'dependencies': [ 'http_parser' ],
101+
'sources': [ 'test.c' ]
102+
},
103+
104+
{
105+
'target_name': 'test-strict',
106+
'type': 'executable',
107+
'dependencies': [ 'http_parser_strict' ],
108+
'sources': [ 'test.c' ]
109+
}
110+
]
111+
}

‎http-parser/http_parser.h

+172-51
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2009,2010 Ryan Dahl <ry@tinyclouds.org>
1+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
22
*
33
* Permission is hereby granted, free of charge, to any person obtaining a copy
44
* of this software and associated documentation files (the "Software"), to
@@ -24,9 +24,13 @@
2424
extern "C" {
2525
#endif
2626

27+
#define HTTP_PARSER_VERSION_MAJOR 2
28+
#define HTTP_PARSER_VERSION_MINOR 0
2729

2830
#include <sys/types.h>
29-
#if defined(_WIN32) && !defined(__MINGW32__)
31+
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
32+
#include <BaseTsd.h>
33+
#include <stddef.h>
3034
typedef __int8 int8_t;
3135
typedef unsigned __int8 uint8_t;
3236
typedef __int16 int16_t;
@@ -35,9 +39,6 @@ typedef __int32 int32_t;
3539
typedef unsigned __int32 uint32_t;
3640
typedef __int64 int64_t;
3741
typedef unsigned __int64 uint64_t;
38-
39-
typedef unsigned int size_t;
40-
typedef int ssize_t;
4142
#else
4243
#include <stdint.h>
4344
#endif
@@ -47,11 +48,8 @@ typedef int ssize_t;
4748
*/
4849
#ifndef HTTP_PARSER_STRICT
4950
# define HTTP_PARSER_STRICT 1
50-
#else
51-
# define HTTP_PARSER_STRICT 0
5251
#endif
5352

54-
5553
/* Maximium header size allowed */
5654
#define HTTP_MAX_HEADER_SIZE (80*1024)
5755

@@ -70,71 +68,150 @@ typedef struct http_parser_settings http_parser_settings;
7068
* chunked' headers that indicate the presence of a body.
7169
*
7270
* http_data_cb does not return data chunks. It will be call arbitrarally
73-
* many times for each string. E.G. you might get 10 callbacks for "on_path"
71+
* many times for each string. E.G. you might get 10 callbacks for "on_url"
7472
* each providing just a few characters more data.
7573
*/
7674
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
7775
typedef int (*http_cb) (http_parser*);
7876

7977

8078
/* Request Methods */
79+
#define HTTP_METHOD_MAP(XX) \
80+
XX(0, DELETE, DELETE) \
81+
XX(1, GET, GET) \
82+
XX(2, HEAD, HEAD) \
83+
XX(3, POST, POST) \
84+
XX(4, PUT, PUT) \
85+
/* pathological */ \
86+
XX(5, CONNECT, CONNECT) \
87+
XX(6, OPTIONS, OPTIONS) \
88+
XX(7, TRACE, TRACE) \
89+
/* webdav */ \
90+
XX(8, COPY, COPY) \
91+
XX(9, LOCK, LOCK) \
92+
XX(10, MKCOL, MKCOL) \
93+
XX(11, MOVE, MOVE) \
94+
XX(12, PROPFIND, PROPFIND) \
95+
XX(13, PROPPATCH, PROPPATCH) \
96+
XX(14, SEARCH, SEARCH) \
97+
XX(15, UNLOCK, UNLOCK) \
98+
/* subversion */ \
99+
XX(16, REPORT, REPORT) \
100+
XX(17, MKACTIVITY, MKACTIVITY) \
101+
XX(18, CHECKOUT, CHECKOUT) \
102+
XX(19, MERGE, MERGE) \
103+
/* upnp */ \
104+
XX(20, MSEARCH, M-SEARCH) \
105+
XX(21, NOTIFY, NOTIFY) \
106+
XX(22, SUBSCRIBE, SUBSCRIBE) \
107+
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
108+
/* RFC-5789 */ \
109+
XX(24, PATCH, PATCH) \
110+
XX(25, PURGE, PURGE) \
111+
81112
enum http_method
82-
{ HTTP_DELETE = 0
83-
, HTTP_GET
84-
, HTTP_HEAD
85-
, HTTP_POST
86-
, HTTP_PUT
87-
/* pathological */
88-
, HTTP_CONNECT
89-
, HTTP_OPTIONS
90-
, HTTP_TRACE
91-
/* webdav */
92-
, HTTP_COPY
93-
, HTTP_LOCK
94-
, HTTP_MKCOL
95-
, HTTP_MOVE
96-
, HTTP_PROPFIND
97-
, HTTP_PROPPATCH
98-
, HTTP_UNLOCK
99-
/* subversion */
100-
, HTTP_REPORT
101-
, HTTP_MKACTIVITY
102-
, HTTP_CHECKOUT
103-
, HTTP_MERGE
104-
/* upnp */
105-
, HTTP_MSEARCH
106-
, HTTP_NOTIFY
107-
, HTTP_SUBSCRIBE
108-
, HTTP_UNSUBSCRIBE
113+
{
114+
#define XX(num, name, string) HTTP_##name = num,
115+
HTTP_METHOD_MAP(XX)
116+
#undef XX
109117
};
110118

111119

112120
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
113121

114122

123+
/* Flag values for http_parser.flags field */
124+
enum flags
125+
{ F_CHUNKED = 1 << 0
126+
, F_CONNECTION_KEEP_ALIVE = 1 << 1
127+
, F_CONNECTION_CLOSE = 1 << 2
128+
, F_TRAILING = 1 << 3
129+
, F_UPGRADE = 1 << 4
130+
, F_SKIPBODY = 1 << 5
131+
};
132+
133+
134+
/* Map for errno-related constants
135+
*
136+
* The provided argument should be a macro that takes 2 arguments.
137+
*/
138+
#define HTTP_ERRNO_MAP(XX) \
139+
/* No error */ \
140+
XX(OK, "success") \
141+
\
142+
/* Callback-related errors */ \
143+
XX(CB_message_begin, "the on_message_begin callback failed") \
144+
XX(CB_url, "the on_url callback failed") \
145+
XX(CB_header_field, "the on_header_field callback failed") \
146+
XX(CB_header_value, "the on_header_value callback failed") \
147+
XX(CB_headers_complete, "the on_headers_complete callback failed") \
148+
XX(CB_body, "the on_body callback failed") \
149+
XX(CB_message_complete, "the on_message_complete callback failed") \
150+
\
151+
/* Parsing-related errors */ \
152+
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
153+
XX(HEADER_OVERFLOW, \
154+
"too many header bytes seen; overflow detected") \
155+
XX(CLOSED_CONNECTION, \
156+
"data received after completed connection: close message") \
157+
XX(INVALID_VERSION, "invalid HTTP version") \
158+
XX(INVALID_STATUS, "invalid HTTP status code") \
159+
XX(INVALID_METHOD, "invalid HTTP method") \
160+
XX(INVALID_URL, "invalid URL") \
161+
XX(INVALID_HOST, "invalid host") \
162+
XX(INVALID_PORT, "invalid port") \
163+
XX(INVALID_PATH, "invalid path") \
164+
XX(INVALID_QUERY_STRING, "invalid query string") \
165+
XX(INVALID_FRAGMENT, "invalid fragment") \
166+
XX(LF_EXPECTED, "LF character expected") \
167+
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
168+
XX(INVALID_CONTENT_LENGTH, \
169+
"invalid character in content-length header") \
170+
XX(INVALID_CHUNK_SIZE, \
171+
"invalid character in chunk size header") \
172+
XX(INVALID_CONSTANT, "invalid constant string") \
173+
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
174+
XX(STRICT, "strict mode assertion failed") \
175+
XX(PAUSED, "parser is paused") \
176+
XX(UNKNOWN, "an unknown error occurred")
177+
178+
179+
/* Define HPE_* values for each errno value above */
180+
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
181+
enum http_errno {
182+
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
183+
};
184+
#undef HTTP_ERRNO_GEN
185+
186+
187+
/* Get an http_errno value from an http_parser */
188+
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
189+
190+
115191
struct http_parser {
116192
/** PRIVATE **/
117-
unsigned char type : 2;
118-
unsigned char flags : 6;
119-
unsigned char state;
120-
unsigned char header_state;
121-
unsigned char index;
193+
unsigned char type : 2; /* enum http_parser_type */
194+
unsigned char flags : 6; /* F_* values from 'flags' enum; semi-public */
195+
unsigned char state; /* enum state from http_parser.c */
196+
unsigned char header_state; /* enum header_state from http_parser.c */
197+
unsigned char index; /* index into current matcher */
122198

123-
uint32_t nread;
124-
int64_t content_length;
199+
uint32_t nread; /* # bytes read in various scenarios */
200+
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
125201

126202
/** READ-ONLY **/
127203
unsigned short http_major;
128204
unsigned short http_minor;
129205
unsigned short status_code; /* responses only */
130-
unsigned char method; /* requests only */
206+
unsigned char method; /* requests only */
207+
unsigned char http_errno : 7;
131208

132209
/* 1 = Upgrade header was present and the parser has exited because of that.
133210
* 0 = No upgrade header present.
134211
* Should be checked when http_parser_execute() returns in addition to
135212
* error checking.
136213
*/
137-
char upgrade;
214+
unsigned char upgrade : 1;
138215

139216
/** PUBLIC **/
140217
void *data; /* A pointer to get hook to the "connection" or "socket" object */
@@ -143,10 +220,7 @@ struct http_parser {
143220

144221
struct http_parser_settings {
145222
http_cb on_message_begin;
146-
http_data_cb on_path;
147-
http_data_cb on_query_string;
148223
http_data_cb on_url;
149-
http_data_cb on_fragment;
150224
http_data_cb on_header_field;
151225
http_data_cb on_header_value;
152226
http_cb on_headers_complete;
@@ -155,6 +229,36 @@ struct http_parser_settings {
155229
};
156230

157231

232+
enum http_parser_url_fields
233+
{ UF_SCHEMA = 0
234+
, UF_HOST = 1
235+
, UF_PORT = 2
236+
, UF_PATH = 3
237+
, UF_QUERY = 4
238+
, UF_FRAGMENT = 5
239+
, UF_USERINFO = 6
240+
, UF_MAX = 7
241+
};
242+
243+
244+
/* Result structure for http_parser_parse_url().
245+
*
246+
* Callers should index into field_data[] with UF_* values iff field_set
247+
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
248+
* because we probably have padding left over), we convert any port to
249+
* a uint16_t.
250+
*/
251+
struct http_parser_url {
252+
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
253+
uint16_t port; /* Converted UF_PORT string */
254+
255+
struct {
256+
uint16_t off; /* Offset into buffer in which field starts */
257+
uint16_t len; /* Length of run in buffer */
258+
} field_data[UF_MAX];
259+
};
260+
261+
158262
void http_parser_init(http_parser *parser, enum http_parser_type type);
159263

160264

@@ -165,15 +269,32 @@ size_t http_parser_execute(http_parser *parser,
165269

166270

167271
/* If http_should_keep_alive() in the on_headers_complete or
168-
* on_message_complete callback returns true, then this will be should be
272+
* on_message_complete callback returns 0, then this should be
169273
* the last message on the connection.
170274
* If you are the server, respond with the "Connection: close" header.
171275
* If you are the client, close the connection.
172276
*/
173-
int http_should_keep_alive(http_parser *parser);
277+
int http_should_keep_alive(const http_parser *parser);
174278

175279
/* Returns a string version of the HTTP method. */
176-
const char *http_method_str(enum http_method);
280+
const char *http_method_str(enum http_method m);
281+
282+
/* Return a string name of the given error */
283+
const char *http_errno_name(enum http_errno err);
284+
285+
/* Return a string description of the given error */
286+
const char *http_errno_description(enum http_errno err);
287+
288+
/* Parse a URL; return nonzero on failure */
289+
int http_parser_parse_url(const char *buf, size_t buflen,
290+
int is_connect,
291+
struct http_parser_url *u);
292+
293+
/* Pause or un-pause the parser; a nonzero value pauses */
294+
void http_parser_pause(http_parser *parser, int paused);
295+
296+
/* Checks if this is the final chunk of the body. */
297+
int http_body_is_final(const http_parser *parser);
177298

178299
#ifdef __cplusplus
179300
}

‎http-parser/test.c

+1,687-151
Large diffs are not rendered by default.

‎http-parser/url_parser.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "http_parser.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
void
6+
dump_url (const char *url, const struct http_parser_url *u)
7+
{
8+
unsigned int i;
9+
10+
printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
11+
for (i = 0; i < UF_MAX; i++) {
12+
if ((u->field_set & (1 << i)) == 0) {
13+
printf("\tfield_data[%u]: unset\n", i);
14+
continue;
15+
}
16+
17+
printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
18+
i,
19+
u->field_data[i].off,
20+
u->field_data[i].len,
21+
u->field_data[i].len,
22+
url + u->field_data[i].off);
23+
}
24+
}
25+
26+
int main(int argc, char ** argv) {
27+
if (argc != 3) {
28+
printf("Syntax : %s connect|get url\n", argv[0]);
29+
return 1;
30+
}
31+
struct http_parser_url u;
32+
int len = strlen(argv[2]);
33+
int connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
34+
printf("Parsing %s, connect %d\n", argv[2], connect);
35+
36+
int result = http_parser_parse_url(argv[2], len, connect, &u);
37+
if (result != 0) {
38+
printf("Parse error : %d\n", result);
39+
return result;
40+
}
41+
printf("Parse ok, result : \n");
42+
dump_url(argv[2], &u);
43+
return 0;
44+
}

‎src/qhttpconnection.cpp

+3-34
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ QHttpConnection::QHttpConnection(QTcpSocket *socket, QObject *parent)
4040
http_parser_init(m_parser, HTTP_REQUEST);
4141

4242
m_parserSettings.on_message_begin = MessageBegin;
43-
m_parserSettings.on_path = Path;
44-
m_parserSettings.on_query_string = 0;
45-
//m_parserSettings.on_query_string = QueryString;
4643
m_parserSettings.on_url = Url;
47-
m_parserSettings.on_fragment = Fragment;
4844
m_parserSettings.on_header_field = HeaderField;
4945
m_parserSettings.on_header_value = HeaderValue;
5046
m_parserSettings.on_headers_complete = HeadersComplete;
@@ -166,40 +162,13 @@ int QHttpConnection::MessageComplete(http_parser *parser)
166162
return 0;
167163
}
168164

169-
int QHttpConnection::Path(http_parser *parser, const char *at, size_t length)
170-
{
171-
QHttpConnection *theConnection = (QHttpConnection *)parser->data;
172-
Q_ASSERT(theConnection->m_request);
173-
QString path = QString::fromAscii(at, length);
174-
175-
QUrl url = theConnection->m_request->url();
176-
url.setPath(path);
177-
theConnection->m_request->setUrl(url);
178-
return 0;
179-
}
180-
181-
int QHttpConnection::QueryString(http_parser *parser, const char *at, size_t length)
165+
int QHttpConnection::Url(http_parser *parser, const char *at, size_t length)
182166
{
183167
QHttpConnection *theConnection = (QHttpConnection *)parser->data;
184168
Q_ASSERT(theConnection->m_request);
185169

186-
Q_ASSERT(false);
187-
return 0;
188-
}
189-
190-
int QHttpConnection::Url(http_parser *parser, const char *at, size_t length)
191-
{
192-
// qDebug() << "URL CALL" << QString::fromAscii(at, length);
193-
// QHttpConnection *theConnection = (QHttpConnection *)parser->data;
194-
// theConnection->m_request->m_url->setPath(QString::fromAscii(at, length));
195-
196-
return 0;
197-
}
198-
199-
int QHttpConnection::Fragment(http_parser *parser, const char *at, size_t length)
200-
{
201-
// TODO: Implement
202-
Q_ASSERT(false);
170+
QString url = QString::fromAscii(at, length);
171+
theConnection->m_request->setUrl(QUrl(url));
203172
return 0;
204173
}
205174

‎src/qhttpconnection.h

-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ private slots:
5555

5656
private:
5757
static int MessageBegin(http_parser *parser);
58-
static int Path(http_parser *parser, const char *at, size_t length);
59-
static int QueryString(http_parser *parser, const char *at, size_t length);
6058
static int Url(http_parser *parser, const char *at, size_t length);
61-
static int Fragment(http_parser *parser, const char *at, size_t length);
6259
static int HeaderField(http_parser *parser, const char *at, size_t length);
6360
static int HeaderValue(http_parser *parser, const char *at, size_t length);
6461
static int HeadersComplete(http_parser *parser);

0 commit comments

Comments
 (0)
Please sign in to comment.