From c2c1ce1dc5b934c07e7a7a276501e18ce5f78471 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 4 Nov 2013 20:16:26 -0500 Subject: [PATCH] Style fixes to HttpRequest --- headers/os/net/HttpRequest.h | 31 +++++++------- src/kits/network/libnetapi/HttpRequest.cpp | 47 +++++++++++----------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/headers/os/net/HttpRequest.h b/headers/os/net/HttpRequest.h index d18222a1b0..9ca604c4ad 100644 --- a/headers/os/net/HttpRequest.h +++ b/headers/os/net/HttpRequest.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Haiku Inc. All rights reserved. + * Copyright 2010-2013 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _B_URL_PROTOCOL_HTTP_H_ @@ -8,7 +8,6 @@ #include - #include #include #include @@ -29,22 +28,22 @@ public: BUrlContext* context = NULL); virtual ~BHttpRequest(); - void SetMethod(const char* const method); - void SetFollowLocation(bool follow); - void SetMaxRedirections(int8 maxRedirections); - void SetReferrer(const BString& referrer); - void SetUserAgent(const BString& agent); - void SetDiscardData(bool discard); - void SetDisableListener(bool disable); - void SetAutoReferrer(bool enable); - void SetUserName(const BString& name); - void SetPassword(const BString& password); + void SetMethod(const char* const method); + void SetFollowLocation(bool follow); + void SetMaxRedirections(int8 maxRedirections); + void SetReferrer(const BString& referrer); + void SetUserAgent(const BString& agent); + void SetDiscardData(bool discard); + void SetDisableListener(bool disable); + void SetAutoReferrer(bool enable); + void SetUserName(const BString& name); + void SetPassword(const BString& password); - void SetPostFields(const BHttpForm& fields); - void SetHeaders(const BHttpHeaders& headers); + void SetPostFields(const BHttpForm& fields); + void SetHeaders(const BHttpHeaders& headers); - void AdoptPostFields(BHttpForm* const fields); - void AdoptInputData(BDataIO* const data, + void AdoptPostFields(BHttpForm* const fields); + void AdoptInputData(BDataIO* const data, const ssize_t size = -1); void AdoptHeaders(BHttpHeaders* const headers); diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 6330a3025c..3620d316c2 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -1,23 +1,26 @@ /* - * Copyright 2010-2011 Haiku Inc. All rights reserved. + * Copyright 2010-2013 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Christophe Huriaux, c.huriaux@gmail.com - * Niels Sascha Reedijk, niels.reedijk@gmail.com + * Niels Sascha Reedijk, niels.reedijk@gmail.com */ +#include + +#include +#include + #include #include #include -#include #include #include #include #include -#include static const int32 kHttpBufferSize = 4096; @@ -260,13 +263,13 @@ BHttpRequest::_ResetOptions() fOptFollowLocation = true; fOptMaxRedirs = 8; - fOptReferer = ""; + fOptReferer = ""; fOptUserAgent = "Services Kit (Haiku)"; fOptUsername = ""; fOptPassword = ""; fOptAuthMethods = B_HTTP_AUTHENTICATION_BASIC | B_HTTP_AUTHENTICATION_DIGEST | B_HTTP_AUTHENTICATION_IE_DIGEST; - fOptHeaders = NULL; + fOptHeaders = NULL; fOptPostFields = NULL; fOptSetCookies = true; fOptDiscardData = false; @@ -274,7 +277,7 @@ BHttpRequest::_ResetOptions() fOptAutoReferer = true; } -#include + status_t BHttpRequest::_ProtocolLoop() { @@ -344,13 +347,12 @@ BHttpRequest::_ProtocolLoop() break; case B_HTTP_STATUS_CLASS_CLIENT_ERROR: - if(fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) { + if (fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) { BHttpAuthentication* authentication = &fContext->GetAuthentication(fUrl); status_t status = B_OK; - if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) - { + if (authentication->Method() == B_HTTP_AUTHENTICATION_NONE) { // There is no authentication context for this // url yet, so let's create one. authentication = new BHttpAuthentication(); @@ -506,15 +508,15 @@ BHttpRequest::_MakeRequest() } else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT) && fOptInputData != NULL) { - for(;;) { + for (;;) { char outputTempBuffer[kHttpBufferSize]; ssize_t read = fOptInputData->Read(outputTempBuffer, sizeof(outputTempBuffer)); - if(read <= 0) break; + if (read <= 0) + break; - if (fOptInputDataSize < 0) - { + if (fOptInputDataSize < 0) { // Chunked transfer char hexSize[16]; size_t hexLength = sprintf(hexSize, "%ld", read); @@ -564,8 +566,7 @@ BHttpRequest::_MakeRequest() receiveEnd = true; fInputBuffer.AppendData(chunk.Data(), bytesRead); - } - else + } else bytesRead = 0; if (fRequestStatus < kRequestStatusReceived) { @@ -651,9 +652,8 @@ BHttpRequest::_MakeRequest() // A chunk of 0 bytes indicates the end of the chunked // transfer - if (bytesRead == 0) { + if (bytesRead == 0) receiveEnd = true; - } } else { bytesRead = fInputBuffer.Size(); @@ -855,13 +855,11 @@ BHttpRequest::_AddHeaders() fOutputHeaders.AddHeader("Content-Length", fOptPostFields->ContentLength()); } else if (fOptInputData != NULL - && (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) - { - if(fOptInputDataSize >= 0) { + && (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) { + if (fOptInputDataSize >= 0) fOutputHeaders.AddHeader("Content-Length", fOptInputDataSize); - } else { + else fOutputHeaders.AddHeader("Transfer-Encoding", "chunked"); - } } // Optional headers specified by the user @@ -901,8 +899,9 @@ BHttpRequest::_AddHeaders() // Write output headers to output stream for (int32 headerIndex = 0; headerIndex < fOutputHeaders.CountHeaders(); - headerIndex++) + headerIndex++) { _AddOutputBufferLine(fOutputHeaders.HeaderAt(headerIndex).Header()); + } }