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 6607697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:31:51+00:00 2026-05-25T19:31:51+00:00

When building a HTTP response, I need to read the file I want to

  • 0

When building a HTTP response, I need to read the file I want to serve in memory.

For binary files, like jpeg, I use

//Setup and other headers omitted
stat(file, &fileStat);
int fileSize=fileState.st_size
sprintf(headerBuffer, "content-length: %u\r\n\r\n", fileSize)
fread(fileBuffer, fileSize, 1, filePtr);
//combine headerBuffer and fileBuffer, then send to socket

However I don’t know how to deal with text files, like html. I’m confused about these two things:

  • Is the content-length still the file size or strlen(whole file as a string)? or are they the same thing?
  • Can I still use fread() to load an text file or do I read it line by line with fgets()? I thought fread() was only for reading binary files, wasn’t it?
  • 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-25T19:31:52+00:00Added an answer on May 25, 2026 at 7:31 pm

    Content-length is the full length of the entity sent in the response. If you’re sending a file, it’s the file size (unless you’re applying any content encoding like gzip, in that case it’s the size of the file after encoded).

    The concept of “letters” doesn’t enter the picture and it wouldn’t make sense. HTTP is not used just to transfer text and what constitutes a letter is in itself problematic (e.g. encoding, Unicode version if applicable, …).

    Finally, you can of course, use fread instead of fgets. There’s no reason to send the response line-by-line.

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

Sidebar

Related Questions

I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
When building a multi-lingual website (with ASP.NET web forms), I'll use an HTTP module
I am looking to use Net::HTTP to examine a response for a particular revision
I'm Using Visual Studio 2008. At http://gotspeech.net/elearning/ Building Voice Workflows Create Voice Response Application
I am building xml rpc service using twisted and I would like to use
I'm building up my site over at http://royronalds.com , and I'm trying to figure
I'm building Flex 3 application and I have a geocoding service ( http://.../GeocodeServer )
I'm building a client that talks to the http server. Now my client needs
I am building CLR Stored Procedures and UDFs as discussed in this article: http://www.codeproject.com/KB/cs/CLR_Stored_Procedure.aspx
I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically

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.