2

I see the http parser written by Igor Sysoev for nginx does not use regular expressions

https://github.com/joyent/http-parser

What could be the main reason for such design decision? I guess I could write few regular expressions to parse HTTP req & res this would be a lot less complex than Igor's version of the parser.

What am I missing here?

asked Jun 23, 2013 at 2:38
8
  • maybe he didn't find a good c regex lib to his liking Commented Jun 23, 2013 at 3:09
  • that is a hell a lot of an effort just to 'not like' a reg exp lib. Dont you think? Commented Jun 23, 2013 at 3:16
  • 3
    Regular expressions are for regular languages. Are http requests/responses regular? If it is specified by a context-free grammar, then a full-blown parser is necessary to handle all the cases. Commented Jun 23, 2013 at 3:19
  • 1
    or he didn't look very hard for one/wanted it to not rely on one. and even if he did use regex he'd still only have a lexer at most not a parser Commented Jun 23, 2013 at 3:22
  • 2
    Why would it? Regular expressions aren't the only method for parsing data, nor are they the best in every situation. Right tool for the job and all that. Commented Jun 24, 2013 at 16:15

1 Answer 1

4

I asked this question over the mailing list of nginx. The following was the response:

Regular expressions isn't something readily available when you code in C, nor something which can be easily used to parse data available in chunks. It's also highly unlikely that even carefully coded regular expressions will be able to beat C code in terms of performance.

Of course if you are coding some simple http server in perl or javascript - using regular expressions is a way to go. But it's unlikely a good choise if you are coding high performance web server in C.

-- Maxim Dounin (member of nginx dev mailing list)

answered Jun 24, 2013 at 16:06
1
  • Can't get a better answer than from the creator. But even if C did have good regex parsing, it is slower than mem ptr char parsing by an average of 1,000 times slower (in my experience with hundreds of data parsers against hundreds of millions of parsed data objects). Commented Aug 15, 2013 at 21:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.