0

I have a program that has a buffer containing http data captured from the wire. The buffer would contain both http header and html. Using C program is there a way to parse the http header? Iam not really interested in html. I have seen other examples as shown in Regex HTTP header parsing, however, Iam looking at using some existing library (to be used in C) that can simply parse the header and give me each field.

My requirements are: - To just peep into the buffer and check if its http payload - If its http payload then run a regex parser to get all fields of http header.

Is there code out there which I can check? Does anyone know of any library?

Regards, bgun

3
  • 1
    Have you tried http-parser? Commented Feb 19, 2013 at 5:08
  • Seems like a nice lib, I will try it out. In future if I have to add more protocol parsing, would it make sense to go with some std regex lib? If so can you suggest any? Commented Feb 19, 2013 at 22:05
  • OK then - I have added http-parser and SLRE as an answer. Accept it if you like it Commented Feb 20, 2013 at 3:36

2 Answers 2

1

Library http-parser should serve you well.

If you want to parse some simple regexes, I would recommend very small and robust C regex parser SLRE - Super Light Regular Expression library. It consists of only one header file and one source file written in standard C, which you can link to your project.

It supports quite usable subset of standard regular expressions:

\d, \w, \s, \S (non-whitespace), * (match 0 or more), + (match 1 or more), () for groups. It don't think it supports nested groups, but I always was able to get by without them.

Sign up to request clarification or add additional context in comments.

Comments

0

Well if it's an http payload the first 5 characters should be "HTTP/". If that's not the beginning of the response then you can assume it's not an http response. If it is and all you care about are the headers, then you simply need to continue receiving data until the first "\r\n\r\n". From there if you must separate the header name from the values, it's as simple as using the first colon on each line as the delimeter.

1 Comment

The request would start with method right? GET/POST etc... At this point Iam more interested in request going out of my system which needs to parsed and modified. I came across this lib slre.sourceforge.net, looks nice, can someone comment on how good it is? Does anyone have experience using it?

Your Answer

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.