Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:09:39+00:00 2026-05-23T18:09:39+00:00

In educational purposes I’m writing a HTTP server in C++. When receiving a request,

  • 0

In educational purposes I’m writing a HTTP server in C++.
When receiving a request, how do I know when the client has finished sending headers? Is there an obligation that all headers must be sent in one shot? What if a client sends G, then after 5 seconds E, then T..? Should I wait a timeout and just close the connection if it takes too long? Should I start parsing as soon as I get the first bytes to know if the request is invalid?

I know there are a lot of libraries for this, I’m just reinventing the wheel to better understand how the Web works at different layers. And I can’t find how they deal with exactly my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:09:40+00:00Added an answer on May 23, 2026 at 6:09 pm

    There are two parts to this answer.

    Firstly, the issue of delay and time-out: you should deal with timeouts indeed, as it’s generally not possibly to detect whether a TCP connection is broken. There is more on this topic in this question: TCP socket in Unix – notify server I am done sending

    Secondly, the format of an HTTP request is defined (in RFC 2616, section 5) as follows:

        Request       = Request-Line              ; Section 5.1
                        *(( general-header        ; Section 4.5
                         | request-header         ; Section 5.3
                         | entity-header ) CRLF)  ; Section 7.1
                        CRLF
                        [ message-body ]          ; Section 4.3
    

    Essentially, you get the request line (for example GET /index.html HTTP/1.1), followed by multiple header lines (without empty lines). Then, the list of headers ends with an empty line. All ends of lines are represented with CRLF (“\r\n“).

    In addition to this, some requests also have a body (typically those using POST or PUT). If the request has a message body, its length will be given either by the Content-Length header or using delimiters via chunked transfer encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a super tiny web server for educational purposes. For the following
I'm writing a lexer for the IMAP protocol for educational purposes and I'm stumped
I'm writing a simple todo app for educational purposes. I store all todos in
I've been trying to implement a web server gateway (for fun and educational purposes)
For educational purposes, I'm writing a set of methods that cause runtime exceptions in
I'm writing some wxWidgets samples for educational purposes. My problem is simple: I'm using
As almost every programmer, I'm writing my own PHP framework for educational purposes. And
Any ideas where can I find a free (trial or for educational purposes) WebSphere
I am writing a website in my spare time for an educational facility and
For educational purposes I want to create a ostream and stream buffer to do:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.