• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to append response to the incoming request from Socket and write to another Socket.....

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created proxy server. It runs on port 9000.

I made proxy settings in my web browser to handle the request coming at port 9000. When I hit any URL on Web browser then I read the data from socket InputStream and write thr data back to Socket outputstream.


Now I want to append some response (in the form of Javascript) with the Incoming request but when I write the response I can't see any code embedded in the web browser.

When I print the response coming from the Web Browser it gives me data in unreadable format....




My issue is How can I append my response with the Incoming request from Socket and write it to another socket.......................
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code of any length. It's unnecessarily hard to read as it is, making it less likely that people will do so. You can edit your post to include them.

Some things I noticed:
  • You may want to use a ServerSocket instead of a Socket for the server, especially if you want to handle multithreading later on
  • You're completely ignoring the issue of encoding, essentially assuming that the platform default encoding of the proxy server will be the same as the encoding of the web request or the web response, which is not a given. In fact, HTTP requests can be encoded using any number of encodings, so the proxy needs to be prepared to recognize the encoding before it can meaningfully transform the byte stream into characters.
  • The code seems to write the request as part of the response, which doesn't make sense - HTTP request and response use completely different headers, for a start.


  • I think you will benefit from thoroughly reading the HTTP specification for how HTTP requests and response may or should look like.
     
    I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic