Thread: Determining HTTP Header?

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Question Determining HTTP Header?

    Nowadays I want to make a local proxy using socket.

    Btw, how we can determining whether the received buffer is a HTTP header / content file?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    If you understand how HTTP works it would be very clear. Note that you'll actually need to understand HTTP in great depth to make a proxy server (at least one that follows the HTTP standards) -- see the RFC.

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Yeah, thank you zacs7.

    Btw the structure of HTTP connection is:

    Code:
    Request header: header + "\r\n"
    Response header: header + "\r\n" + content (if any)
    Well, I discovered that internet/network programming is so interesting.
    It's complex but standarized.

    But I just get confused when different browser sends different thing of request.

    For example:
    From http:// username : password @ server
    typed in address bar.

    Firefox sent:
    Code:
    GET http://server/ HTTP/1.1
    Host: http://server
    Opera sent:
    Code:
    GET http://server/ HTTP/1.1
    Host: http://server:80 (extra useful? port)
    Authentication: Basic aaBBccDDee (plus this)
    Also they act different when we are inputting https:// address.


    Btw, they said C is for network programming. But where is the std* API for network?

    Should I use WSA* API in Windows?
    Last edited by audinue; 08-01-2008 at 09:28 AM.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Sockets is the "standard" for TCP/IP network programming, which is the basis of the Internet. See Beej's Guide for a nice tutorial for programming sockets.

    Yes, the WSA* stuff is Winsock, the Windows Sockets API. Here's how to do a basic Winsock app.

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Wow, your reply is very-very help me rags_to_riches...

    Thank you.

    Btw I think "standard" is something like stdlib.h, stdio.h, time.h that provided portability and included in every C compilers ^_^ ...

    Notes:
    I found that Internet Explorer doesn't suport proxies for FTP protocols.
    Last edited by audinue; 08-01-2008 at 12:05 PM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Btw I think "standard" is something like stdlib.h, stdio.h, time.h that provided portability and included in every C compilers ^_^ ...
    There is no support for network programming in the C standard library. On the other hand, sockets programming is at least a de facto standard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    C and UNIX were developed together. BSD sockets was developed on BSD (I think) UNIX. Therefore, you can see how sockets and C go together.

  8. #8
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    It's ok I think I will go search something like cygwin to make a portable local proxy...

    Btw, guys, I have a problem about receiving and sending request andresponse header in my proxy...

    Code:
    client -> serverProxy -> clientProxy -> server -> clientProxy -> serverProxy -> client
    1. A client sends a raw request header to the serverProxy(a socket).

    2. The proxy translate them into web request header then send it to the server via clientProxy(a socket).

    3. The clientProxy get the response header and the content. The proxy synchronizing it with serverProxy.

    4. The serverProxy send the response header and the content to the browser.

    ...

    My questions
    In step 2, any tips for translating raw to web request header?
    In step 4, do we need to do something with response header in step 4?

    And ...
    What is the advantages/disadvantages of blocking and non-blocking connection in socket?

  9. #9
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Hey, I found a clear and simple Socket tutorial:
    http://www.nullterminator.net/winsock.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM