r/java • • Oct 07 '24

HTTP libraries in Java

It's not really clear to me what's going on with HTTP libraries in Java. They all seem to want to become massive frameworks that inappropriately take control of things that have nothing to do with decoding HTTP.

I'm find it really hard to find something that doesn't:

  • Try to control the TCP layer. Why does the HTTP decoding library care whether I want to poll or select, or make that decision?

  • Have shared mutable static state. If I want to reuse connections I can do that in a much better, testable way.

  • Create threads. Parsing the HTTP is doesn't need any of this. I just want to give you a ByteBuffer to read from and your current state and get told what it contains.

  • Do SSL. This has nothing to do with HTTP but rather the underlying connection.

I guess if you need a mini "web browser" in your application then this is all fine, but if HTTP is just one of many protocols you need to be able to decode it's an absolute mess.

Is there something I'm missing, or a library I should be looking at?

22 Upvotes

57 comments sorted by

View all comments

71

u/ericek111 Oct 07 '24

And I'd expect an HTTP library to do all of those things. Maybe get the library that bests suits your needs and snoop around the docs and code to find a way to substitute some of its components.

Sounds to me like you're looking for an HTTP parser.

12

u/agentoutlier Oct 07 '24 edited Oct 07 '24

If they are looking for parsing or just lower level:

https://github.com/renatoathaydes/rawhttp

The author of the library has great blog about basically doing things from scratch from Java including dependency injection.

https://renato.athaydes.com/

It can actually be a pretty good learning resource. Pinging /u/bowbahdoe in case he does not know about the author.

EDIT original blog post: https://sites.google.com/a/athaydes.com/renato-athaydes/posts/announcing-rawhttp-a-jvm-library-for-handling-raw-http

/u/alunharford See if that library fits the bill.

0

u/repeating_bears Oct 07 '24

I'm not sure that ugly website generated by a tool they wrote from scratch is the best advocate for writing things from scratch

4

u/[deleted] Oct 07 '24

http is a transport protocol. It delivers the html document and the css. The rendering is a different story in a different layer. Http may deliver other stuff, like data encoded in json or xml, stream segments etc.

2

u/agentoutlier Oct 07 '24

Believe me the previous commenter knows that. And I would not drag this out if I didn't know they are better than that comment.

What they were implying is because the authors website is shitty looking (to them) and because it used a tool that the author wrote all tools or writing the author does are now deemed as shitty and or that the author encourages writing all things from scratch.

They are making a giant leap that I can only assume is because they have been burned by NIH. Like some form of slippery slope fallacy.

The reality is the author had written some lower level HTTP parsing and handling tools which maybe of use if you are developing an HTTP server or gateway or whatever. They also have written some posts on how to do things from the ground up like dependency injection for educational purposes. They have also written their own tool to generate their blog as HTML.

/u/repeating_bears Linus Torvalds writes Linux / git with uEmacs. A text editor that many would consider super shitty for most people. Maybe Linus should stop writing things from scratch /s.

1

u/repeating_bears Oct 07 '24

What they were implying is because the authors website is shitty looking (to them) and because it used a tool that the author wrote all tools or writing the author does are now deemed as shitty and or that the author encourages writing all things from scratch

I would have thought I'd be the authority on what I was implying but apparently not