MCPcopy Create free account
hub / github.com/amcewen/HttpClient / sendInitialHeaders

Method sendInitialHeaders

HttpClient.cpp:145–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145int HttpClient::sendInitialHeaders(const char* aServerName, IPAddress aServerIP, uint16_t aPort, const char* aURLPath, const char* aHttpMethod, const char* aUserAgent)
146{
147#ifdef LOGGING
148 Serial.println("Connected");
149#endif
150 // Send the HTTP command, i.e. "GET /somepath/ HTTP/1.0"
151 iClient->print(aHttpMethod);
152 iClient->print(" ");
153#ifdef PROXY_ENABLED
154 if (iProxyPort)
155 {
156 // We're going through a proxy, send a full URL
157 iClient->print("http://");
158 if (aServerName)
159 {
160 // We've got a server name, so use it
161 iClient->print(aServerName);
162 }
163 else
164 {
165 // We'll have to use the IP address
166 iClient->print(aServerIP);
167 }
168 if (aPort != kHttpPort)
169 {
170 iClient->print(":");
171 iClient->print(aPort);
172 }
173 }
174#endif
175 iClient->print(aURLPath);
176 iClient->println(" HTTP/1.1");
177 // The host header, if required
178 if (aServerName)
179 {
180 iClient->print("Host: ");
181 iClient->print(aServerName);
182 if (aPort != kHttpPort)
183 {
184 iClient->print(":");
185 iClient->print(aPort);
186 }
187 iClient->println();
188 }
189 // And user-agent string
190 if (aUserAgent)
191 {
192 sendHeader(HTTP_HEADER_USER_AGENT, aUserAgent);
193 }
194 else
195 {
196 sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent);
197 }
198 // We don't support persistent connections, so tell the server to
199 // close this connection after we're done
200 sendHeader(HTTP_HEADER_CONNECTION, "close");
201
202 // Everything has gone well

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected