Comments (17)
How about having a helper called createOutputStream()
that returns an OutputStream
that is called from openOutput()
that by default just returns the value of getConnection().getOutputStream()
?
You could override that and wrap the connection's output stream in another output stream if desired.
from http-request.
true. though I am not sure that alone would do.
Here is the gist of the code I had to write to overcome some of the deficiencies in HttpRequest.
Points to note there:
- there needs to be a
getOutput()
method that returns the outputstream variable since thesend()
methods dont capture all use cases. - constructor for
HttpRequestException
should be either public or there needs to be a methodnewHttpRequestException()
method, so we dont have to subclass the exception just to throw it.
from http-request.
On point 1, currently a RequestOutputStream
is used internally to wrap the connection's OutputStream
.
Are you saying you want to replace RequestOutputStream
completely or you just want to replace the OutputStream
it wraps in your sub-classes?
from http-request.
I made the HttpRequestException
constructor public in commit aeccee6
from http-request.
I forgot to actually post the gist in my last comment.
here it is:
https://gist.github.com/pdeva/6314946
from http-request.
point 1 relates to the writeData(HttpURLConnection conn, boolean isDeflate, JSONStreamAware obj)
method in the gist.
Here the JSONStreamAware
needs to be passed an OutputStream
object. currently there is no way to get a reference to the outputstream from the httprequest object.
also the copy()
method is incorrect. It checks for -1 as a terminator. Many times, especially while sending binary/compressed data, -1 is a real value. The method instead needs to take in a length
param.
from http-request.
So in your example you want to send the data compressed to the server right?
I think this is something useful to build into the library but I also want to make extensions like yours work.
from http-request.
i think any situation where you are acccepting a byte array and automatically assume -1 is a terminator inside that array is fundamentally incorrect.
from http-request.
Isn't -1
what the docs say as the end of stream?
http://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayInputStream.html#read()
from http-request.
it only says:
"If pos equals count, then -1 is returned to indicate end of file."
nowhere does it say that the presence of -1 in the stream indicates end of
stream.
Prashant
Sent from my iPhone
On Aug 23, 2013, at 9:05 AM, Kevin Sawicki [email protected] wrote:
Isn't -1 that what the docs say as the end of stream?
http://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayInputStream.html#read()
—
Reply to this email directly or view it on
GitHubhttps://github.com//issues/52#issuecomment-23171021
.
from http-request.
oops I read the wrong read() method in the last comment. the one you
pointed to also says values in the range 0 to 255 are valid.
Java uses a 2s complement system and leaves one bit for the sign, so -1
will be 255. (Byte.MaxValue is 128).
Prashant
Sent from my iPhone
On Aug 23, 2013, at 9:05 AM, Kevin Sawicki [email protected] wrote:
Isn't -1 that what the docs say as the end of stream?
http://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayInputStream.html#read()
—
Reply to this email directly or view it on
GitHubhttps://github.com//issues/52#issuecomment-23171021
.
from http-request.
Could you point to the line of code in HttpRequest.java
that you think is not checking the end of streams properly?
from http-request.
oh my bad. i thought you were looking for a -1 in the byte array stream.
this is what happens when you are dealing with a bug and wondering if its your code or the library ;)
from http-request.
No worries, thanks for letting me know, I want to circle back to your original point and rephrase to make sure I understand what you are looking for:
In your example you don't want to have the internal class RequestOutputStream
used at all, you want to completely take over the output stream written in the various send
methods so you can compress it on the way out?
from http-request.
Actually there is no RequestOutputStream
class in my example...
https://gist.github.com/pdeva/6314946
The class that should not be present is that entire ConnectionDataWriter
class.
from http-request.
Yeah, sorry, RequestOutputStream
is internal to HttpRequest
and is what is currently returned from openOutput()
.
I asked because the output
field in HttpRequest
assumes a RequestOutputStream
and not just an OutputStream
.
from http-request.
yes, that assumption definitely prevents us from doing what we need to do
Prashant
On Wed, Aug 28, 2013 at 11:14 AM, Kevin Sawicki [email protected]:
Yeah, sorry, RequestOutputStream is internal to HttpRequest and is what
is currently returned from openOutput().I asked because the output field in HttpRequest assumes a
RequestOutputStream and not just an OutputStream.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/52#issuecomment-23435597
.
from http-request.
Related Issues (20)
- How do I add request headers? I saw the accept method which is expecting a string, but I need to add new key,value pairs for headers HOT 3
- MOBILE TOP 10: M5-INSUFFICIENT CRYPTOGRAPHYMOBILE
- Accessing the headers of a request, without starting a connection
- Parameter value contains the character # HOT 1
- How to send request with client certificate ? (not globally configured for every request)
- Support of digest authentication
- how to GET with cookie in headers?
- how to make a http request with session? HOT 1
- "Exception in thread "main" java.lang.IllegalStateException" when useProxy
- project status in 2020
- Correcion en peticiones por GET
- option to log the request and the responses HOT 1
- cannot post multi-part with file HOT 1
- java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required
- java.io.IOException: Premature EOF
- java.lang.IllegalStateException: Already connected
- hope to support HTTP2.0
- Add pkcs12 certificate to autenticate
- CVE-2019-1010206 HOT 2
- It is recommeded to use `java.net.http.HttpClient` with JDK11 or higher.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-request.